Hi!
I've been lurking on gamedev for a while and this is my first actual post. I am looking for some help with implementing deferred rendering.
The thing I am struggling with at the moment is the actual rendering of the geometry to the g-buffer textures. I have read a lot on the subject but I still feel like I'm falling short.
The scene is just a square object rotating with a point light in the back (the light is irrelevant at this point though). The scene is rendering fine with forward rendering.
from Scene.cpp render function:
multiplerendertargets->begin();
// Base image texture
glActiveTexture(GL_TEXTURE0 + 0);
glBindTexture(GL_TEXTURE_2D, texture->textureID());
// Draw the triangles
glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, (void*)0);
multiplerendertargets->end();
where the begin/end functions do the following:
void FrameBufferObjects::begin()
{
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0, 0, this->width, this->height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
glDrawBuffers(3, buffers);
};
void FrameBufferObjects::end()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glPopAttrib();
};
What I am trying to achieve is to output the three textures to the screen separately, the function for this seems to be in working order when not making any draw calls. However, when I make the draw call above and try to output the textures, all I get is a black screen.
Geometry pass fragment shader:
/*
Geometry pass fragment shader (first pass)
*/
#version 400
in VertexData {
vec3 position;
vec3 normal;
vec2 tex_coords;
} vertexIn;
uniform sampler2D tDiffuse;
layout(location = 0) out vec4 diffuseOut;
layout(location = 1) out vec4 positionOut;
layout(location = 2) out vec4 normalsOut;
void main() {
diffuseOut = vec4(texture(tDiffuse,vertexIn.tex_coords).rbg, 0);
positionOut = vec4(vertexIn.position, 0);
normalsOut = vec4(vertexIn.normal, 0);
}
What the scene looks like with forward rendering:

I feel like I'm missing something elementary but I just have no clue what it is and I'm going a bit blind staring away at the code. I just don't see how it would result in all the textures being completely black?
Any and all help is much appreciated.![]()
