PDA

View Full Version : resizing display window and glRotatef question



godhand
04-01-2004, 08:20 PM
Hi, I have drawn a simple square on the screen and I drew another one rotated 30 degree to its left like this glRotatef(30,0,0,-1). The question is whenever I resize the window, the rotated square keeps on moving(rotating), so how would I keep it in a fixed position, thanks.

mikael_aronsson
04-01-2004, 09:03 PM
Hi !

this is a bit tricy, what do you mean with a "fixed position", do you mean that you want it in a fixed position compared to the other square, or at a fixed position in pixel coordinates or what ?

If you are using 3D then it becomes a bit complex to keep it in a fixed position, but if you switch to ortographic mode (glOrtho...) it is much simpler, but then you will not have any perspective, but if you just render 2D squares it is not a problem.

in orthographic mode the depth value has no impact on the size of the objects you render, if you you want to map opengl coordinates to pixel coordinates you can have a look at the transformation section of the faq on this website, there is information on how to do that.

This is the only way to keep the object in "fixed position" pixelwise.

Hope that helps
Mikael

malancha
04-01-2004, 10:37 PM
Matrix operations are multiplicative, so what's happening is that every time you redisplay (which happens when you resize), glRotate acts upon the already rotated matrix. Use glLoadIdentity() before your call to glRotate and your problem should be resolved.