开发者

How to use different independent overlapping layers in opengl?

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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