Pixel coordinates and upside-down-ness

Started by
2 comments, last by FurryKef 16 years, 7 months ago
I'm writing a 2D game in OpenGL because I want to use neat polygon-based effects that would be impractical in pure SDL. But, if possible, I also want my game to run in SDL without the special effects. I've already got the game working this way, even with some of the special effects, but I've run into a bit of a problem. We're basically designing our graphics for 1600x1200. Since many people may want to run the game at lower resolutions, we just scale 'em down when loading them. All the game coordinates are given in 1600x1200 and my SDL rendering routines just scale the pixels down before rendering. Now, (0, 0) is the upper-left of the screen. But in OpenGL mode, by default, (0, 0) is the lower-left. So in my game's setup code, I did this: glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0, 1600, 1200, 0, -1, 1) ...as opposed to glOrtho(0, 1600, 0, 1200, -1, 1). This mostly works fine, but I ran into a problem: when I use glCopyTexImage2D, which I'm use to copy the whole screen, the resulting texture is upside-down! So an obvious workaround is to render the scene upside-down before making that call, which I did by calling glOrtho(0, 1600, 0, 1200, -1, 1) before rendering, and setting it back the way it was afterward. But this has a quirk that bugs me. Let's suppose the game is in windowed mode and the bottom 20 pixels are off the screen. What will happen is that those bottom 20 pixels will not be drawn while I'm rendering upside-down. So when I set it right-side-up and render the texture, the top 20 pixels are missing. Not good. Is there a better way to have (0, 0) at the upper-left in OpenGL that avoids this problem? Should I just change all my game coordinates to use OpenGL's coordinate system (which means my SDL code will have to convert the coordinates)? What would you do? - Kef
Advertisement
Mm, I think my best course of action is to just redo the coordinates... I think it'd be less painful to make my SDL wrapper take OpenGL-style coordinates than to make OpenGL take SDL-style coordinates properly.

- Kef
You could always just render the image normally for the screenshot, and flip the captured image as you save it. (or flip the image
memory before you use it, i just assumed you were doing screenshots)
Hmm, I think that might be a better solution... it does avoid the problem with the wrong pixels being clipped when the window is partially obscured. All right, thanks.

Still, I must admit it does feel a little silly and hackish having to flip it upside-down in the first place.

- Kef

This topic is closed to new replies.

Advertisement