Hi,
I am trying to render a scene to an offscreen texture first and then draw this texture to the render buffer. I am using opengl ES 1.1 on XCode 3.1.4 for iphones.. This is what Have I done so far...
In my ES1renderer class declaration in ES1renderer.h
GLuint defaultFramebuffer,bigFrameBuffer, bigColorRenderBuffer,colorRenderbuffer,depthRenderbuffer;
GLuint offscreentexture;
In my init function in ES1Renderer.m
glGenFramebuffersOES(1, &defaultFramebuffer);
glGenRenderbuffersOES(1, &colorRenderbuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer);
glGenRenderbuffersOES(1, &bigColorRenderBuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, bigColorRenderBuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGBA8_OES,640, 960);
glGenRenderbuffersOES(1, &depthRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT24_OES, 640, 960);
glGenFramebuffersOES(1,&bigFrameBuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, bigFrameBuffer);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES,GL_RENDERBUFFER_OES,bigColorRenderBuffer);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
glGenTextures(1, &offscreentexture);
glBindTexture(GL_TEXTURE_2D, offscreentexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_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);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 640,960, 0,
GL_RGBA, GL_UNSIGNED_BYTE, 0);
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES,GL_TEXTURE_2D,offscreentexture, 0);
GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
if (status != GL_FRAMEBUFFER_COMPLETE_OES) {
NSLog(@"Incomplete FBO");
exit(1);
}
And in my render function
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, bigFrameBuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, bigColorRenderBuffer);
glViewport(0, 0, backingWidth, backingHeight);
//Then I draw my thing here...
glDrawElements(GL_TRIANGLES,countInd, GL_UNSIGNED_SHORT, waterIndices);
I believe whatever scene I have drawn is drawn to the offscreen texture...Is there anyway to check whether it is indeed drawn into the texture..Plus now I want to render the screen to a render buffer half the size of the buffer allocated above which is 640 * 960 (backingWidth and backingHeight in the above program) .. How can I achieve that...
Also this is the document which help me get thus far
http://iphone-3d-programming.labs.oreilly.com/ch06.html#ch06_id36002707
I think whatever I have done upto now is correct...(again is there any way of checking?)..But I am at a roadblock here..I somehow want to render the scene to a texture and then from texture to the screen..What is next think I got to do...