Advertisement Jump to content
Sign in to follow this  

OpenGL Problem with Deffered Rendering

This topic is 1663 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So i'm trying to implement deffered rendering in my first "graphic engine" using this tutorial: . And got some issues with drawing my position and normal to the texture. I think i'm sending everything alright, cause before it worked normally with forward rendering. This is how it looks.






Texture coords, diffuse and depth buffer are looking fine.


Here are my shaders for model geometry (for terrain it is similar, just with additional calculation)



#version 400
layout(location = 1) in vec3 vertex_position;
layout(location = 2) in vec2 vertex_texture;
layout(location = 3) in vec3 vertex_normals;

uniform mat4 pvw_matrix;
uniform mat4 world;

layout(location = 0) out vec2 texture_coords;
layout(location = 1) out vec3 normals;
layout(location = 2) out vec3 world_pos;

void main()
	vec4 tmp = (world * vec4(vertex_normals, 0.0));
	normals =;
	tmp = (world * vec4(vertex_position, 1.0));
	world_pos =;
	texture_coords = vertex_texture;
	gl_Position = pvw_matrix * vec4( vertex_position, 1.0 );


#version 400

layout(location = 0) in vec2 TexCoord;
layout(location = 1) in vec3 Normal;
layout(location = 2) in vec3 WorldPos;

layout (location = 0) out vec3 WorldPosOut;
layout (location = 1) out vec3 DiffuseOut;
layout (location = 2) out vec3 NormalOut;
layout (location = 3) out vec3 TexCoordOut;

uniform sampler2D sampler;  

void main()
	vec4 texel = texture(sampler, TexCoord);
	WorldPosOut = WorldPos; 
	DiffuseOut =;
	NormalOut = normalize(Normal);
	TexCoordOut = vec3(TexCoord, 0.0);

Thanks for any clues, that will help me solve this riddle. I will paste more code if necessary. Link to my repo is here:


Share this post

Link to post
Share on other sites
I took the liberty to look the format up in his repo:
for (unsigned int i = 0 ; i < GBUFFER_NUM_TEXTURES ; i++) {
    glBindTexture(GL_TEXTURE_2D, m_textures[i]);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, windowWidth, windowHeight, 0, GL_RGB, GL_FLOAT, NULL);
    glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, m_textures[i], 0);
glBindTexture(GL_TEXTURE_2D, m_depthTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, windowWidth, windowHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthTexture, 0);
Now I'm pretty sure, there are no real GL_RGB formats, only GL_R, GL_RG and GL_RGBA. But OpenGL should extend that automatically. However note, that the textures are incomplete: no calls to glTexParameter{i,f}. I would expect like this:
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);

Regarding the CodeXL images, can you hover over the pixels with your mouse and look at the numeric content? Maybe the colors are just the result of some weird banding filter, that CodeXL automatically applies to all float buffers.

Also note, that your GBuffer is extremely big. You currently have 64 bytes per pixel, not counting the depth buffer. Once you have everyting running correctly, you might want to decrease that a bit.

Share this post

Link to post
Share on other sites

Sry i didnt answer, timezone...


But what about texture initializing, i did everything according to the tutorial and there was no line about setting any TexParameter. I checked out values in CodeX and you may be right about this filtering, i will try to save those textures as an image from my code and check results there.


And yeah i will have to think about optimalization, but now it is my least problem.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!