seems im having issues copy the depth texture, or anything for that matter from the frame buffer to a texture…
void Draw2DQuad(float screenwidth, float screenheight, float xsize, float ysize)
{
// some code to draw a quad with a texture so we can check... stuff
glViewport(0, 0, screenwidth,screenheight);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,screenwidth,screenheight,0,1,-1);
glDisable(GL_CULL_FACE);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
//glDisable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glNormal3f(0.0f,0.0f,1.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f,1.0f); glVertex2f(0.0f,0.0f);
glTexCoord2f(0.0f,0.0f); glVertex2f(0.0f,ysize);
glTexCoord2f(1.0f,0.0f); glVertex2f(xsize,ysize);
glTexCoord2f(1.0f,1.0f); glVertex2f(xsize,0.0f);
glEnd();
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
}
int main(int argc, char** argv)
{
//http://www.paulsprojects.net/tutorials/smt/smt.html
Engine engine;
Device* custom = new Device();
custom->Create(512.0f, 512.0f);
engine.SetDevice(custom);
engine.Create();
int windowWidth, windowHeight;
engine.GetDevice()->GetDeviceSize(windowWidth, windowHeight);
//load a model
Mesh mesh;
mesh.Load("data/scene.mdl");
int shadowMapSize = 512;
GLuint shadowTexture;
Vector3 lightPos(5.0f, 5.0f, 0.0f);
glEnable(GL_TEXTURE_2D);
//Create the shadow map texture
glGenTextures(1, &shadowTexture);
glBindTexture(GL_TEXTURE_2D, shadowTexture);
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapSize, shadowMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, shadowMapSize, shadowMapSize, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
Camera light;
light.SetLookAt(Vector3(1, 0, 0), Vector3(0, 1, 0), Vector3(0, 0, 1));
light.SetPosition(-10.0f, 0, 0);
light.Transform();
Matrix4 projection;
projection.LoadCurrent(GL_PROJECTION_MATRIX);
Matrix4 transform;
double rotation = 0.0f;
Camera camera;
camera.SetLookAt(Vector3(0, 0, 1), Vector3(0, 1, 0), Vector3(1, 0, 0));
camera.SetPosition(0, 0, 10.0f);
camera.Transform();
bool exit = false;
while(!exit)
{
engine.Update();
if (engine.GetInput()->KeyDown(SDLK_ESCAPE))
exit = true;
glEnable(GL_CULL_FACE);
//We use glScale when drawing the scene
glEnable(GL_NORMALIZE);
engine.GetDevice()->BeginRender();
rotation += 0.0000001f;
transform.RotateY(rotation);
//viewport need to be same size as shadow texture
glViewport(0, 0, shadowMapSize, shadowMapSize);
//Draw back faces into the shadow map
glCullFace(GL_FRONT);
//Disable color writes, and use flat shading for speed
glShadeModel(GL_FLAT);
glColorMask(1, 1, 1, 1);
// render from light
//light.LookAt();
camera.LookAt();
transform.SetM();
mesh.RenderNoMat();
//copy from frame buffer
//Read the depth buffer into the shadow map texture
glBindTexture(GL_TEXTURE_2D, shadowTexture);
// glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, shadowMapSize, shadowMapSize, 0);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, shadowMapSize, shadowMapSize, 0);
//glBindTexture(GL_TEXTURE_2D, shadowTexture);
Draw2DQuad(windowWidth, windowHeight, 100, 100);
engine.GetDevice()->EndRender();
}
return 0;
}
i’ve tried just copying everything from frame buffer using GL_RGB instead of depth texture, but even that doesnt work, all i get is a white texture, no screen grab of the screen as expected :-/