PDA

View Full Version : Drawing camera independantly


LongJumper
2003.10.07, 03:01 PM
I want to draw something onto a window that is camera independant. Like a square that is always positioned so that you can see the front of it, no matter where the camera goes.

I was thinking something like pushing the matrix, switching to orthographic view and drawing, then popping it back out? Is that going to work? And in what order should I draw it in.

My update function goes something like glClear, loadIdentity,render the camera, draw the world, flush then swap buffers.

OneSadCookie
2003.10.07, 03:18 PM
Precisely what you want to do depends on precisely what effect you want to achieve...

Whatever you do though, it's going to involve pushing the current modelview and projection matrices, loading new ones, (possibly clearing the depth buffer), drawing stuff, and popping the matrices again.

You may want to look into billboarding. Unfortunately, I can't find the good tutorial at the moment :(

Bachus
2003.10.07, 05:22 PM
Originally posted by LongJumper
I was thinking something like pushing the matrix, switching to orthographic view and drawing, then popping it back out? Is that going to work? And in what order should I draw it in.

That's what I do for drawing in Gaichu


glViewport( 0, 0, sceneBounds.size.width, sceneBounds.size.height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();

gluPerspective(viewAngle, aspectRatio, nearZ, farZ);
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

// draw normal game stuff, level, player, etc

glViewport(sceneBounds.origin.x, sceneBounds.origin.y,
sceneBounds.origin.x + sceneBounds.size.width, sceneBounds.origin.y + sceneBounds.size.height);

glPushMatrix();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 180, 480, 0);
glPopMatrix();

glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// draw interface stuff

glPopMatrix();


Now that I look at the code, the pushes and pops are probably unnecessary, but I haven't gone through and optimized state changes yet. You probably won't need the glViewport calls (unless you're doing something like what I'm doing with the interface), and your gluPerspective and gluOrtho2D calls will vary.

But as OSC said, what you should do depends on the effect you're trying to achieve. Billboarding may be faster and easier for whatever you're doing. (huh, I can't find a billboarding tutorial either, weird)

monteboyd
2003.10.07, 07:37 PM
What you are describing is what I do in Slope Rider in two situations, for the background sky, and for the "Awesome" and "Repeat" mesages that show up. For the sky I turn off depth-testing and draw the quad with the sky texture after calling glLoadIdentity and before transforming the model view matrix (moving the camera). Then I push the model view matrix, do the transform on it, do all my other drawing, pop the model view matrix, turn off depth testing again and draw the Awesome/Repeat messages. This causes the sky to always appear behind everything and the Awesome/Repeat messages to always appear in front of everything.