Using depth buffer with GL_LINES - opengl

I want to draw edges of an object with hidden edges removed. The idea I want to apply is to render the object's faces first to the depth buffer, then in a second pass drawing the edges with depth testing enabled.
Since not all triangle edges should be visible, the edges are stored separately (simple example: in a cube, the diagonal edges should not be visible, although they are there since a quad is rendered as two triangles). The faces are therefore drawn using GL_TRIANGLES, the edges are drawn uing GL_LINES with a separate vertex buffer.
The problem is that hidden edges are partly shown with this setup, and that visible edges are partly hidden. How can I achieve a proper result?
without depth testing:
with depth testing:
faces which are rendered to depth buffer:
I use a framebuffer with an attached color and depth buffer to draw my object.
// Color buffer setup.
glBindTexture(GL_TEXTURE_2D, objectEdges);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 640, 360, 0, GL_RGBA, GL_UNSIGNED_BYTE, nil);
// Depth buffer setup.
glBindRenderbuffer(GL_RENDERBUFFER, objectFaces);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 640, 360);
// Framebuffer setup.
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, objectEdges, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
GL_RENDERBUFFER, objectFaces);
assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
assert(glGetError() == GL_NO_ERROR);
This setup works without any problems. I draw my object as following:
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthMask(GL_TRUE);
glBindVertexArrayOES(vertexArray_faces);
glDrawArrays(GL_TRIANGLES, 0, vertexCount_faces);
glBindVertexArrayOES(0);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_FALSE);
glBindVertexArrayOES(vertexArray_edges);
glDrawArrays(GL_LINES, 0, vertexCount_edges);
glBindVertexArrayOES(0);
glDisable(GL_DEPTH_TEST);
The used shader is just a standard model-view-projection vertex shader, and a fragment shader which outputs white for all fragments.
GLKMatrix4 projectionMatrix =
GLKMatrix4MakePerspective(
GLKMathDegreesToRadians(65.0f), 640.0 / 360.0f, 0.01f, 10.0f);
GLKMatrix4 modelViewMatrix =
GLKMatrix4MakeLookAt(0.2f, 0.4f, 0.2f, 0.2f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

You're running into the issue that depth values are calculated for lines slightly differently than for filled primitives. The very thing you try to do is one of the reasons for the existance of the so called "polygon offest". The whole thing is described in the official programming guide in the appendix: "Hidden-Line Removal"

Related

Frame buffer not rendering depth into depth texture

So, i have this assignment about double pass rendering to compute shadows and I am trying to store the depth value of each of the objects of a scene and rendering them as a texture in another object.
I am using OpenGL, I don't really know where the error could be, but when analyzing a capture with RenderDoc, it says that the FBO (FrameBufferObject) is unused and also interprets what should be my 1st pass, a depth only pass, as a color pass.
/*-This is how I create the FBO and the texture to render the depth-*/
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
// Create texture for Depth image (first pass)
glGenTextures(1, &depthTexture);
glBindTexture(GL_TEXTURE_2D, depthTexture);
// Give pixel data to opengl
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1024, 1024, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, nullptr);
// WITH PCF for anti-aliasing shadow edges
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glGenFramebuffers(1, &FBO);
glBindFramebuffer(GL_FRAMEBUFFER, FBO);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,
depthTexture, 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
/*---------------------------END------------------------------------*/
/*---This is how I render all the objects (1st and second pass)-----*/
glViewport(0, 0, 1024, 1024);
glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
cube.FirstPass(light.getPos());
plane.FirstPass(light.getPos());
cone1.FirstPass(light.getPos());
cone2.FirstPass(light.getPos());
glFlush();
glFinish();
glViewport(0, 0, WIDTH, HEIGHT);
glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
cube.display(&cam, light.getPos());
plane.display(&cam, light.getPos());
viewport.display(&cam, light.getPos());
cone1.display(&cam, light.getPos());
cone2.display(&cam, light.getPos());
/*---------------------------END------------------------------------*/
/*---------This is how I do First Pass---------*/
//Here goes first pass
glBindFramebuffer(GL_FRAMEBUFFER, sceneManager.getFBO());
glClear(GL_DEPTH_BUFFER_BIT);
glUseProgram(DepthPass.shader);
glm::mat4 mtx = glm::perspective(glm::radians(60.0f), 1024.0f / 1024.0f, 5.0f, 40.0f);
DepthPass.setMat("M", mtx * glm::lookAt(glm::vec3(lightPos.x, lightPos.y, lightPos.z), glm::vec3(0.0, 0.0, 0.0), glm::vec3(0.0, 1.0, 0.0)) *
getModelToWorld());
glBindVertexArray(vao);
// Draw
glDrawArrays(GL_TRIANGLES, 0, ModelVertices.size());
glBindFramebuffer(GL_FRAMEBUFFER, 0);
/*---------------------------END------------------------------------*/
/*--This is what I pass to the shader that shows the depth texture--*/
DepthPass.setFloat("near", 5.0f);
DepthPass.setFloat("far", 40.0);
DepthPass.setInt("IsViewport", 1);
glActiveTexture(GL_TEXTURE0);
//GetDepthTexture() returns a handle of the texture created before
glBindTexture(GL_TEXTURE_2D, sceneManager.GetDepthTexture());
std::string textureName = "depthTexture";
DepthPass.setInt(textureName.c_str(), sceneManager.GetDepthTexture());
/*---------------------------END------------------------------------*/

