iDevGames Forums
Render to Texture behaves weirdly - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Render to Texture behaves weirdly (/thread-10886.html)

Render to Texture behaves weirdly - ardowz - Jan 24, 2014 12:33 PM

I followed this guide:

And omitted the depth attachment since I'm only trying to create a gradient quad. (Note, I'm writing using OpenGL 2.1 since that is what the API is only capable of)

This is how I set up my framebuffer.
GLint currentFboSample;
GLuint fboSample;
glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &currentFboSample);
glGenFramebuffersEXT(1, &fboSample);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboSample);

GLuint renderTexture;
glGenTextures(1, &renderTexture);
glBindTexture([outTex target], renderTexture);
glTexImage2D([outTex target], 0, GL_RGBA, [outTex width], [outTex height], 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, [outTex target], renderTexture, 0);
status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
       NSLog (@"Framebuffer not complete. Status = 0x%0x. Gradient texture missing", status);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboSample);
glViewport(0, 0, [outTex width], [outTex height]);
GLfloat halfW = [outTex width] / 2.0f;
GLfloat halfH = [outTex height] / 2.0f;
glColor3f(1, 0, 0);
glVertex3f(-halfW, -halfH, 0);

glColor3f(1, 0, 0);
glVertex3f(halfW, -halfH, 0);
glColor3f(1, 1, 0);
glVertex3f(halfH, halfH, 0);
glColor3f(1, 1, 0);
glVertex3f(-halfW, halfH, 0);

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

And this is How I used the texture

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, currentFboSample);
glColor3f(1, 1, 1);
glEnable([outTex target]);
glBindTexture([outTex target], renderTexture);

glVertex3f(0, 0, 0);
glTexCoord2f(0, 0);            
glVertex3f(150, 0, 0);
glTexCoord2f(0, [outTex height]);
glVertex3f(150, 150, 0);
glTexCoord2f([outTex width], [outTex height]);
glVertex3f(0, 150, 0);
glTexCoord2f([outTex width], 0);

The Values are:
[outTex target] is GL_TEXTURE_RECTANGLE
[outTex width] this one can vary the same way [outTex height] is, for example's sake it's 800 and 600 respectively.

The question now is, Given this set up, Whenever I move the camera the quad in the main buffer will move as well. For example, If I view the quad in a different angle, the texture inside will rotate and clip because of the quad's vertices.

Any thoughts on preventing this? I want it to be static like an ordinary texture that will just stick to the quad.

This is how it starts:
[Image: ScreenShot2014-01-24at113022AM.png]

If i zoom in it will start becoming an actual quad but I will start losing the other part of the gradient.

When I view the quad in a different angle this is what it looks like:
[Image: ScreenShot2014-01-24at113037AM.png]

RE: Render to Texture behaves weirdly - OneSadCookie - Jan 28, 2014 05:49 PM

OpenGL state is not reset on BindFramebuffer, you must manually reset any state you don’t want to carry over.

RE: Render to Texture behaves weirdly - ardowz - Feb 17, 2014 04:50 PM

Thanks, I placed the draw after manipulation which was causing this.