Search code examples
openglgeometryvertex

Removing polygons from the screen (OpenGL)?


Assuming the code is:

    glLoadIdentity();
    glTranslatef(-1.5f,0.0f,-6.0f);
glBegin(GL_TRIANGLES);
        glVertex3f( 0.0f, 1.0f, 0.0f);
        glVertex3f(-1.0f,-1.0f, 0.0f);
        glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();

    glLoadIdentity();
    //Drawing another object...

How would I change the code to erase the object? I know that commenting out glTranslatef() will erase the triangle, but is that the formal way to do it?


Solution

  • If you put glClear at the start of the draw function (draw function is usually in a loop) you can simply choose not to redraw the triangle, drawing like that will leave no reference to your triangle.

    Also, glTranslatef() wont remove your triangle, glTranslatef() is just a function to move the current matrix (in your case the matrix with your triangle is being moved into the camera view)

    glClear()

    http://www.khronos.org/opengles/documentation/opengles1_0/html/glClear.html