Depth values and FBO

This is the lovely image I keep seeing gDebugger as I attempt to implement shadow maps. For reference I'm using the tutorial at http://fabiensanglard.net/shadowmapping/index.php. I've tried a couple different things with varying results, mostly either an FBO that has flat depth values(no slight variance indicating weird depth ranges) or this awesome guy. I've tried a huge amount of different things but alas, sans complete FBO failure, I mostly come back to this. For reference, here is what gDebugger spits out as my actual depth buffer:
So, with all that in mind, here's my code. Shader code is withheld because I have yet to get something in my FBO that's worth processing.
Here's how I initialize the FBO/Depth tex:
int shadow_width = 1024;
int shadow_height = 1024;
// Try to use a texture depth component
glGenTextures(1, &depth_tex);
glBindTexture(GL_TEXTURE_2D, depth_tex);
// GL_LINEAR does not make sense for depth texture. However, next tutorial shows usage of GL_LINEAR and PCF
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// Remove artefact on the edges of the shadowmap
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
// No need to force GL_DEPTH_COMPONENT24, drivers usually give you the max precision if available
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24,
shadow_width, shadow_height, 0, GL_DEPTH_COMPONENT,
GL_FLOAT, 0);
// attach the texture to FBO depth attachment point
glBindTexture(GL_TEXTURE_2D, 0);
// create a framebuffer object
glGenFramebuffers(1, &fbo_id);
glBindFramebuffer(GL_FRAMEBUFFER, fbo_id);
// Instruct openGL that we won't bind a color texture with the currently binded FBO
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D, depth_tex, 0);
// switch back to window-system-provided framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, 0);
And here's my render code:
glLoadIdentity();
float lpos[4] = {0,0,0,1};
float lpos3[4] = {5000,-500,5000,1};
glBindTexture(GL_TEXTURE_2D,0);
glBindFramebuffer(GL_FRAMEBUFFER,fbo_id);
glViewport(0, 0, 1024, 1024);
glClear(GL_DEPTH_BUFFER_BIT);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
setup_mats(lpos[0],lpos[1],lpos[2],lpos3[0],lpos3[1],lpos3[2]);
glCullFace(GL_FRONT);
mdlman.render_models(R_STENCIL);
mdlman.render_model(R_STENCIL,1);
set_tex_mat();
glBindFramebuffer(GL_FRAMEBUFFER,0);
glViewport( 0, 0, (GLsizei)800, (GLsizei)600 );
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
this->r_cam->return_LookAt();
gluPerspective(45,800/600,0.5f,2000.0f);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(&r_cam->getProjectionMatrix()[0][0]);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(&r_cam->getViewMatrix()[0][0]);
glCullFace(GL_BACK);
mdlman.render_models(R_NORM);
And here's how I draw objects for the FBO:
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER,models.at(mdlid).t_buff);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,models.at(mdlid).i_buff);
glNormalPointer(GL_FLOAT,sizeof(vert),BUFFER_OFFSET(sizeof(GLfloat)*2));
glVertexPointer(3, GL_FLOAT,sizeof(vert),BUFFER_OFFSET(sizeof(GLfloat)*5));
glDrawElements(GL_TRIANGLES,(models.at(mdlid).f_index.size())*3,GL_UNSIGNED_INT,0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
Some closing notes: the depth buffer image from gDebugger IS from the lights POV. My camera is quaternion based and uses matrices aligned with OGL for it's lookAt function(which is used to translate to light position/view.) I can provide the code for that if need be. Everything else is pretty much carbon-copied from the tutorial to make sure that I'm not doing or setting up something stupid.

Shadow Mapping is faint

I am trying to do OpenGL GLSL based shadow mapping. The trouble is that after I have finished rendering the shadow map, I am rendering the map to the screen to test whether the rendering works correctly or not i.e I am simply using the newly generated texture as a texture which I am mapping on to the screen. The expected result is that I will see the new texture. But instead, what i am seeing is a white area with the texture drawn but extremely faint. That is, if I tilt the screen at a certain angle only then I can see the faint outlines of the shadow map.
Can anyone tell me if I am doing anything wrong?
Here is relevant parts of my code :
void Init_FBO()
{
//glActiveTexture(GL_TEXTURE3);
GLfloat border[] = {1.0f, 0.0f, 0.0f, 0.0f};
glGenTextures(1, &depthTex);
glBindTexture(GL_TEXTURE_2D, depthTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24,900,900, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LESS);
glBindTexture(GL_TEXTURE_2D,0);
glGenFramebuffers(1, &shadowFBO);
glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTex, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0); // go back to the default framebuffer
// check FBO status
GLenum FBOstatus = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
if(FBOstatus != GL_FRAMEBUFFER_COMPLETE)
{
printf("GL_FRAMEBUFFER_COMPLETE failed, CANNOT use FBO\n");
}
else
{
printf("Frame Buffer Done Succesfully\n");
}
}
void generateShadowTex()
{
//Calculate final ligting properties
glm::vec4 a_f=light_ambient*mat_ambient;
glm::vec4 d_f=light_diffuse*mat_diffuse;
glm::vec4 s_f=light_specular*mat_specular;
int counter=0;
glEnable(GL_DEPTH_TEST); // need depth test to correctly draw 3D objects
glClearColor(0,0,0,1);
//glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
glCullFace(GL_FRONT);
if(wframe)
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
else
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glUseProgram(programObject);
//Draw the stuff using Light Position as camera
//glutSwapBuffers();
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D,depthTex);
glUseProgram(0);
}
void generateScene()
{
//Calculate final ligting properties
glm::vec4 a_f=light_ambient*mat_ambient;
glm::vec4 d_f=light_diffuse*mat_diffuse;
glm::vec4 s_f=light_specular*mat_specular;
int counter=0;
glEnable(GL_DEPTH_TEST); // need depth test to correctly draw 3D objects
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//Draw the stuff using camera as camera position
}
glutSwapBuffers();
glUseProgram(0);
}
void display()
{
glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO);
generateShadowTex();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
generateScene();
}
your depth texture is looking normally, depth covers range from near to far clip planes, you can set some reasonable clipping planes using glFrustumf(...)

