I’m capturing webcam data using OpenCV and display them as the Texture for a GL Window, This works fine.
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, image->width, image->height, GL_RGB, GL_UNSIGNED_BYTE, image->imageData);
But I want also to overlay some basic shapes, Md2 models on top of this, retaining the texture in the background and in the same window itself.
This is my function that is passed into glutDisplayFunc()
void drawScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
// Set Projection Matrix
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 0);
// Setup the view // Switch to Model View Matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_QUADS);
// Trapezoid
glVertex3f(-0.7f, -1.5f, -5.0f);
glVertex3f(0.7f, -1.5f, -5.0f);
glVertex3f(0.4f, -0.5f, -5.0f);
glVertex3f(-0.4f, -0.5f, -5.0f);
glEnd(); //End quadrilateral coordinates
// start drawing the Background texture
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex2f(VIEWPORT_WIDTH, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex2f(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, VIEWPORT_HEIGHT);
glEnd();
glFlush();
glutSwapBuffers();
}
EDIT
new order
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex2f(VIEWPORT_WIDTH, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex2f(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, VIEWPORT_HEIGHT);
glEnd();
glBegin(GL_QUADS); //Begin quadrilateral coordinates
// Trapezoid
glVertex3f(-0.7f, -1.5f, -5.0f);
glVertex3f(0.7f, -1.5f, -5.0f);
glVertex3f(0.4f, -0.5f, -5.0f);
glVertex3f(-0.4f, -0.5f, -5.0f);
glEnd(); //End quadrilateral coordinates
EDIT:
New order and coordinates:
glDisable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
// Trapezoid to be displayed on top of texture
glVertex3f(0.2f, 0.3f, -0.6f);
glVertex3f(0.5f, -0.5f, -0.5f);
glVertex3f(0.4f, -0.5f, -0.5f);
glVertex3f(-0.4f, -0.5f, -0.5f);
glEnd(); //End quadrilateral coordinates
////
glEnable(GL_TEXTURE_2D); // start drawing the background texture
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex2f(VIEWPORT_WIDTH, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex2f(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, VIEWPORT_HEIGHT);
glEnd();
The result after doing above and Disabling gluOrtho2D()

Check the docs for
gluOrtho2D():You’re placing your trapezoid at Z = -5, way behind your near clipping plane:
Try -0.5 for your Z coordinates, or at least something between -1 and 0.
EDIT: Example: