Okay, I wish I would have learned this before, but for my mobile game, I need to render my scene to a texture on devices with smaller resolutions such as the iPhone. Since my game works best on mobile and touch oriented devices, that's primarily what I'm aiming for. Now, the biggest issue with certain mobile devices is screen resolution. A 480x320 resolution is far too small, so my idea is to double the size by rendering to a texture (FBO), and scale touch locations accordinly. It's kinda hard to explain, but my game requires lots of rapid movements which require a fairly large screen resolution to pull off, and there's no need for this on iPads and what not. If there's a better solution, feel free to share it.
Once again, I hate dumping code on you all, but I really must get this working asap. These are the steps I've taken:
1. Create the FBO, RBO, and a texture, and bind them together.
2. Clear the screen to white.
3. Bind the FBO.
4. Clear the screen and draw as normal.
5. Unbind the FBO.
6. Draw a screen sized quad with the results.
So far, whenever I try, nothing renders.
FBO creation and usage:
bool create_render_target( int width, int height, rendertarget_t* rt )
{
glGenFramebuffers(1, &rt->fbo);
glBindFramebuffer(GL_FRAMEBUFFER, rt->fbo);
glGenRenderbuffers(1, &rt->rbo);
glBindRenderbuffer(GL_RENDERBUFFER, rt->rbo);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rt->rbo);
glGenTextures(1, &rt->tex);
glBindTexture(GL_TEXTURE_2D, rt->tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->tex, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE)
{
printf( "ogldrv_t::create_render_target(): failed to make complete framebuffer object 0x%X\n", status);
return false;
}
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
return true;
}
void set_render_target( rendertarget_t* rt )
{
GLenum error = glGetError();
if( rt )
glBindFramebuffer( GL_FRAMEBUFFER, rt->fbo );
else
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
if( (error = glGetError()) != GL_NO_ERROR )
printf( "Error binding render target!\n" );
}
Example usage:
This->m_ogldrv->set_render_target( &rt );
This->reshape_func( width, height );
This->display_func();
This->m_ogldrv->set_render_target( NULL );
Without the rendertarget stuff, it works fine. But when I do use it, nothing renders afterwards, all I see is the colour of the screen I set it to be cleared to. I've spent hours tweaking and googling, but no success so far. Would it have to do with the size of my render target? This sucks. Any ideas? Thanks.
Shogun.