2009-12-05 5 views
12

iPhone의 OpenGL ES에서 오프 스크린 렌더링 버퍼를 만들려고합니다. 나는 다음과 같은 버퍼를 만들었습니다 :OpenGL ES (iPhone)에서 오프 스크린 렌더 버퍼에 그리기

 glGenFramebuffersOES(1, &offscreenFramebuffer); 
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, offscreenFramebuffer); 

    glGenRenderbuffersOES(1, &offscreenRenderbuffer); 
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, offscreenRenderbuffer); 
    glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, offscreenRenderbuffer); 

그러나 저장소를 렌더링하는 방법에 대해 혼란스러워합니다. 애플의 문서에서는 EAGLContext renderBufferStorage : fromDrawable : 메소드를 사용하라고 말하고 있지만 이것은 하나의 렌더링 버퍼 (표시되는 주된 버퍼)에 대해서만 작동하는 것처럼 보입니다. 일반 OpenGL 함수 glRenderBufferStorageOES를 사용하면 표시 할 수없는 것처럼 보입니다. 코드는 다음과 같습니다.

 // this is in the initialization section: 
    glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGB8_OES, backingWidth, backingHeight); 

    // and this is when I'm trying to draw to it and display it: 
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, offscreenFramebuffer); 
    GLfloat vc[] = { 
     0.0f, 0.0f, 0.0f, 
     10.0f, 10.0f, 10.0f, 
     0.0f, 0.0f, 0.0f, 
     -10.0f, -10.0f, -10.0f,   
    }; 

    glLoadIdentity(); 
    glEnableClientState(GL_VERTEX_ARRAY); 
    glVertexPointer(3, GL_FLOAT, 0, vc); 
    glDrawArrays(GL_LINES, 0, 4); 
    glDisableClientState(GL_VERTEX_ARRAY); 

    glBindRenderbufferOES(GL_RENDERBUFFER_OES, offscreenRenderbuffer); 
    [context presentRenderbuffer:GL_RENDERBUFFER_OES]; 

이렇게하면 아무 것도 화면에 표시되지 않습니다. 그러나 renderBufferStorage 메서드로 만든 버퍼에 대해 "오프 스크린 ... 버퍼"에 대한 참조를 전환하면 정상적으로 작동합니다.

제안 사항?

답변

2

@ david 좋은 아이디어 .. 당신이해야 할 일은 @prideout이 말한 것입니다. 텍스처를 만들어 렌더링하고 매번 쿼드에 텍스처를 사용하십시오. 한 번만 텍스처에 그려야합니다.

- (void)setUpTextureBuffer 
{ 
glGenFramebuffersOES(1, &texturebuffer); 
glBindFramebufferOES(GL_FRAMEBUFFER_OES, texturebuffer); 

// create the texture 
glGenTextures(1, &canvastexture); 
glBindTexture(GL_TEXTURE_2D, canvastexture); 
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, canvastexture, 0); 

GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); 
if(status != GL_FRAMEBUFFER_COMPLETE_OES) { 
    NSLog(@"failed to make complete framebuffer object %x", status); 
} 

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 

glClearColor(1.0, 1.0, 1.0, 1.0); 
glViewport(0, 0, 512, 512); 
glClear(GL_COLOR_BUFFER_BIT); 
} 



//setTargetToTexture() function 

glBindFramebufferOES(GL_FRAMEBUFFER_OES, tbuffer); 
glBindTexture(GL_TEXTURE_2D, allbrushes); 
glViewport(0, 0, 512, 512); 

//reset pointers after finishing drawing to textures 

glViewport(0, 0, BWIDTH, BHEIGHT); 
glVertexPointer(2, GL_FLOAT, 0, canvas); //canvas vertices 
glTexCoordPointer(2, GL_FLOAT, 0, texels); 
glBindTexture(GL_TEXTURE_2D, boundtexture); //bind to the texture which is the special render target 
glBindFramebufferOES(GL_FRAMEBUFFER_OES, fbuffer); //back to normal framebuffer 
1

(glRenderbufferStorage로 생성 한) 일반 렌더 버퍼를 표시 할 수 없으며 항상 오프 스크린입니다. presentRenderbuffer:renderbufferStorage:fromDrawable:을 사용하여 생성 된 렌더 버퍼에만 사용할 수 있습니다. 그 값인 presentRenderbuffer:을 확인했다면 실패한 것으로 간주해야합니다.

무엇을하려하십니까?

+0

저는 프레임마다 지속되어야하는 것들을 화면에 그려 넣는 게임을 쓰고 있습니다. 이러한 영구적 인 것들을 오프 스크린 버퍼에 그리고 나서 각 프레임에서 "blit"하여 화면에 표시하고 비 지속/휘발성을 그 위에 표시합니다. 객체의 수를 매우 빠르게 다루기가 어려울 수 있기 때문에 영구 객체의 목록을 유지하고 각 프레임을 다시 작성하지 않아도됩니다. –

+0

David, 해결 했습니까? 나는 같은 문제에 직면 해있다. – vargonian

3

오프 스크린 FBO와 함께 presentRenderbuffer을 사용할 수 없으므로, 을 사용하여 텍스처 개체와 연결 한 다음 질감이있는 전체 화면 쿼드를 렌더링해야합니다.

관련 문제