2009-12-23 1 views
3

StackOverflow에서 몇 가지 게시물을 사용하여 프레임 버퍼를 사용하여 간단한 렌더링 - 텍스처를 만들었습니다.framebuffer를 사용하여 텍스처로 렌더링하려고하면 항상 흰색 텍스처가 발생합니다.

문제는 작동하지 않는다는 것입니다. 내 마지막 질감은 흰색 사각형이므로 뭔가가 잘못되었습니다. 나는 gl 오류를 전혀 얻지 못하고있다. 여기 내 코드가있다.

인스턴스 변수를 선언하십시오.

GLuint texture; 
GLuint textureFrameBuffer; 

텍스처와 프레임 버퍼를 생성하십시오.

glGetError(); 

    //Generate the texture that we will draw to (saves us a lot of processor). 
    glEnable(GL_TEXTURE_2D); 
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 

    // Use OpenGL ES to generate a name for the texture. 
    // Pass by reference so that our texture variable gets set. 
    glGenTextures(1, &texture); 

    // Bind the texture name. 
    glBindTexture(GL_TEXTURE_2D, texture); 

    // Specify a 2D texture image, providing a pointer to the image data in memory. 
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 

    //Create a frame buffer to draw to. This will allow us to directly edit the texture. 
    GLint oldFBO; 
    glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &oldFBO); 
    glGenFramebuffersOES(1, &textureFrameBuffer); 
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, textureFrameBuffer); 
    glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, texture, 0); 

    glBindFramebufferOES(GL_FRAMEBUFFER_OES, oldFBO); 

    GLenum err = glGetError(); 
    if (err != GL_NO_ERROR) 
    { 
     NSLog(@"Error on framebuffer init. glError: 0x%04X", err); 
    } 

큰 문자열을 프레임 버퍼에 그립니다.

glGetError(); 

GLint oldFBO; 
glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &oldFBO); 

//Bind our frame buffer. 
glBindFramebufferOES(GL_FRAMEBUFFER_OES, textureFrameBuffer); 

//Clear out the texture. 
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

//Draw the letters to the frame buffer. (calls glDrawArrays a bunch of times, binds various textures, etc.) Does everything in 2D. 
[self renderDialog:displayString withSprite:displaySprite withName:displaySpriteName]; 

//Unbind the frame buffer. 
glBindFramebufferOES(GL_FRAMEBUFFER_OES, oldFBO); 

GLenum err = glGetError(); 
if (err != GL_NO_ERROR) 
{ 
    NSLog(@"Error on string creation. glError: 0x%04X", err); 
} 

그리기.

glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 

    glGetError(); 

    //Draw the text. 
    [EAGLView enable2D]; 

    //Push the matrix so we can keep it as it was previously. 
    glPushMatrix(); 

    //Store the coordinates/dimensions from the rectangle. 
    float x = 0; 
    float y = [Globals getPlayableHeight] - dialogRect.size.height; 
    float w = [Globals getPlayableWidth]; 
    float h = dialogRect.size.height; 

    // Set up an array of values to use as the sprite vertices. 
    GLfloat vertices[] = 
    { 
     x,  y, 
     x,  y+h, 
     x+w, y+h, 
     x+w, y 
    }; 

    // Set up an array of values for the texture coordinates. 
    GLfloat texcoords[] = 
    { 
     0,   0, 
     0,   h/128, 
     w/512, h/128, 
     w/512, 0 
    }; 

    //Render the vertices by pointing to the arrays. 
    glVertexPointer(2, GL_FLOAT, 0, vertices); 
    glTexCoordPointer(2, GL_FLOAT, 0, texcoords); 

    // Set the texture parameters to use a linear filter when minifying. 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 

    //Allow transparency and blending. 
    glEnable(GL_BLEND); 
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 

    //Enable 2D textures. 
    glEnable(GL_TEXTURE_2D); 

    //Bind this texture. 
    [EAGLView bindTexture:texture]; 

    //Finally draw the arrays. 
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 

    //Restore the model view matrix to prevent contamination. 
    glPopMatrix(); 

    GLenum err = glGetError(); 
    if (err != GL_NO_ERROR) 
    { 
     NSLog(@"Error on draw. glError: 0x%04X", err); 
    } 

다른 모든 것들은 다른 컨텍스트에서 잘 작동합니다. 어떤 아이디어? Framebuffers에 대해서는 거의 알지 못하므로 문제 해결에 도움이 될 것입니다.

답변

4

텍스처 매개 변수는 텍스처 단위로 설정됩니다. 렌더링 한 텍스처가 만들어 지거나 바인딩되기 전에 게시 한 코드가 GL_TEXTURE_MIN_FILTER으로 설정되어있는 것으로 보입니다. 다른 곳에서 필터를 설정하지 않고 나머지 레벨에 대해 텍스처 이미지를 지정하지 않은 경우 텍스처가 불완전한 것일 수 있습니다. 따라서 흰색을 얻게됩니다.

나중에 참조하기 위해 프레임 버퍼 설정 후 GL 오류가 없다고해서 프레임 버퍼가 렌더링에 사용할 수 있다는 의미는 아닙니다. glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES)을 호출하고 GL_FRAMEBUFFER_COMPLETE_OES이 반환되는지 확인하여 프레임 버퍼가 완료되었는지도 확인해야합니다.

+0

시도해 보겠습니다. 이전에 실제로 완료 확인을 했었고 사실이었습니다. 위 코드에 포함하지 않았습니다. 이 프레임 버퍼가 완료되면 모든 것이 제대로 작동한다는 것을 의미하지는 않는다고 가정합니다. 또한, 내가 GL_TEXTURE_MIN_FILTER에 대해 당신을 따르는 지 확신하지 못한다. glGenTextures (첫 번째 코드 블록 참조)를 호출하기 전에이를 설정했다. – Eli

+0

각 텍스처에는 고유 한 축소/확대 기능과 랩 모드가 있습니다. glTexParameterf를 호출하면 함수가 호출 될 때 현재 바인딩 된 텍스처에만 영향을줍니다. 렌더링하는 텍스처에 대한 축소 함수를 변경하려면 텍스처를 만들고 바인딩 한 후 glTexParameterf를 호출해야합니다. 프레임 버퍼 완성도는 특정 케이스와 관련이없는 것처럼 들리지만,보다 이국적인 프레임 버퍼 객체 구성을 염두에 두는 것이 좋습니다. – Pivot

관련 문제