Trailing shadows in Shadow Map

I have created the shadow map. However it has two problems :
1. The shadow comes into picture only when I change the model matrix. i.e initially there is no shadows, but when i press a key to move the figure, that is there is a change in the model matrix, the shadow appears.
2. There is a trail of old renders on the texture on the framebuffer that results in a long trail.
Can anyone shed any light on this?
THis is the screenshot of the problem
Edit Code here :
void generateShadowTex()
{
//Calculate final ligting properties
glm::vec4 a_f=light_ambient*mat_ambient;
glm::vec4 d_f=light_diffuse*mat_diffuse;
glm::vec4 s_f=light_specular*mat_specular;
int counter=0;
glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST); // need depth test to correctly draw 3D objects
glClearColor(0,0,0,1);
//glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
if(wframe)
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
else
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D,depthTex);
// MAths here for mvp manupulation
//Draw Elements
if(a<17 || a==18)
glDrawElements(GL_QUADS, masterNumberIndices[a], GL_UNSIGNED_INT, (char*) NULL+0);
else
glDrawElements(GL_TRIANGLES, masterNumberIndices[a], GL_UNSIGNED_INT, (char*) NULL+0);
glBindVertexArrayAPPLE(0);
}
glUseProgram(0);
}
void Init_FBO()
{
GLfloat border[] = {1.0f, 0.0f, 0.0f, 0.0f};
//glActiveTexture(GL_TEXTURE3);
glGenTextures(1, &depthTex);
glBindTexture(GL_TEXTURE_2D, depthTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24,900,900, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LESS);
glBindTexture(GL_TEXTURE_2D,0);
glGenFramebuffers(1, &shadowFBO);
glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTex, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0); // go back to the default framebuffer
// check FBO status
GLenum FBOstatus = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
if(FBOstatus != GL_FRAMEBUFFER_COMPLETE)
{
printf("GL_FRAMEBUFFER_COMPLETE failed, CANNOT use FBO\n");
}
else
{
printf("Frame Buffer Done Succesfully\n");
}
}
void display()
{
glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO);
generateShadowTex();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
generateScene();
}
You need to enable the depth buffer before you clear it. From the OpenGL specification:
If a buffer is not present, then a glClear directed at that buffer has no effect. 1
And:
GL_DEPTH_TEST
If enabled, do depth comparisons and update the depth buffer. Note that even if the depth buffer exists and the depth mask is non-zero, the depth buffer is not updated if the depth test is disabled. 2
As to the first part of your question, I can only guess what the problem might be, but you're probably not initializing the model matrix correctly.

