OpenGLES - 仅渲染一次背景图像而不擦除它

时间:2010-06-18 09:47:40

标签: iphone objective-c opengl-es

第一次在这里问一个问题但是一直在看别人的答案。我自己的问题是改善我的计划的表现。

目前我正在通过我的程序擦除viewFrameBuffer,然后先渲染背景图像,然后渲染场景的其余部分。我想知道如何渲染一次背景图像,只擦拭场景的其余部分以进行更新/重新渲染。

我尝试使用单独的缓冲区,但我不确定如何将这个新缓冲区呈现给渲染缓冲区。

// Set the current EAGLContext and bind to the framebuffer.  This will direct all OGL commands to the
// framebuffer and the associated renderbuffer attachment which is where our scene will be rendered
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);

// Define the viewport.  Changing the settings for the viewport can allow you to scale the viewport
// as well as the dimensions etc and so I'm setting it for each frame in case we want to change i
glViewport(0, 0, screenBounds.size.width , screenBounds.size.height);

// Clear the screen.  If we are going to draw a background image then this clear is not necessary
// as drawing the background image will destroy the previous image
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);

glClear(GL_COLOR_BUFFER_BIT);

// Setup how the images are to be blended when rendered.  This could be changed at different points during your
// render process if you wanted to apply different effects
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

switch (currentViewInt) {
    case 1: 
    {   
        [background render:CGPointMake(240, 0) fromTopLeftBottomRightCenter:@"Bottom"];
        // Other Rendering Code
    }}

// Bind to the renderbuffer and then present this image to the current context
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];

希望通过解决这个问题,我还能够实现另一个缓冲区来渲染粒子,因为我可以将它们设置为始终使用黑色背景作为alpha源。非常感谢任何帮助

1 个答案:

答案 0 :(得分:0)

如果要将缓冲区绘制到另一个缓冲区中,这意味着第一个缓冲区必须是纹理,因此您可以将纹理映射四边形绘制到另一个缓冲区中。

如果您将背景作为纹理(最有可能),那么只需要具有该纹理,使用内容(粒子等)绘制另一个纹理(使用FBO绘制)并将它们绘制在一起以将最终场景合成为屏幕。