LebGeeks

A community for technology geeks in Lebanon.

You are not logged in.

#1 April 6 2014

Freddy98
Member

Nvidea 8400 gs depth framebuffer support

Hello , I've been trying since two weeks to get shadow mapping to work (OpenGl) , but the depth isn't writing from the framebuffer to the texture (it's always white) . I've tried nearly everything , looked into many tutorials , including the opengl programming guide code , but nothing worked . Does anybody know if my graphic card Nvidea 8400 gs doesn't support writing depth from framebuffer to texture ?
Thanks !

Offline

#2 April 6 2014

Johnaudi
Member

Re: Nvidea 8400 gs depth framebuffer support

Can we see the code?

Offline

#3 April 6 2014

Freddy98
Member

Re: Nvidea 8400 gs depth framebuffer support

//this is outside the main loop to generate the depth texture and the framebuffer
GLuint depthTexture;
glGenTextures(1, &depthTexture);
glBindTexture(GL_TEXTURE_2D, depthTexture);
glTexImage2D(GL_TEXTURE_2D, 0,GL_DEPTH_COMPONENT, 1024, 1024, 0,GL_DEPTH_COMPONENT, GL_FLOAT, 0);
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_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
glBindTexture(GL_TEXTURE_2D, 0);

GLuint FramebufferName ;
glGenFramebuffers(1, &FramebufferName);
glBindFramebuffer(GL_FRAMEBUFFER , FramebufferName);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexture, 0);
glDrawBuffer(GL_NONE);
glBindFramebuffer(GL_FRAMEBUFFER , 0);
//this is inside the loop
glBindFramebuffer(GL_FRAMEBUFFER , FramebufferName);

glClearDepth(1.0f);
glClear(GL_DEPTH_BUFFER_BIT);

glViewport(0,0,1024,1024);

if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
      cout<<" YOU DUMB ! ";


Matrix DephtViewMatrix = IDENTITY_MATRIX;
DephtViewMatrix = MultiplyMatrices(DephtViewMatrix , TRANSLATION_MATRIX(0,-25,0));  //my own math header
DephtViewMatrix = MultiplyMatrices(DephtViewMatrix , XROTATION_MATRIX(-1.6));
shadow.UseProgram();
shadow.CreateProjection(60,1024,1024,0.1 ,70);//also tried to change the near and far planes , but nothing changed
shadow.setMVP(DephtViewMatrix , IDENTITY_MATRIX);

sphere.draws();
terrain.draws();
glBindFramebuffer(GL_FRAMEBUFFER ,0);
//vetrex shader
#version 330

layout(location=0) in vec3 in_Position;

uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
	
void main(void)
{   
   gl_Position = ProjectionMatrix * ViewMatrix * vec4(in_Position.xyz ,1) ;//tried dividing by 50 to put the values between 0 and 1 , but didn't work
       
 }

//fragment shader

#version 330

layout(location = 0) out float depth;

void main()
{
    depth = gl_FragCoord.z;
}

The problem is that I'm always getting a white texture . I tried rendering with colors , the scene was correct . I also tried writing manually the depth , it worked , but the process will be expensive because the colors are written . Well , it can be a small mistake , I'm still a beginner .

Offline

#4 April 6 2014

Johnaudi
Member

Re: Nvidea 8400 gs depth framebuffer support

I don't think it's a video card issue, the GPU is mainly used as an accelerator and since this is still a template script I pretty much know it can generate enough to show everything correctly.

Offline

#5 April 9 2014

Freddy98
Member

Re: Nvidea 8400 gs depth framebuffer support

I solved the issue finally . Now I have some nice shadows in my scene :) . The problem was mainly with the perspective projection , and I removed the texture comparison parameters .

Offline

Board footer