Load Textures.

Started by
4 comments, last by X5-Programmer 19 years, 7 months ago
Hi, I have some problem on how do get sharp good looking textures on Quads for like menues and so on, the loader I am using to load textures is an jpg loader from www.gametutorials.com, but when I load them and put them as an texture on an quad that is the same size as the image, let say we have an 400*400 image. I draw it like this.

glBegin(GL_QUADS);
	
		glTexCoord2f(0.0f, 1.0f);	glVertex2f(0, 0);
		glTexCoord2f(0.0f, 0.0f);	glVertex2f(0, 400.0f);
		glTexCoord2f(1.0f, 0.0f);	glVertex2f(400.0f, 400.0f);
		glTexCoord2f(1.0f, 1.0f);	glVertex2f(400.0f, 0);
	
	glEnd();

But if I open the picture in Photoshop and compare it to the texture in the app it does not have the same sharpness like the image in photoshop. Do you guys know any way to get the same sharpness? And if so can you write an example or explain how to do it. hope anyone can point me somewere. thx.
-[ thx ]-
Advertisement
Quote:but when I load them and put them as an texture on an quad that is the same size as the image, let say we have an 400*400 image.


Same size in screen co-ordinates is what matters, not just gl co-ordinates. It's unclear if you have that.
The image-width and image-height should be a power of 2: 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, etc.
Quote:Original post by Pipo DeClown
The image-width and image-height should be a power of 2: 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, etc.

You missed the "1" [wink].

OGL will (by default?) filter your texture so you must disable filterung manually to avoid such artifacts.
If you use glu to upload your texture image, it will re-sample it, and it'll do a poor and slow job. You're much better off uploading the image yourself (using TexSubImage()) and calculating MIP maps yourself (if you need then, which you do for 3D stuff because it makes things render faster, but not for 2D stuff, as you're 1:1).

Thus, if you want a 400x400 image, you allocate a 512x512 texture, and TexSubImage to the lower-left 400x400 pixels of that. Then you use the texture coordinates 0 and (400.0/512.0) for low/left and top/right respectively. If your ortho is set up to be one unit per pixel, then this will give you crisp images, even if you use LINEAR filtering, because it'll sample perfectly at the center of each texel.

If you get small imperfections, you can reduce them by setting filtering to NEAREST, but that shouldn't be necessary -- if you get it RIGHT.
enum Bool { True, False, FileNotFound };
Allright, thanks for your replays. But I learn better on look and try to understand code, so If someone have time and willing to write me and example I will be wery glad.

thx.
-[ thx ]-

This topic is closed to new replies.

Advertisement