OpenGL: Rendering to colour texture attached to FBO results in white texture

My problem is that after having set up a frame buffer object with a single colour texture attached to the GL_COLOR_ATTACHMENT0 point and rendering a number of objects to this texture when I then go to draw this to the screen I get a completely white texture.
Now I know the drawing code is correct as I can draw to the back buffer just fine, it's simply when the frame buffer becomes involved that the problem occurs. The drawing code uses a very basic shader that textures a quad.
My code is below:
// Create the FBO
glGenFramebuffers(1, &m_gbufferFBO);
glBindFramebuffer(GL_FRAMEBUFFER, m_gbufferFBO);
// Create a colour texture for use in the fbo
glGenTextures(1, &m_colourBuffer);
glBindTexture(GL_TEXTURE_2D, m_colourBuffer);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_colourBuffer, 0);
// check if the frame buffer was successfully created
CheckFrameBufferErrors();
CheckGLErrors();
// Begin rendering with the frame buffer
glBindFramebuffer(GL_FRAMEBUFFER, m_gbufferFBO);
glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT);
// Set the viewport to match the width and height of our FBO
glViewport(0, 0, m_width, m_height);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
// Clear buffer to whatever the clear colour is set to
glClearColor(m_clearColour.GetR(), m_clearColour.GetG(), m_clearColour.GetB(), m_clearColour.GetA());
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
Game::GetInstance().GetCamera()->ApplyViewTransform();
// RENDERING OF OBJECTS
glPopAttrib();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
Then the buffer's colour texture is rendered to the screen using the fixed function pipeline.
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
// Render the colour buffer to screen
glBindTexture(GL_TEXTURE_2D, m_colourBuffer);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_QUADS);
glTexCoord2f(0.f, 0.f); glVertex3f(0.f, 0.f, 0.f);
glTexCoord2f(1.f, 0.f); glVertex3f(m_width, 0.f, 0.f);
glTexCoord2f(1.f, 1.f); glVertex3f(m_width, m_height, 0.f);
glTexCoord2f(0.f, 1.f); glVertex3f(0.f, m_height, 0.f);
glEnd();
Any ideas on what I could be doing wrong here?
The FBO attached texture must not be bound, when the FBO is bound. A texture can never be a data source and sink at the same time.
For all texturing units and targets to which the texture has been bound you must bind another or no texture before binding the FBO as render destination.