Results 1 to 2 of 2

Thread: Creating a texture from the zbuffer

  1. #1
    Member Newbie
    Join Date
    Oct 2001
    Location
    Orange County, Ca
    Posts
    41

    Creating a texture from the zbuffer

    Hi, not sure whether to post this in the beginnners or advanced forum so thought I would start here.

    I am trying to display the z buffer as a texture in the upper right corner of the screen. The following code seems to always give me a pure white texture. I should be getting a texture that shows the rendered scene in grayscale, kind of. I have a geforce 3. Anyone know what I am doing wrong? Is there a rendering state I need to change before displaying the texture or is there something I need to do before copying the z buffer to a texture?

    Render(); //renders lots of objects

    //texture has already been setup as
    //GL_DEPTH_COMPONENT
    //like this
    //glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, 256, 256, 0 );
    glBindTexture( GL_TEXTURE_2D, iTexture );
    glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, 256, 256 );

    glViewport( 640 - 256, 480 - 256, 256, 256 );

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    glDisable( GL_LIGHTING );
    glDisable( GL_CULL_FACE );
    glEnable( GL_TEXTURE_2D );

    glBegin( GL_QUADS );
    glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );

    glTexCoord2f( 0.0f, 0.0f );
    glVertex2f( -1.0f, -1.0f );

    glTexCoord2f( 1.0f, 0.0f );
    glVertex2f( 1.0f, -1.0f );

    glTexCoord2f( 1.0f, 1.0f );
    glVertex2f( 1.0f, 1.0f );

    glTexCoord2f( 0.0f, 1.0f );
    glVertex2f( -1.0f, 1.0f );
    glEnd();


    KC

  2. #2
    Member Contributor
    Join Date
    Aug 2000
    Location
    Epinay sur Seine, France
    Posts
    67

    Re: Creating a texture from the zbuffer

    Well, i didn't look at your code precisely but you need to resample the data you get from the glReadPixel since the depth values are NOT rgb related. Here a snip from my own code (that works) to save a depth buffer bitmap :

    Code :
    		glReadPixels(0, 0, gameInfo.screenwidth, gameInfo.screenheight, _GL_FORMAT, _GL_TYPE, p_depth_in);
     
    		// Resample depth values in order to use full [0.0 .. 1.0] range
    		{
    			// Research min and max depth values
    			min_depth = 1.0f;
    			max_depth = 0.0f;
    			p_depth = p_depth_in;
     
    			for (i = 0 ; i < nb_pixels ; i++, p_depth++) {
    				if (min_depth > *p_depth) {
    					min_depth = *p_depth;
    				}
    				if (max_depth < *p_depth) {
    					max_depth = *p_depth;
    				}
    			}
     
    			// Resample factor : stretch
    			depth_factor = 1.0f / (max_depth - min_depth);
    			p_depth = p_depth_in;
     
    			// Resampling....
    			for (i = 0 ; i < nb_pixels ; i++, p_depth++) {
    				*p_depth -= min_depth;
    				*p_depth *= depth_factor;
    				*p_depth *= 255.0f;
    			}
    		}
    One life for hate , one eternity for love [img]/forum/images/%%GRAEMLIN_URL%%/smile.gif[/img]

Similar Threads

  1. Crash while creating texture
    By shultays in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 01-08-2018, 05:28 PM
  2. Creating texture from HDR image
    By saam_b in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 01-25-2012, 05:22 AM
  3. Creating a 3d texture from data
    By imanoutkast in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 11-21-2009, 05:52 PM
  4. texture creating: what's wrong?
    By Digital-fol in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-26-2004, 02:33 PM
  5. Creating a texture
    By I_NeedHelp in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 01-15-2003, 01:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean