Rotating in an Ortho projection?

Started by
5 comments, last by nullsquared 17 years, 9 months ago
Here's the problem. I need to flip a texture upside down, and I for the most part know how to do that. I worked with doing 3d things in gluPerspective quite a bit. However I've decided for the game I want to make, it's just going to be 2d, not quite as adventurous. So I'm just using glOrtho. The problem arises when I try to perform a rotation on a particular texture. All I want to do is flip it upside down, but whenever I use glRotatef to try and rotate the scene in even the slightest, the texture disappears completely. Why would this happen using glOrtho, and how do I fix it? Some conditions of the situation that may or may not present a complicating condition in the matter: (I'm not sure) *I'm not using a 1, -1, 1, -1, 1, -1 coordinate system. I'm using 0, 800, 600, 0. *The texture in question is one generated by glFont. But my assumption is that it's just a quad and I should be able to flip it like a regular polygon. (And the documentation of glFont supports that belief)
Advertisement
why not just change the texture coordinates being used to draw the texture.

Or use a scale matrix instead of a rotation matrix?

Or change the texture matrix instead of the perspective matrix.

How are you doing your rotation, which axis are you roating around?
Quote:Original post by BrknPhoenix
Here's the problem. I need to flip a texture upside down, and I for the most part know how to do that. I worked with doing 3d things in gluPerspective quite a bit. However I've decided for the game I want to make, it's just going to be 2d, not quite as adventurous. So I'm just using glOrtho.

The problem arises when I try to perform a rotation on a particular texture. All I want to do is flip it upside down, but whenever I use glRotatef to try and rotate the scene in even the slightest, the texture disappears completely.

Why would this happen using glOrtho, and how do I fix it?

Some conditions of the situation that may or may not present a complicating condition in the matter: (I'm not sure)

*I'm not using a 1, -1, 1, -1, 1, -1 coordinate system. I'm using 0, 800, 600, 0.

*The texture in question is one generated by glFont. But my assumption is that it's just a quad and I should be able to flip it like a regular polygon. (And the documentation of glFont supports that belief)


Your problem is you are calling () correct? Well if you want to do any rotating of your polygons you need to call glOrtho() and set your near/far plane parameters to 1.0 100.0 respectively. The problem is gluOrtho2D() is set to -1.0 and 1.0 IIRC so when you rotate a polygon its out of the frustum and it gets clipped... HTH
The 1.0, 100.0 solution didn't work, as it just clipped everything then. I didn't originally want to go off altering the coordinates because it was part of the glFont API, so I figured I must have been doing something wrong. But with lack of any better ideas, I took the advice of changing the coordinates in the API and it works fine now :)
Quote:Original post by BrknPhoenix
The 1.0, 100.0 solution didn't work, as it just clipped everything then. I didn't originally want to go off altering the coordinates because it was part of the glFont API, so I figured I must have been doing something wrong. But with lack of any better ideas, I took the advice of changing the coordinates in the API and it works fine now :)


Well it's been awhile but it may be -100. and 100. I can't remember for sure but you may want to try that.
The near and far plane distances aren't your problem. If you are rotating around the correct axis then the quad will stay in the same plane. Assuming the default OpenGL coordinate system with +x to the right, +y up, and +z coming out of the screen, you should be rotating around the z-axis. You should also be doing your rotations on the modelview matrix. If neither of those are the problems then post some relevant code.

EDIT: Nevermind the above, I think I misunderstood your problem at first. It seems to me that glFont assumes a coordinate system with the origin at the bottom-left of the screen. You are giving it one with the origin at the top-left. In this case (still assuming the default OpenGL axes) rotating it 180 degrees about the z-axis will not give the correct result. You either need to rotate it about the x-axis or scale it by -1 on the y-axis. Using either one of those options, you will need to switch the front face (or switch the face culling mode or disable it altogether). Don't forget to switch it back when rendering everything else.

[Edited by - Kalidor on July 6, 2006 11:38:54 AM]
Just scale it to a negative?

X-flip: glScalef(-1.0f, 1.0f, 1.0f);
Y-flip: glScalef( 1.0f,-1.0f, 1.0f);

EDIT: Nevermind Kalidor got it. I should read all the replies before replying [grin].

This topic is closed to new replies.

Advertisement