Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: urgent: drawing squares over an image

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2008
    Posts
    3

    urgent: drawing squares over an image

    I'm new to OpenGL
    I loaded a ppm image and I can't figure out how to draw squares over it, then update the coordinates of these shapes. when I draw them using glBegin(GLQuads) nothing is displayed. here is the code:
    void display(void)
    {

    glClear ( GL_COLOR_BUFFER_BIT );
    glRasterPos2i(0,0);
    glColor3f(1.0f, 0.7f, 0.3f);
    glBegin(GL_QUADS);
    glVertex3f(-0.5f, -3.5f, 3.5f);
    glVertex3f(0.5f, -3.5f, 3.5f);
    glVertex3f(0.5f, -3.5f, -3.5f);
    glVertex3f(-0.5f, -3.5f, -3.5f);


    glEnd();
    glDrawPixels(n,m,GL_RGB, GL_UNSIGNED_INT, image);
    glFlush ( );

    }
    I just loads the image. Please help me it's urgent

  2. #2
    Advanced Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: urgent: drawing squares over an image

    yeah, also post please what your PROJECTION and MODELVIEW matrices look like.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2008
    Posts
    3

    Re: urgent: drawing squares over an image

    It's my first time with openGL but I tried many different code without any success.
    here is the projection that I'm currently having:
    void handleResize(int w, int h) {
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0, (float)w / (float)h, 1.0, 200.0);
    }
    and in the above display function:
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);

    does this answer your question?

  4. #4
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: urgent: drawing squares over an image

    With glDrawPixels, you draw into the framebuffer in a way that it would erase all previous data already written the the drawing area. Call glDrawPixels before drawing quads it would already helps.

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2008
    Posts
    3

    Re: urgent: drawing squares over an image

    I already tried that... doesn't work
    the only thing I can think of is the fact I'm using double buffering (I tried single buffering too) no results.
    Any OpenGL experts?

  6. #6
    Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Los Angeles
    Posts
    386

    Re: urgent: drawing squares over an image

    First - comment out the call to DrawPixels. Then try to draw the square. I'm guessing that it doesn't work. Your problem has nothing to do with the fact you are trying to draw a square over an image. Your problem is that you aren't drawing the square correctly. It is not being drawn perpendicular to the line of site. It is being drawn edge-on to the line of site (which is in the -Z direction). All of your Z coordinates should be the same to draw a rectangle perpendicular to the line of site. In your example all of the Y coords are the same, but the Z coords differ. Use the Vertex commands below in place of yours and the rectangle should appear. Good luck.

    Code :
           glVertex3f (-10, -5, -30);
           glVertex3f ( 10, -5, -30);
           glVertex3f ( 10,  5, -30);
           glVertex3f (-10,  5, -30);
    Am I doing your homework for you?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •