开发者

Removing polygons from the screen (OpenGL)?

开发者 https://www.devze.com 2023-02-19 23:06 出处:网络
Assuming the code is: glLoadIdentity(); glTranslatef(-1.5f,0.0f,-6.0f); glBegin(GL_TRIANGLES); 开发者_JS百科glVertex3f( 0.0f, 1.0f, 0.0f);

Assuming the code is:

    glLoadIdentity();
    glTranslatef(-1.5f,0.0f,-6.0f);
glBegin(GL_TRIANGLES);
 开发者_JS百科       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?


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


If you're asking how to make the triangle go away in subsequent frames, there's no need. Every frame time you're responsible for redrawing everything. OpenGL will not remember your triangle.


Putting an if around glBegin...glVertex...glEnd would be the most straightforward way.

0

精彩评论

暂无评论...
验证码 换一张
取 消