OpenGL Rendering from a spritesheet

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

Recommended Posts

I've been trying to write a simple scrolling 2D game with OpenGL, because I'd like fast sprite rotation. I have a spritesheet that I load into a 256x256 texture, then draw quads with the relevant texture coordinates on them. I also have a 'camera' transformation matrix that does the scrolling (it's just a glTranslatef). The problem I have is that if the arguments to the scrolling glTranslatef are non-integer, I get weird corruption at the sides of the tiles (here, the bottom and left, but it varies depending on what the translation is like): (the bits it's showing are bits of the spritesheet surrounding those tiles) If I round the arguments to glTranslatef() down to integers, the 'corruption' disappears, but scrolling becomes jerky. Surely I must be missing something...? Why does translating prior to drawing the quads change the texture mapping? Thanks in advance.

Share on other sites
Greetings fellow Sydney-sider!

Your problem has nothing to do with the rotation. It has to do with the texture sampling states. You probably have them at Linear. You want to make them Nearest. The code needed is below:
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);

Alternatively, if you want to keep the linear sampling, you could shave off a small amount of each uv coordinate. Or do both and give the user the option of having their graphics filtered or not.

Good luck!

Share on other sites
Wow, it's so obvious in retrospect.

However, changing it to GL_NEAREST achieves essentially the same effect as rounding the glTranslatef() coordinates -- but looking at it, I can't really see any way for that not to happen. Just looks weird now that the ball's got linear but the platform has nearest. The platform sorta jerks around under the ball when the ball's going really slowly.

I guess it's not that big a deal, though.

Thanks so much for your help! :)

(where in Sydney? >.>)

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 9
• Forum Statistics

• Total Topics
633330
• Total Posts
3011389
• Who's Online (See full list)

There are no registered users currently online

×