Rendering "layers" in OpenGL ES

I'm making an iOS app and I want to be able to render with individual "layers" so that I can do blending between them and use shaders on each individually before blending them all together and rendering to the screen.

I understand that I will be rendering to Textures and then rendering these textures on top of each other in the framebuffer, but I am not understanding clearly what code needs to be written to follow this procedure. In another answer I found what I want to do, but I don't know what code accomplishes this task: How to achieve multi-layered drawing with OpenGL ES on iOS? (For example how do I "Bind texture 1, then draw it"? What does it mean to "Attach texture 1"?)

I've also looked at Apple's documentation regarding this technique but it isn't very clear about the steps or code for the actual rendering part of the process.

How would I go about doing this? (hopefully with code examples of each step because I haven't understood spotty instructions that expect me to just know what is needed for each step)

Here is an example of what I want to do with this. The spheres would be rendered into a "layer" or Texture2D which I would then pass through the shader, then render on top of a already partially rendered scene. I don't know exactly what kind of openGL code could do that.


You're looking at wrong place. To use OpenGL, you need to study OpenGL, not anything else. Apple doesn't provide any OpenGL documentation because it's an open standard, so the specs are freely published. Apple assumes you're already familiar with it.

  • OpenGL ES 2.0 spec
  • manual pages
  • I think you are having trouble because you don't have understanding of GL specific terms. The spec describes them very well and clearly. So, please read the spec. That will save your time A LOT. Or you will keep the trouble.

    Also, I like to introduce a site which has very nice conceptual description of OpenGL pipeline.

    http://www.songho.ca/opengl/

    This site is targeting desktop GL, and some API may be different a little. Please focus on conceptual understanding. For example, here's an illustration from the site.

    For more tutorials, google with proper keyword like OpenGL ES 2.0 tutorials (or how-tos). Here's an example link, and would be helpful. There're also many more tutorials. If spec is too boring, it's also good to have some fun with tutors.

    Update

    I like to say one more. IMO, the OpenGL is all about drawing triangles . Everything is ultimately converted into triangles in 3D space to represent some shape. Anything else all exists only for optimization. And in most cases, GL chooses batch processing for major optimization strategy. Because overhead of each drawing call is not affordable for most games.

    It's hard to start OpenGL ES because it's an optimized version of desktop GL, so all convenient or easy drawing features are stripped off. This is same even on recent version of desktop GL.

    So there's no such drawOneTriangle function. Instead GL has something like

  • make a buffer,
  • put list of many triangles there
  • select the buffer for next drawing.
  • draw all triangles in current buffer at once
  • delete the buffer.
  • By using buffer, you don't need to dispatch duplicated data to GPU from CPU. And GL uses this approach everywhere. For example, you don't have such drawOneTriangleWithTexture function to use textures. Instead, you have to

  • make a buffer
  • put list of many pixels there (bitmap)
  • select the buffer for next drawing.
  • draw all triangles with the texture pixel data in current buffers.
  • delete the buffer.
  • Everything overly complex stuffs on GL are all exists for optimization. This may look weird at first, but there're usually very good reasons for the design.

    Update 2

    Now I think you're looking for render to texture feature. (well actually you already mentioned this…)

    You can use a rendered image as a texture source. To do this,

  • you need to bind a frame-buffer with texture object rather then render-buffer object using some functions like glFramebufferTexture .

  • Once you render to a texture, and switch frame-buffer to final buffer, and bind the texture you drawn and others, and perform the final drawing. You need two frame buffers: one for render-to-texture, and one for final output.

  • 链接地址: http://www.djcxy.com/p/34022.html

    上一篇: OpenGL ES纹理质量下降

    下一篇: 在OpenGL ES中渲染“图层”