PDA

View Full Version : 513x513 grid of data to 512x512 texture



Leadwerks
06-17-2008, 05:58 PM
I have a grid of 513x513 shorts used for terrain. Terrain is a power of two resolution, so the vertices are power of two +1.

I want to upload this data to a texture to display the heightmap. This is what I am trying:

glpixelstorei GL_UNPACK_ROW_LENGTH,513
glTexImage2D GL_TEXTURE_2D,0,GL_LUMINANCE,512,512,0,GL_LUMINANC E,GL_UNSIGNED_SHORT,heightfield

When I do this my data is skewed 45 degrees, as if it is off by one pixel each row. Oddly enough, the same thing happens when I try a 513x513 texture. Any thoughts?

Sik the hedgehog
06-17-2008, 06:28 PM
Try setting the second parameter of glPixelStorei() to 1 (513 - 512)? I don't normally use glPixelStore*() often (I think that only once when initializing texturing), but I think that's the cause, judging how stride values are given often in other functions. Also it would make sense the 45 degree skewing.

If that doesn't work, try 512. Yeah, trial and error, like I said, I only use it for texturing and there I only need to give 1 as value :p But you better try out all possible values for this.

arekkusu
06-17-2008, 06:34 PM
Or you could read the documentation for GL_UNPACK_ALIGNMENT.

MichalST
06-18-2008, 01:27 AM
if its not a problem for you (due to hardware limitations) try to use

http://www.opengl.org/registry/specs/ARB/texture_rectangle.txt

or use bigger pow2 tex, and work on a part of it.

cass
06-18-2008, 08:56 AM
These days you should just be able to use a non-pow2 texture map with any modern hardware.

As arekkusu commented, you'll need to either need to set the GL_UNPACK_ALIGNMENT to 2 (or you could just be crazy and go all the way to 1 for convenience).

Cass

Sik the hedgehog
06-18-2008, 11:33 AM
Anyways, stupid question... wouldn't this leave two borders away? I mean, if the value at 512 and the one at 513 are completely different, you'll see the value at 512 and you can't know what's meant to be show at 513. In order to fix this, you would have to do some kind of average... which will result in a 512x512 texture that will kill out any issue of this kind :p

Just an opinion, a 513x513 texture could do too, just it isn't power-of-two and there are still several pre-GL2 cards (specially Intel cards). I mean, once I found a card with GL 1.3 and the computer wasn't too old...