513x513 grid of data to 512x512 texture

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

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?

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 :stuck_out_tongue: But you better try out all possible values for this.

Or you could read the documentation for GL_UNPACK_ALIGNMENT.

if its not a problem for you (due to hardware limitations) try to use


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

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).


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 :stuck_out_tongue:

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…