Render to Texture behaves weirdly
I followed this guide:
http://www.gamedev.net/page/resources/_/...-101-r2331
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.
And this is How I used the texture
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]](http://img.photobucket.com/albums/v442/ardo/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:
http://www.gamedev.net/page/resources/_/...-101-r2331
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.
Code:
GLint currentFboSample;
GLuint fboSample;
glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, ¤tFboSample);
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);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
{
NSLog (@"Framebuffer not complete. Status = 0x%0x. Gradient texture missing", status);
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboSample);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0, 0, [outTex width], [outTex height]);
glClear(GL_COLOR_BUFFER_BIT);
GLfloat halfW = [outTex width] / 2.0f;
GLfloat halfH = [outTex height] / 2.0f;
glBegin(GL_QUADS);
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);
glEnd();
glPopAttrib();
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
And this is How I used the texture
Code:
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, currentFboSample);
glColor3f(1, 1, 1);
glEnable([outTex target]);
glBindTexture([outTex target], renderTexture);
glBegin(GL_QUADS);
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);
glEnd();
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]](http://img.photobucket.com/albums/v442/ardo/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]](http://img.photobucket.com/albums/v442/ardo/ScreenShot2014-01-24at113037AM.png)
OpenGL state is not reset on BindFramebuffer, you must manually reset any state you don’t want to carry over.
Thanks, I placed the draw after manipulation which was causing this.
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
Render video (e.g. QuickTime) to buffer or texture? | Ingemar | 14 | 19,825 |
Jun 8, 2011 04:09 PM Last Post: mdejong1024 |
|
Render to Texture? | IBethune | 5 | 9,137 |
May 2, 2007 04:25 AM Last Post: IBethune |
|
PBuffer & Render to Texture (read & write) | habicht | 4 | 7,173 |
Feb 7, 2005 05:33 PM Last Post: habicht |
|
Render to texture and Blending | reubert | 3 | 6,287 |
Oct 30, 2004 04:48 AM Last Post: arekkusu |
|
Render-To-Texture? | MacFiend | 11 | 9,285 |
May 30, 2003 04:46 AM Last Post: OneSadCookie |