   drawing HUD (orthogonal projection)
  I'm trying to get HUD display working (2D quads remaining stationary w.r.t the camera regardless of camera rotation) and I know that all I have to do is use orthogonal projection but every time I move the camera, the quad doesn't "stay in place".init(){   glClearColor( .5, .5, 1, 0 );   glEnable( GL_CULL_FACE );   glCullFace( GL_FRONT );   //glMatrixMode( GL_PROJECTION );   //glLoadIdentity();   //gluPerspective( 45, 1.0, 0.0, 1000.0 );}render(){   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );   glMatrixMode(GL_PROJECTION);   glPushMatrix(); glLoadIdentity(); glOrtho( -400, 400 , -300 , 300, 1, 900 ); glMatrixMode( GL_MODELVIEW ); glPushMatrix();    glLoadIdentity();    gluLookAt( pos.x, pos.y, pos.z, target.x, target.y, target.z, 0, 1,0 );    glPushMatrix();    glBegin( GL_QUADS );  glVertex3f( -10.f, -10.f, 0.f );  glVertex3f( 10.f, -10.f, 0.f );  glVertex3f( 10.f,  10.f, 0.f );  glVertex3f( -10.f,  10.f, 0.f );    glEnd();    glPopMatrix(); glPopMatrix();   glMatrixMode(GL_PROJECTION);   glPopMatrix();   glMatrixMode(GL_MODELVIEW);   SDL_GL_SwapBuffers();}[Edited by - 16bit_port on June 21, 2009 1:10:50 PM]
  Of course the quad moves with the camera; you make a call to gluLookAt with, what looks to me as camera parameters, just before drawing the quad. That means the position of the quad depends on your camera parameters.   ;  So to get that quad to stay on my screen as I move my camera through my scene, do I place it in front of the camera at init() and then as I'm translating and/or rotating my camera in update(), I apply those exact same transformations to my quad and perform an orthogonal projection?   ;  In order to get the quad to not move, you don't do anything. That is, remove the call to gluLookAt, and the quad will not be affected by the camera parameters. Just make sure you draw at the correct depth; at the moment you draw at Z=0, but the depth range is -1 to -900. Set the last two parameters of glOrtho to -1 and 1, respectively, and remove the call to gluLookAt, and you should be fine.   ;  That's the thing, if I remove the gluLookAt, my camera just stay stationary in the scene but I want to be able to move it through the scene (that's why I keep on calling gluLookAt) while still having that HUD follow me.   ;  Then use gluLookAt with the camera parameters when you draw your scene, and don't use it when you draw the HUD. I'm a bit confused; is the code you posted supposed to be the HUD or the scene? If it's the HUD, you drop gluLookAt. If it's the scene, you leave it there.Keep in mind that objects are only subject to transformations that you apply. If you don't want something to be affected by a transformation, you don't apply it. So if the code above is supposed to draw the HUD, then removing gluLookAt will keep it fixed on the screen as you move around your scene.   ;Quote:Original post by Brother BobThen use gluLookAt with the camera parameters when you draw your scene, and don't use it when you draw the HUD. I'm a bit confused; is the code you posted supposed to be the HUD or the scene? If it's the HUD, you drop gluLookAt. If it's the scene, you leave it there.Keep in mind that objects are only subject to transformations that you apply. If you don't want something to be affected by a transformation, you don't apply it. So if the code above is supposed to draw the HUD, then removing gluLookAt will keep it fixed on the screen as you move around your scene.You're right. Ugh... I can't believe the projection matrix stack completely slipped my mind. Anyway, I did it without any difficulties. Thanks, Brother Bob.   