I am trying to create a mipmapped textured image that represents elevation. The image must be 940 x 618. I realize that my texture must have a width and height of a power of 2. As of now I have tried to incrementally go through doing all my texturing in squares (eg 64 x 64, or 128 x 128, even 512 x 512), but the image still comes out blurry. Any idea of how to better texture an image of this size?
4 Answers
Use a 1024x1024 texture and put your image in just a part of the image, 940x618. Then use the values 940.0/1024.0 and 618.0/1024.0 for the max texture coordinates, or scale the TEXTURE_MATRIX
. This will make a 1:1 mapping for your pixels. You might also need to shift the model half a pixel to get a perfect fit, this depends on your model setup and view.
This is the technic I used in this screensaver I made for the Mac. http://memention.com/void/ It grabs the screen contents and uses it as a texture on some 3D effects and I really wanted a pixel perfect fit.

- 45,805
- 17
- 110
- 144
-
Ok yea I think my problem is I am not mapping my pixels 1:1. Do I use glMultiTexCoord2f() to set the max texture coordinates? And do I do that before I call gluBuild2DMipmaps() ? Thanks for the help! – anthv123 Jun 13 '11 at 21:21
-
Either you use `glTexCoord2f` with the new values, or use `glMatrixMode(GL_TEXTURE); glScalef(*nv1*,*nv2*,1.0); glMatrixMode(GL_TEXTURE); ... draw your thing as before ...; reset texture matrix to identity` – epatel Jun 13 '11 at 22:31
-
Here is the code I am using. Nothing seems to be working. glEnable(GL_LIGHTING); glLightfv(...); glMatrixMode(GL_TEXTURE); glScalef(940.0/1024.0, 618.0/1024.0, 1.0); glMatrixMode(GL_TEXTURE); glDrawElements(...); glLoadIdentity(); glDisable(GL_LIGHTING); – anthv123 Jun 14 '11 at 14:29
-
Oups...sorry, saw now that I used `GL_TEXTURE` twice, should have been a reset on the last `glMatrixMode(..)` ie to `glMatrixMode(GL_MODELVIEW)` – epatel Jun 14 '11 at 17:18
As far as I know, modern technologies do not require you to use a power of 2 for your dimensions. Just know however, that if this code is run an older machine, you'll have some problems. How old is your machine?

- 5,812
- 5
- 29
- 46
-
Definitely not old. Any ideas as to why it would be blurry? If I try to texture the entire image just using a 128 x 128 texture, it is very blurry, if I use a 256 x 256 it gets less blurry, and so on... – anthv123 Jun 13 '11 at 19:35
-
2@anthv123 Of course it gets blurry when you stretch it to a size larger than the texture, or to another aspect ratio. So when your hardware isn't that old, just try a 940x618 texture and see if it works. You can look, if your driver supports the `GL_ARB_texture_non_power_of_two` extension (or alternatively OpenGL 2.0). – Christian Rau Jun 13 '11 at 19:38
-
I have tried using the exact texture, but nothing better. Does anything below OpenGL 2.0 require a power of 2 texture? – anthv123 Jun 13 '11 at 19:50
-
You can try turning off filtering too: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); – Ville Krumlinde Jun 13 '11 at 20:15
The texture is probably not mapped 1:1, and you have GL_LINEAR or GL_NEAREST filtering. Try higher resolution texture, mipmapping, and 1:1 screen mapping.

- 3,695
- 7
- 27
- 42
-
Also, with any non Intel Extremely Crappy Graphics card you can just use TEXTURE_NON_POWER_OF_2 extension to load the texture of any size. In that case you can just map it with coordinates ranging from [0;1] and it should map 1:1. – Coder Jun 13 '11 at 21:24
Use a 940x618 sized texture (if this is truly the size of the surface it's applied to) and set the texture's minification/magnification to use GL_LINEAR. That should give you the results you're after.

- 564
- 3
- 7