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?
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?
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?
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!)
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.
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)
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.
One more thing - which of following methods would you recommend for optimal combination of accuracy,speed and quality (in case of satellite terrain rendering):
standard power-of-two textures (load and then rescale the image to power of 2 size)
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)
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.