Jump to content
  • Advertisement
Sign in to follow this  
nornagon

OpenGL Rendering from a spritesheet

This topic is 4110 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'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): brokenness (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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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? >.>)

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!