Texture coordinate, half-pixel offsets

Started by
1 comment, last by roos 18 years, 8 months ago
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
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.
Ah! That's a good idea, thanks very much :D I'll give that a shot

This topic is closed to new replies.

Advertisement