Jump to content
  • Advertisement
Sign in to follow this  
roos

Texture coordinate, half-pixel offsets

This topic is 4846 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

Sorry for the vague title of this post, wasn't sure exactly what to call it :) Anyway, recently I wrote some code that packs multiple images into one texture. This way on the project I'm working on, we can have each image in its own file for convenience, but also good performance by minimizing texture switching. Now, at first I was calculating the texture coordinates like this: // given an image at pixel offset (x,y) within the texture, // with dimensions (w,h). The texture's dimensions are (TW,TH) u1 = x / TW v1 = y / TH u2 = (x+w) / TW v2 = (y+h) / TH Now, the problem with this is that with GL_CLAMP for the wrapping, you get some artifacts at the edges. Now I've heard of some GL_CLAMP_TO_EDGE but apparently it's not supported universally so I ditched that idea. Then, I found out you could just add an offset of a half-pixel to the coordinates, like so: u1 = (x+.5) / TW v1 = (y+.5) / TH u2 = (x+w-.5) / TW v2 = (y+h-.5) / TH In fact, for DirectX users, I believe that's what the D3DX image drawing routines do but I could be wrong... Anyway, this "trick" works perfectly for me with my Radeon 9800 pro. However, when my teammate tried running the game after I implemented the new texture-packing code, he said that he had a distinct 1-pixel wide white line on the left and top edges of the screen... (I don't know what video card he has yet). I think it might be related to the pixel offsets. So, I was wondering, does anyone have any experience with this and might have some idea about how to get rid of those white lines? Thanks very much, roos

Share this post


Link to post
Share on other sites
Advertisement
For what it's worth, GL_CLAMP_TO_EDGE is in OpenGL 1.2 and higher. I say just go for it. If your card doesn't support OpenGL 1.2, time to upgrade.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!