Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6799667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:52:33+00:00 2026-05-26T18:52:33+00:00

I’m capturing webcam data using OpenCV and display them as the Texture for a

  • 0

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()

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:52:34+00:00Added an answer on May 26, 2026 at 6:52 pm

    Check the docs for gluOrtho2D():

    gluOrtho2D sets up a two-dimensional orthographic viewing region. This is equivalent to calling glOrtho with near = -1 and far = 1.

    You’re placing your trapezoid at Z = -5, way behind your near clipping plane:

    glBegin(GL_QUADS);
    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(); 
    

    Try -0.5 for your Z coordinates, or at least something between -1 and 0.

    EDIT: Example:

    #include <GL/glut.h>
    
    int win_w = 0;
    int win_h = 0;
    GLuint texObj = 0;
    
    void display(void)
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
        // set up projection
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        double halfWidth = (win_w / 2.0);;
        double halfHeight = (win_h / 2.0);
        glOrtho( -halfWidth, halfWidth, -halfHeight, halfHeight, -10, 10 );
    
        // set up modelview
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    
        // render textured quad
        glEnable(GL_TEXTURE_2D);
        glColor3ub(255,255,255);
        glPushMatrix();
            glScalef(halfWidth * 0.9, halfHeight * 0.9, 1.0);
            glBegin(GL_QUADS);
                glTexCoord2f(0,0);
                glVertex2f(-1,-1);
                glTexCoord2f(1,0);
                glVertex2f(1,-1);
                glTexCoord2f(1,1);
                glVertex2f(1,1);
                glTexCoord2f(0,1);
                glVertex2f(-1,1);
            glEnd();
        glPopMatrix();
        glDisable(GL_TEXTURE_2D);
    
        // draw quad on top
        glColor3ub(255,0,0);
        glPushMatrix();
            // move quad back a bit so it's above Z=0
            glTranslatef(0,0,-1);
            glScalef(50,50,50);
            glBegin(GL_QUADS);
                glVertex2f(-1,-1);
                glVertex2f(1,-1);
                glVertex2f(1,1);
                glVertex2f(-1,1);
            glEnd();
        glPopMatrix();
    
        glFlush();
        glutSwapBuffers();
    }
    
    void reshape(int w, int h)
    {
        win_w = w;
        win_h = h;
        glViewport(0, 0, w, h);
    }
    
    GLuint getTexture()
    {
        // 2x2 texture
        unsigned char bytes[] =
        {
              0,   0, 255,      255, 255, 255,
            255,   0,   0,      0, 255,   0,
        };
    
        GLuint texID;
        glGenTextures(1, &texID);
        glBindTexture(GL_TEXTURE_2D, texID);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, bytes);
        return texID;
    }
    
    int main(int argc, char **argv)
    {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
    
        glutInitWindowSize(800,600);
        glutCreateWindow("Texture");
    
        glutDisplayFunc(display);
        glutReshapeFunc(reshape);
    
        texObj = getTexture();
        glutMainLoop();
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.