• Advertisement
Sign in to follow this  

seeing depth as texture?

This topic is 4923 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

okay i was following a depth texture tutorial, but my version doesnt wanna work, but i wanna see what the depth texture looks like (ie. whats being rendered in the z-buffer), i copy the screen buffer as follows: glBindTexture(GL_TEXTURE_2D, shadowTexture); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowMapSize, shadowMapSize); where the texture is created like this: glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapSize, shadowMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); so i wanna draw a quad with it as a texture to see what it looks like, ideas?

Share this post


Link to post
Share on other sites
Advertisement
normaly I'd explain aload of stuff, however as I'm feeling lazy atm I'll just throw this code at you and field any questions later if needs be...

call this when you like as it preserves any modelview transformations you make, however it also plays with the viewport and doesnt restore it so atm its best just to make sure you give it the same size screen as it had before.


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);

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);
}







To use, bind texture (be it a normal texture or a depth texture) to texture unit zero and call.
Sizes are in pixels.
Quad is drawn in the top left corner.

Draw2DQuad(1280, 1024,300.0f,300.0f); // draws a 300x300 quad for example

Share this post


Link to post
Share on other sites
thats not the problem, problem is the texture showing up on the quad is blank

<source>
//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, 0, 0, 0);

// render from light
//light.LookAt();

camera.LookAt();
transform.SetM();
mesh.Render();

//copy from frame buffer
//Read the depth buffer into the shadow map texture
glBindTexture(GL_TEXTURE_2D, shadowTexture);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowMapSize, shadowMapSize);
</source>

oh then after that i draw the quad with the shadowTexture,

i can see the model on my screen (in red as expected), but not on the quad showing the texture, its just plain red?!

Share this post


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

  • Advertisement