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: Does freeglut allow you to draw in top of other?

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2011
    Posts
    27

    Does freeglut allow you to draw in top of other?

    I have white image. I am trying to draw another image in top of it.
    But I cannot see it.
    And is there a way to erase a drawing? Not from the code

  2. #2
    Intern Contributor
    Join Date
    Sep 2010
    Posts
    74

    Re: Does freeglut allow you to draw in top of other?

    To "erase", use glClear(GL_COLOR_BUFFER_BIT), and swap buffers if using double buffering.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2011
    Posts
    27

    Re: Does freeglut allow you to draw in top of other?

    But that deletes everything. However i want to delete just a single part. How can I do that?

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,718

    Re: Does freeglut allow you to draw in top of other?

    You redraw everything except that part you don't want to see anymore. This is how the vast majority of OpenGL applications operates.

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2011
    Posts
    27

    Re: Does freeglut allow you to draw in top of other?

    true.
    but what I am trying to do is let the user change the color of the object. Unfortunately, I could not learn picking. So, I thought i would use if statements like if x>122&amp;&amp; x< 213 return 1. same for y. So I would know which object was clicked. And then I called a popupmenu function for the user to choose color. Then I decided to redraw the colored object on top of other. If i erase all and draw again it will not work because I have different functions for drawing not colored things and colored things.
    anyway I will try.
    If you dont get this then I can provide a better explanation with code

  6. #6
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: Does freeglut allow you to draw in top of other?

    If you want to do color picking, you have 2 choices. Either you use the back buffer or a RenderBuffer. Assuming you want to use the back buffer.

    Whichever you choose, all you need to do is
    glCear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENIL_BUFFER_BIT);
    RenderObjectsWithUniqueColor();
    //Read back color under the mouse
    uint thecolor;
    glReadPixels(x, y, 1, 1, GL_BGRA, GL_UNSIGNED_BYTE, thecolor);

    //And clear again
    glCear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENIL_BUFFER_BIT);
    RenderObjects();
    SwapBuffers();
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posting Permissions

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