   OpenGL. Draw object ignoring the camera
  Hi all, I just wanted to better understand how the camera and transformation matrix works. My final target is to ignore what is the camera position and draw a big quad in the center of the screen.So let's assume I'm using the ModelView matrix mode...// Set the camera// Draw some objectsglPushMatrix();glLoadIdentity();glColor3f(1, 0, 0);glNormal3f(0, 0, 1);float halfEdge = 10;float depth = -10;glBegin(GL11.GL_QUADS);glVertex3f(-halfEdge, -halfEdge, depth);glVertex3f(halfEdge, -halfEdge, depth);glVertex3f(halfEdge, halfEdge, depth);glVertex3f(-halfEdge, halfEdge, depth);glEnd();GL11.glPopMatrix();So I understood that when I set the camera with gluLookAt the transformation matrix is set to operate a translation/rotation to all the object that is the inverse of the camera position. So basically the camera is always still in 0,0,0 but the objects are moving according to it.Now if I push the matrix and load the identity matrix, I should be able to draw a rectangle in (-10,-10,20,20) over the current scene. But this doesn't seem to work, am I missing anything?Thanks in advance   
  If you want to draw a 2D element ON the screen, as in, size defined by pixels, then you need to switch to orthogonal mode. So, first you draw the scene with gluPerspective, then you switch to glOrtho, example:  glViewport(0, 0, width, height);  glMatrixMode(GL_PROJECTION);  glLoadIdentity();  glOrtho(0.0f, width, height, 0.0f, -1.0f, 1.0f);  glMatrixMode(GL_MODELVIEW);  glLoadIdentity();  glDisable(GL_DEPTH_TEST);  glColor4f(1.0f, 1.0f, 1.0f, 1.0f);  glTranslatef(0.0f, 0.0f, -1.0f);  /// start drawing GUI or other 2D stuff  float halfEdge = 10;  float depth = -10;  glBegin(GL_QUADS); glVertex3f(-halfEdge, -halfEdge, depth); glVertex3f(halfEdge, -halfEdge, depth); glVertex3f(halfEdge, halfEdge, depth); glVertex3f(-halfEdge, halfEdge, depth);  glEnd();  //////////////////  glDisable(GL_TEXTURE_2D);  glViewport(0, 0, 200, 150); // this and above not needed if both need to be rendered to the full screen (not to fullscreen mode necessarily)  glMatrixMode(GL_PROJECTION);  glLoadIdentity();  gluPerspective(45.0f, (GLfloat) 200 / (GLfloat) 150, 0.1f, 100.0f);  glMatrixMode(GL_MODELVIEW);  glLoadIdentity();  glEnable(GL_DEPTH_TEST);  glTranslatef(0.0f, 0.0f, -5.0f);  glRotatef(r, 0.4f, 1.0f, 0.2f);  glBegin(GL_TRIANGLES); glColor4f(1.0f, 0.0f, 0.0f, 1.0f); glVertex3f( 0.0f,  1.0f, 0.0f); glColor4f(0.0f, 1.0f, 0.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 0.0f); glColor4f(0.0f, 0.0f, 1.0f, 1.0f); glVertex3f( 1.0f, -1.0f, 0.0f);  glEnd();  glBegin(GL_QUADS);// Start Drawing The Cube glColor4f(0.0f, 1.0f, 0.0f, 0.5f);// Set The Color To Green glVertex3f( 1.0f, 1.0f,-1.0f);// Top Right Of The Quad (Top) glVertex3f(-1.0f, 1.0f,-1.0f);// Top Left Of The Quad (Top) glVertex3f(-1.0f, 1.0f, 1.0f);// Bottom Left Of The Quad (Top) glVertex3f( 1.0f, 1.0f, 1.0f);// Bottom Right Of The Quad (Top) glColor4f(1.0f, 0.5f, 0.0f, 0.5f);// Set The Color To Orange glVertex3f( 1.0f,-1.0f, 1.0f);// Top Right Of The Quad (Bottom) glVertex3f(-1.0f,-1.0f, 1.0f);// Top Left Of The Quad (Bottom) glVertex3f(-1.0f,-1.0f,-1.0f);// Bottom Left Of The Quad (Bottom) glVertex3f( 1.0f,-1.0f,-1.0f);// Bottom Right Of The Quad (Bottom) glColor4f(1.0f, 0.0f, -0.0f, 0.5f);// Set The Color To Red glVertex3f( 1.0f, 1.0f, 1.0f);// Top Right Of The Quad (Front) glVertex3f(-1.0f, 1.0f, 1.0f);// Top Left Of The Quad (Front) glVertex3f(-1.0f,-1.0f, 1.0f);// Bottom Left Of The Quad (Front) glVertex3f( 1.0f,-1.0f, 1.0f);// Bottom Right Of The Quad (Front) glColor4f(1.0f, 1.0f, 0.0f, 0.5f);// Set The Color To Yellow glVertex3f( 1.0f,-1.0f,-1.0f);// Bottom Left Of The Quad (Back) glVertex3f(-1.0f,-1.0f,-1.0f);// Bottom Right Of The Quad (Back) glVertex3f(-1.0f, 1.0f,-1.0f);// Top Right Of The Quad (Back) glVertex3f( 1.0f, 1.0f,-1.0f);// Top Left Of The Quad (Back) glColor4f(0.0f, 0.0f, 1.0f, 0.5f);// Set The Color To Blue glVertex3f(-1.0f, 1.0f, 1.0f);// Top Right Of The Quad (Left) glVertex3f(-1.0f, 1.0f,-1.0f);// Top Left Of The Quad (Left) glVertex3f(-1.0f,-1.0f,-1.0f);// Bottom Left Of The Quad (Left) glVertex3f(-1.0f,-1.0f, 1.0f);// Bottom Right Of The Quad (Left) glColor4f(1.0f, 0.0f, 1.0f, 0.5f);// Set The Color To Violet glVertex3f( 1.0f, 1.0f,-1.0f);// Top Right Of The Quad (Right) glVertex3f( 1.0f, 1.0f, 1.0f);// Top Left Of The Quad (Right) glVertex3f( 1.0f,-1.0f, 1.0f);// Bottom Left Of The Quad (Right) glVertex3f( 1.0f,-1.0f,-1.0f);// Bottom Right Of The Quad (Right)  glEnd();  r += 0.03f;This is done every frame. This example btw first draws 2D and then some 3D on top of it.   ;  Thanks a lot for the answer,but still I don't understand where is the problem if I want to draw something in perspective. Where is the flaw in my previous reasoning?   ;  Try using a negative depth value (by default, the view is looking towards the negative z side). That should solve your problems.   ;  Also check whether the depth value (in view space) will fall between the near and far clipping planes.Quote:Original post by Jardak... the camera is always still in 0,0,0 but the objects are moving ...This is a question of interpretation. Please check for the term "reference system". E.g. the above is true when using the view space as reference system. When using the world space as reference system, all objects remain in place but the camera is moving.   