如何在opengl中使用不同的独立重叠层?
我想知道是否可以有多个可以独立操作并以重叠方式显示的图层。
这就是我想做的。我正在实现一个 Turtle Graphics API。我想制作乌龟运动的动画。我想知道是否可以将所有图形放在一个图层中,而将乌龟(我使用小等腰三角形表示)单独放在另一图层中,以便我可以通过清除该图层来擦除乌龟,而不影响图形层和在海龟平面上的另一个位置/方向重新绘制海龟。
I want to know if it is possible to have multiple layers which can be manipulated independently and displayed in an overlapping manner.
Here is what I want to do. I'm implemeting a Turtle Graphics API. I want to animate the turtle movement. I was wondering if i could have all the graphics in one layer and the turtle (which I'm representing using a small isosceles triangle) alone in another layer so that I can erase the turtle by clearing this layer and without affecting the graphics layer and redraw the turtle in another location/orientation on the turtle plane.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OpenGL 不是场景图。
OpenGL(通常)不是您想要尝试最小化重绘的经典 2D 帧缓冲区。使用 OpenGL,您通常会在清除深度和颜色缓冲区后每帧重新绘制整个场景。
您有多种选择:
1) 禁用深度缓冲区/深度检查并将图层从后向前渲染。
2) 确保每个图层都有适当的 Z 坐标并以任意顺序渲染它们,让 Z 缓冲区负责正确分层。如果您的图层是半透明的,则不起作用。
3) 通过您想要支持的任何方法(
glCopyPixels()
、PBO、FBO、开罗)。渲染一个屏幕大小的纹理四边形,并将乌龟放在上面。4)在每一帧中完整地重新绘制海龟路径,首先是最旧的点。除非行数达到数十万,否则不应慢。确保使用顶点数组或 VBO。
OpenGL is not a scene graph.
OpenGL is (generally) not a classic 2D framebuffer where you want to try to minimize redraws. With OpenGL you'll generally be redrawing the entire scene each frame after clearing the depth and color buffers.
You have several options:
1) Disable the depth buffer/depth check and render your layers back to front.
2) Make sure each of your layers has an appropriate Z coordinate and render them in whatever order, letting the Z buffer take care of getting the layering right. Won't work if your layers are translucent.
3) Render your turtle path to a texture via whatever method you feel like supporting (
glCopyPixels()
, PBOs, FBOs, cairo). Render a screen-sized textured quad and your turtle on top.4) Redraw your turtle path in full each frame, oldest point first. Shouldn't be slow unless you have line count in the hundreds of thousands. Make sure to use vertex arrays or VBOs.