Jump to content
  • Advertisement
Sign in to follow this  
B_old

OpenGL Odd behavior with arbitrarily sized textures

This topic is 2074 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I stumbled over this while porting font printing code from D3D to OpenGL.

I place all glyphs I potentially want to draw in an atlas which can have an arbitrary size depending on the resolution of the glyphs. In the case I tested, I ended up with an 243x211 atlas. In OpenGL the atlas looks "skewed" and I can't figure out why.

The problem does not appear if the atlas has a size of 256x201 for instance, without changing anything else. So I think the problem is directly related to the texture size. The data used to create the texture is allocated like this: data = new unsigned char[x * y]; So I'm not explicitly controlling the alignment or anything.

Any idea what could be going on here? Do I need glPixelStorei() in some form?

NPOT textures are supported by the hardware.

Share this post


Link to post
Share on other sites
Advertisement

By default, pixel rows are required to be 4-byte aligned. I assume from your call to new that you're allocating single channel 8-bit images. That means your 243 pixel wide image is not a multiple of 4 bytes wide, so OpenGL assumes there's a byte padding after each row, since 244 is the next larger multiple of 4 bytes per row. Either pad your images accordingly, or set the unpack alignment to 1 with glPixelStore.

Share this post


Link to post
Share on other sites

Thanks, I did not know that!

 

Do you know in what way this affects the texture data actually stored on the GPU. Will the driver automatically pad the texture if it doesn't fit the 4 byte alignment and is glPixelStore just an information how to decode the provided data, or will the texture actually reside in graphics memory like that?

Edited by B_old

Share this post


Link to post
Share on other sites

Thanks, I did not know that!

 

Do you know in what way this affects the texture data actually stored on the GPU. Will the driver automatically pad the texture if it doesn't fit the 4 byte alignment and is glPixelStore just an information how to decode the provided data, or will the texture actually reside in graphics memory like that?

 

Maybe, maybe not; it all depends on the driver and hardware really - OpenGL itself doesn't specify that.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!