View Full Version : How to improve texture coordinate accuracy?

08-31-2008, 04:19 AM

I'm doing terrain rendering with satellite image textures and additional layer displays on it(polygons,roads...etc)

I have texture coordinate accuracy problem - looks like I have a shift arround 100 meters.Any tips how to improve it?

I also have more specific question about solution I did,which maybe is causing this problem:
Texture size given to function glTexImage2D(...) must be in powers of 2. So used fixed size matrix texSatellite[2048][2048][3] and filled it with pixels of satellite tile and the rest left black (sometimes the area I need to display is smaller then the matrix size and sometimes bigger and then I do texture pagging) ,so I needed to calculate differently texture coordinates: instead of 1.0 as maximal coordinate now I need to normalize everything by MaxImagePixelX/2048.0 and MaxImagePixelY/2048.0.Is this right?

And also I'm working with float values,double should be better?

Thanks in advance

08-31-2008, 04:47 AM
glTexImage2D does not have to be powers of 2 (since OpenGL2.0?)

I would be surprised if you are getting a problem with texture coordinates - care to post the code you use to upload your texture and calculate your texture coordinates?

(Also, what card do you have?)

08-31-2008, 05:29 AM
My card is Quadro NVS 135M

About texture sizes - I'm aware that latest OpenGL versions allow any size textures, but then I have to assume that users will have appropriate graphic card?

08-31-2008, 07:04 AM
I'm trying now non-power-of-two textures,just for comparison,but
I can't get it work,here is my code.Is something missing?
I'm getting grey picture (not black!)

glGenTextures(1, &uiId);


glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0,GL_RGB,imgSatellite.iSizeX,imgSatellite.iSizeY,
0, GL_RGB, GL_UNSIGNED_BYTE, imgSatellite.pixels);


08-31-2008, 07:14 AM
He didn't meant to use rectangle textures, but non-power-of-two textures. That means, when your gfx card supports it, you can simply upload a GL_TEXTURE_2D, whose size is not a power of two. You don't need to change ANY code, simply use the real npot texture-sizes.

Rectangle textures do have some very different characteristics, that is why you get the grey result, but they are not suitable to your current problem, they are usually very useful, when doing screen-space computations.


08-31-2008, 06:58 PM
I also HIGHLY recommend that you change the third parameter on that call to glTexImage2D to be GL_RGB8 - as if you do not specify the bit depth you want - different cards may/will give you different precisions. (and some users would complain about color banding)

08-31-2008, 07:01 PM
Oh and for non-power of two textures - as Jan said above - just pass in the size you want using standard GL_TEXTURE_2D call:

Non-power-of-two textures are supported if the GL version is 2.0 or greater, or if the implementation exports the GL_ARB_texture_non_power_of_two extension.

If you use rectangle textures options (as you did above with GL_TEXTURE_RECTANGLE_ARB), the coordinates are not normalized - so to access position 5,5 in a 10x10 texture - the texture coordinates are just 5.0, 5.0.

08-31-2008, 11:13 PM
Thanks for your help

One more thing - which of following methods would you recommend for optimal combination of accuracy,speed and quality (in case of satellite terrain rendering):

1. standard power-of-two textures (load and then rescale the image to power of 2 size)

2. standard power-of-two textures (without rescaling,using technique I described in my first post in this thread:using calculated maximal texel coordinate instead of 1.0)

3. non-power-of two normalized coordinate textures



09-01-2008, 01:24 AM
2. standard power-of-two textures (without rescaling,using technique I described in my first post in this thread:using calculated maximal texel coordinate instead of 1.0)

3. non-power-of two normalized coordinate textures

Use 3 if the hardware support it, and is fast enough.
Use 2 otherwise.

About your accuracy problem : compared to a texel, how much is it off ? Half-texel ? More ? Less ?
You know that, when using linear filtering, the center of each texel for X texture coordinate is (0.5 + zero_based_index_of_texel_in_X_direction)/total_number_of_texels_in_X_direction. Same for Y.

09-01-2008, 05:36 AM
If done correctly, they should all be about the same speed (if not using texture compression)

Quality should be the same for all but option 1.

They should all have the same accuracy.

As ZbuffeR said, I suspect you are not generating the texture coordinates correctly for how you want to use them.