I want to draw a 3d model and a texture mapped quad in 3d space. The model is transformed according to glTranslate and glRotate data. The quad will be displayed using glOrtho, because it will play the role of a hanging poster. The only problem is, that even if I enable depth test, the poster will always hide the model, even if the model is between the viewer and the poster.
The steps of drawing are the following:
-
Set up the camera:
gluPerspective( GLOBAL_CAM.fov, 1.3, 2.0, 1500.0 );
gluLookAt(GLOBAL_CAM.x, GLOBAL_CAM.y, GLOBAL_CAM.z,
GLOBAL_CAM.target_x, GLOBAL_CAM.target_y, GLOBAL_CAM.target_z,
0,1,0); -
Draw the poster:
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,screen_w,screen_h,0, -1000,1000);
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
glEnable(GL_DEPTH_TEST); //needed (?) to use depth
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex);
glBegin(GL_QUADS);
glNormal3f(0.0f, 0.0f, 1.0f);
glTexCoord2f(0, 1);
//z should be the distance between the viewer and the poster (z=1000). The model is about 200-300 units from the cam away
glVertex3d(x1, y1, z);
glTexCoord2f(0, 0);
glVertex3d(x1, y2, z);
glTexCoord2f(1, 0);
glVertex3d( x2, y2, z);
glTexCoord2f(1, 1);
glVertex3d( x2, y1, z);
glEnd();
glEnable(GL_LIGHTING);
glDisable(GL_BLEND);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
- Draw the model (no ortho used.)
How is it possible to use ortho as a ‘normal’ depth sorted 3d object?
Thank you in advance