从屏幕上删除多边形(OpenGL)?
假设代码是:
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...
如何更改代码以擦除对象?我知道注释掉 glTranslatef() 会删除三角形,但这是正式的方法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果将 glClear 放在绘制函数的开头(绘制函数通常在循环中),您可以简单地选择不重绘三角形,这样绘制将不会留下对三角形的引用。
另外,glTranslatef()不会删除你的三角形,glTranslatef()只是一个移动当前矩阵的函数(在你的情况下,带有三角形的矩阵被移动到相机视图中)
glClear()
http://www.khronos.org/opengles/documentation/opengles1_0/html/glClear.html
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
如果您问如何使三角形在后续帧中消失,则没有必要。每一帧时间你都负责重绘所有内容。 OpenGL 不会记住你的三角形。
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.
在
glBegin
...glVertex
...glEnd
周围放置if
将是最直接的方法。Putting an
if
aroundglBegin
...glVertex
...glEnd
would be the most straightforward way.