Render to Texture behaves weirdly

Posts: 11
Joined: 2013.10
Post: #1
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]
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #2
OpenGL state is not reset on BindFramebuffer, you must manually reset any state you don’t want to carry over.
Quote this message in a reply
Posts: 11
Joined: 2013.10
Post: #3
Thanks, I placed the draw after manipulation which was causing this.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Render video (e.g. QuickTime) to buffer or texture? Ingemar 14 12,964 Jun 8, 2011 04:09 PM
Last Post: mdejong1024
  Render to Texture? IBethune 5 6,101 May 2, 2007 04:25 AM
Last Post: IBethune
  PBuffer & Render to Texture (read & write) habicht 4 4,058 Feb 7, 2005 05:33 PM
Last Post: habicht
  Render to texture and Blending reubert 3 4,114 Oct 30, 2004 04:48 AM
Last Post: arekkusu
  Render-To-Texture? MacFiend 11 5,024 May 30, 2003 04:46 AM
Last Post: OneSadCookie