Advertisement

opengl render to texture problem

Started by November 09, 2014 03:11 AM
0 comments, last by Jan2go 10 years, 2 months ago

I'm so confused with the ogl rtt things. The tutorials I can find don't really explain how which is the one that renders the scene to a texture. I don't even know if my texture is valid or not.

So , which is the key code that really renders the texture.

assuming a empty texture is created by this:



m_fboTexture = pGraphics->CreateTexture2D(800,600,false);
 
then generate fbo


glGenFramebuffers(1,&m_fbo);
glBindFramebuffer(GL_FRAMEBUFFER,m_fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,m_fboTexture,0);

then how can i draw to it in my render loop?

It's such a confusing stuff :(

OpenGL alsways renders to the active framebuffer. Your call to glFramebufferTexture2D sets m_fboTexture as the active texture on slot 0 of your framebuffer. That means that all draw calls that you make after this call will render into this texture.
To bind the default framebuffer (i.e. to render to the backbuffer) you later need to call glFramebufferTexture2D with 0 on the texture argument.

This topic is closed to new replies.

Advertisement