문제

나는 정말로 이것에 대해 내 마음을 감싸 수 없습니다.

이전에 프레임 버퍼가 작동 할 수는 없었지만 지금은 가고 있습니다. 그러나 프레임 버퍼에서 생성 된 텍스처와 함께이 엄청나게 이상한 미러링이 진행되고있는 이유는 무엇입니까? 기본적으로 GL_TRIANGLE_FAN을 사용하여 0,0으로 텍스처를 그리려고 노력할 것이며, 텍스처는 오른쪽 상단 코너에서 정상 (더 많은)으로 나타납니다. 또한 왼쪽 하단 모서리에 나타납니다. 내 뷰포트 영역의 대부분 또는 전부를 동일한 텍스처로 채우면 결과는 추악한 Z-Fighting Outdrap입니다.

스크린 샷은 더 많은 정의를 할 것입니다.

원본 이미지 :

원본 http://img301.imageshack.us/img301/1518/testsprite.png

(0,0)에서 80x80을 그려

80x80 http://img407.imageshack.us/img407/8339/screenshot20100106at315.png

(0,0)에서 100x180을 그렸습니다.

100x180 http://img503.imageshack.us/img503/2584/screenshot20100106at316.png

(0,0)에서 320x480을 그려

320x480 http://img85.imageshack.us/img85/9172/screenshot20100106at317.png

그리고 여기 내 코드가 있습니다.

보기 설정 :

//Apply the 2D orthographic perspective.
glViewport(0,0,320,480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0, 320, 480, 0, -10000.0f, 100.0f);

//Disable depth testing.
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_DEPTH_TEST);

//Enable vertext and texture coordinate arrays.
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glShadeModel(GL_SMOOTH);

glClearColor(0.5f, 0.5f, 0.5f, 1.0f);   

glGetError(); // Clear error codes

sprite = [Sprite createSpriteFromImage:@"TestSprite.png"];
[sprite retain];

[self createTextureBuffer];

텍스처 버퍼를 만듭니다.

- (void) createTextureBuffer
{
    // generate texture
    glGenTextures(1, &bufferTexture);
    glBindTexture(GL_TEXTURE_2D, bufferTexture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0,  GL_RGBA, GL_UNSIGNED_BYTE, NULL);     // check if this is right

    // generate FBO
    glGenFramebuffersOES(1, &framebuffer);
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer);
    // associate texture with FBO
    glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, bufferTexture, 0);

    // clear texture bind
    glBindTexture(GL_TEXTURE_2D,0);

    // check if it worked (probably worth doing :) )
    GLuint status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
    if (status != GL_FRAMEBUFFER_COMPLETE_OES)
    {
        printf("FBO didn't work...");
    }   
}

렌더 루프를 실행하십시오.

- (void)drawView
{
    [self drawToTextureBuffer];

    // Make sure that you are drawing to the current context
    [EAGLContext setCurrentContext:context];

    //Bind the GLView's buffer.
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    glViewport(0, 0, 320, 480);

    //Clear the graphics context.
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

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

    //Rotate to match landscape mode.
    glRotatef(90.0, 0, 0, 1);
    glTranslatef(0.0f, -320.0f, 0.0f);

    //Store the coordinates/dimensions from the rectangle.
    float x = 0.0f;
    float y = 0.0f;
    float w = 480.0f;
    float h = 320.0f;

    // 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,  1,
        1,  1,
        0,  1
    };

    //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);

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

    //Bind this texture.
    glBindTexture(GL_TEXTURE_2D, bufferTexture);

    //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);
    }


    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];
}

첫 번째 패스에서 렌더 루프는 이미지를 FBO로 그립니다.

- (void)drawToTextureBuffer
{
    if (!bufferWasCreated)
    {
        // render to FBO
        glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer);
        // set the viewport as the FBO isn't be the same dimension as the screen
        glViewport(0, 0, 512, 512);

        glPushMatrix();



        //Store the coordinates/dimensions from the rectangle.
        float x = 0.0f;
        float y = 0.0f;
        float w = 320.0f;
        float h = 480.0f;

        // 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,  1,
            1,  1,
            1,  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);

        //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.
        glBindTexture(GL_TEXTURE_2D, sprite.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);
        }

        //Unbind this buffer.
        glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);

        bufferWasCreated = YES;
    }
}
도움이 되었습니까?

해결책

당신의 texcoords 안에 - (void)drawView 틀린 것 같습니다

GLfloat texcoords[] =
{
    0,  0,
    0,  1,
    1,  1,
    0,  1     << HERE should be 1, 0
};
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top