Draw to offscreen renderbuffer in OpenGL ES (iPhone)

Posted by David Ensminger on Stack Overflow See other posts from Stack Overflow or by David Ensminger
Published on 2009-12-05T21:34:42Z Indexed on 2010/06/18 15:13 UTC
Read the original article Hit count: 652

Filed under:
|

I'm trying to create an offscreen render buffer in OpenGL ES on the iPhone. I've created the buffer like this:

    	glGenFramebuffersOES(1, &offscreenFramebuffer);
	glBindFramebufferOES(GL_FRAMEBUFFER_OES, offscreenFramebuffer);

	glGenRenderbuffersOES(1, &offscreenRenderbuffer);
	glBindRenderbufferOES(GL_RENDERBUFFER_OES, offscreenRenderbuffer);
	glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, offscreenRenderbuffer);

But I'm confused on how to render the storage. Apple's documentation says to use the EAGLContext renderBufferStorage:fromDrawable: method, but this seems to only work for one render buffer (the main one being displayed). If I use the normal OpenGL function glRenderBufferStorageOES, then I can't seem to get it to display. Here's the code:

    	// this is in the initialization section:
	glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGB8_OES, backingWidth, backingHeight);

	// and this is when I'm trying to draw to it and display it:
	glBindFramebufferOES(GL_FRAMEBUFFER_OES, offscreenFramebuffer);
	GLfloat vc[] = {
		0.0f, 0.0f, 0.0f,
		10.0f, 10.0f, 10.0f,
		0.0f, 0.0f, 0.0f,
		-10.0f, -10.0f, -10.0f,			
	};

	glLoadIdentity();
	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_FLOAT, 0, vc);
	glDrawArrays(GL_LINES, 0, 4);
	glDisableClientState(GL_VERTEX_ARRAY);

	glBindRenderbufferOES(GL_RENDERBUFFER_OES, offscreenRenderbuffer);
	[context presentRenderbuffer:GL_RENDERBUFFER_OES];

Doing it this way, nothing is displayed on the screen. However, if I switch out the references to "offscreen...Buffer" to the buffers that were created with the renderBufferStorage method, it works fine.

Any suggestions?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about opengl-es