I want to generate shadow map,but all value got form depth buffer is zero.these1s my test code,where`s wrong? thanks!
#include<stdlib.h>
#include<stdio.h>
#include<glew.h>
#include<glut.h>
#pragma comment(lib,"glew32.lib")
static float litPos[]={100.0f,300.0f,100.0f,1.0f};
void init()
{
glewInit();
glDisable(GL_NORMALIZE);
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glClearDepth(0.0);
}
void createShadowMap()
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPerspective(150.0,1.0,1.0,400.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
gluLookAt(litPos[0],litPos[1],litPos[2],0,0,0,0,1,0);
glDepthMask(GL_TRUE);
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
glViewport(0,0,512,512);
glClear(GL_DEPTH_BUFFER_BIT);
glutSolidCube(2.0);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
float* dexel=new float[512*512];
glReadPixels(0,0,512,512,GL_DEPTH_COMPONENT,GL_FLOAT,dexel);
for(int i=0;i<512*512;i++){
printf("%f
",dexel[i]);
}
glRasterPos2i(0,0);
glDrawBuffer(GL_BACK);
glDrawPixels(512,512,GL_LUMINANCE,GL_FLOAT,dexel);
delete [] dexel;
glutSwapBuffers();
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH|GLUT_RGBA);
glutInitWindowPosition(0,0);
glutInitWindowSize(512,512);
glutCreateWindow("shadowMap");
init();
glutDisplayFunc(createShadowMap);
glutMainLoop();
return 0;
}