I want to use offscreen rendering using openGL es 2.0 and GLSL shader
I setup FBO and it seems working except there are two problems
1) The program goes about 30 fps but all the sudden, it drops to 20fps and then come back to 30 fps again, then few secs later, drops to 20fps again then come back to 30fps and so on...(keeps going on like that) and I don't know what cause this random pause/delay
2) When I close the application, it does not respond for awhile. In other words, it seems like there are some data to clean up or some delay...So when I close the program, it does not do so until few seconds later.
Am I doing something wrong? Is there anyway I can fix these?
Here is my code:
My init function:
glGenFramebuffers(1,&frameBuf);
glGenRenderbuffers(1,&renderBuf);
glBindRenderbuffer(GL_RENDERBUFFER,renderBuf);
glRenderbufferStorage(GL_RENDERBUFFER,GL_RGBA4,640,480);
glBindRenderbuffer(GL_RENDERBUFFER,0);
glBindFramebuffer(GL_FRAMEBUFFER,frameBuf);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_RENDERBUFFER,renderBuf);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE)
printf("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT\n");
else
printf("COMPLETE\n");
glBindFramebuffer(GL_FRAMEBUFFER,0);
The my draw function:
glBindFramebuffer(GL_FRAMEBUFFER, frameBuf);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLfloat vertices1[] = {
-1.0,-1.0,-1.0, 1.0,-1.0,-1.0, -1.0,1.0,-1.0,
1.0, 1.0,-1.0, -1.0,1.0,-1.0, 1.0,-1.0,-1.0
};
glVertexAttribPointer(vertexAttr1, 3, GL_FLOAT, GL_FALSE, 0, vertices1);
glEnableVertexAttribArray(vertexAttr1);
GLfloat texCoord[] = {
0.0f,0.0f, 1.0f,0.0f, 0.0f,1.0f,
1.0f,1.0f, 0.0f,1.0f, 1.0f,0.0f
};
glVertexAttribPointer(texCoordAttr1, 2, GL_FLOAT, GL_FALSE, 0, texCoord);
glEnableVertexAttribArray(texCoordAttr1);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindFramebuffer(GL_FRAMEBUFFER, 0);