开发者

iPhone opengl ES copy framebuffer into the renderbuffer

开发者 https://www.devze.com 2023-03-02 16:40 出处:网络
Hy folks, I\'m working on an animation in opengl es. The animation should draw squares. This works already, but how can I copy the content from the Framebuffer into the renderbuffer, the problem is t

Hy folks,

I'm working on an animation in opengl es. The animation should draw squares. This works already, but how can I copy the content from the Framebuffer into the renderbuffer, the problem is that with every frame only one square is on the display.

When I tested it in the simulator and it worked. With every new frame a knew square is drawn and the others that have been drawn already are still on the screen. But when I tested it on the device it didn't worked. The screen was just blinking.

I think this happens because my mac like every other computer is using doublebuffering and the iPhone dosen't.

Please help me.

This is how I'm setting up my Framebuffer:

- (BOOL)createFramebuffer {

    glGenFramebuffersOES(1, &viewFramebuffer);
    glGenRenderbuffersOES(1, &viewRenderbuffer);

    glBindF开发者_运维问答ramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
    glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);

    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
    if (USE_DEPTH_BUFFER) {
            glGenRenderbuffersOES(1, &depthRenderbuffer);
            glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
            glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
            glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
        }

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

        return YES;
    }

I also wrote a setupView Methode:

- (void)setupView {
    glClearColor(0.0f, 0.0f, 0.0f, 0.5f);               // Black Background
    //  glEnable(GL_DEPTH_TEST);                            // Enables Depth Testing
    //  glDepthFunc(GL_LEQUAL);                             // The Type Of Depth Testing To Do
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);  // Really Nice Perspective Calculations


    glViewport(0,0,backingWidth,backingHeight);                     // Reset The Current Viewport

    glMatrixMode(GL_PROJECTION);                        // Select The Projection Matrix
    glLoadIdentity();                                   // Reset The Projection Matrix

    // Calculate The Aspect Ratio Of The Window
    gluPerspective(45.0f,(GLfloat)backingWidth/(GLfloat)backingHeight,0.1f,100.0f);

    glMatrixMode(GL_MODELVIEW);                         // Select The Modelview Matrix

    isSetUp = YES;

}

This is my drawView Methode:

const GLfloat squareVertices[] = { -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 0.0f, -1.0f, -1.0f, 0.0f };

[EAGLContext setCurrentContext:context];

if (!isSetUp) {
    [self setupView];
}


glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);

//glClear(GL_COLOR_BUFFER_BIT);

//////////////////////Variablen
float xg = -26;
float yg = 35.5;
float z = -100.0;

float abstandXg = 3.0;
float abstandYg = 3.0;

for (int i = 0; i < 26; i++) {
    //arrayKoordinatenY[j] = y - abstandY * (j);
    for (int j = 0; j<=17; j++) {

        // glLoadIdentity(); 
        //arrayKoordinatenX[i] = x + abstandX * (i);
        //glTranslatef(arrayKoordinatenX[j],arrayKoordinatenY[i],z);

        glTranslatef(xg,yg,z);


        glEnableClientState(GL_VERTEX_ARRAY);


        glColor4f(0.0f,0.0f,0.0f,0.0f);
        glVertexPointer(3, GL_FLOAT, 0, squareVertices);
        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

        arrayKoordinatenX[j]=xg;
        xg = xg + abstandXg;        

    }
    xg = -26.0;

    arrayKoordinatenY[i]=yg;
    yg = yg - abstandYg;
}
//// Here comes the Part where the squares are draw
.
.
.
/////
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];
}


glMatrixMode(GL_PROJECTION);                        // Select The Projection Matrix
glLoadIdentity(); 

OK - but where is the same thing for GL_MODELVIEW ?

0

精彩评论

暂无评论...
验证码 换一张
取 消