View Full Version : OpenGL Transform Opinion

Duke Leto
Jul 20, 2009, 08:28 AM
In my OpenGL view (which was switched from a normal NSView), I have had to adjust from using NSView's bounds rectangle to using Modelview matrix transformations so that the user can move around, zoom in/zoom out.

I have a system set up with three variables: translateX, translateY, and zoom. Every time I draw, I load the identity matrix, then use these variables to transform the view. I have also thought about using glFrustrum, along with these variables to transform the view in just one operation.

I just wanted to know how you do transformations in OpenGL, and if my way can be improved on. (It is pretty inefficient).

I have another idea. I know that re-drawing a scene that is animating is very time consuming if I redraw every time (In this case, the planets in Gravita are being redrawn each time). Is it possible to remember what has to move, and by how much, then push a matrix, move the origin to whatever needs to move, move it, then pop the matrix and repeat? Would that work?

-- woah, just realized why that wouldn't work! --

But is there another way to translate only one part of a drawing in OpenGL, instead of clearing the screen with black and redrawing? That seems a bit inefficient. :/

Jul 20, 2009, 04:09 PM
Just redraw the entire scene every frame. OpenGL is very fast, and polygons offscreen get clipped anyway.

Remember what Knuth said: premature optimization is the root of all evil.