• Create Account

## Render Depth to texture

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1WiredCat  Members

Posted 25 September 2012 - 04:31 AM

Fairly simple topic, but i can not make it work, the thing is that i don't know how to copy it to a texture.

I dont want to use any shaders just pure opengl ; )

The code might be handy:

But i don't know what type of texture use:
should it be? unsigned int Texture; or something else?

i use something like this to initalize:

glEnabled(GL_TEXUTRE_2D);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, 512, 512, 0, GL_DEPTH_COMPONENT24, GL_UNSIGNED_BYTE, 0);
glDisable(GL_TEXTURE_2D);


then i call:

glEnable(GL_TEXTURE_2D);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24,
glDisable(GL_TEXTURE_2D);


and i try to draw it but i see blank white texture (NOTE: i am using 24 bit depth buffer)]

Maybe i shouldn't see anything but how i am supposed to see if my shadowmap is working when i can't see it even on on blank quad (i expected to see a white texture with black (shadow ;P)

like i said working code would come handy without explenations

### #2mhagain  Members

Posted 25 September 2012 - 05:34 AM

It's very possible that blank white is actually correct.

As the depth buffer is non-linear the tendency is for most of the depth range to be clustered very close to the near clipping plane, with very few bits of precision as it starts to approach the far. What that means in terms of depth textures when they're drawn to screen (and therefore reduced to 8bpp for this purpose) is that nearby objects will occupy the vast majority of the 0-254 greyscale range, and further objects will all be rammed into the 255 pure-white part. The problem is that "further" in this case is really not that much further, so what you're seeing as pure white is just the effect of reducing a 24-bit depth buffer to 8 bits for display.

You say you don't want to use shaders, but shaders are also "pure OpenGL" - much more pure than the fixed pipeline in fact, as all modern hardware will be emulating the fixed pipeline via shaders anyway. Plus they're also very useful for re-linearizing depth in cases such as this.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.

### #3WiredCat  Members

Posted 25 September 2012 - 06:08 AM

i did

Edited by ___, 25 September 2012 - 10:19 AM.

Posted 25 September 2012 - 09:27 PM

It's very possible that blank white is actually correct.

Thanks mhagain! I was just doing that. It turns out all my Z data was between 0.998 and 1. I used the following code to see it.
return (1 - Depth.Sample(Sampler, input.cords)) * 500;

### #5Kaptein  Prime Members

Posted 26 September 2012 - 01:12 AM

i did

i believe even internal chip gpus have basic shader support
you need to have a context, aka. opengl32.dll must be loaded (or visually: a window open) to get an entry point
also, try different function names, such as simply: "glShaderSource"

### #6mhagain  Members

Posted 26 September 2012 - 08:57 AM

glShaderSourceARB is from the original GL_ARB_shader_objects extension and should not be used; the core GL2.0 and above versions have some subtle differences and are in general more robust on a wider range of hardware, as well as much more likely to be actually supported (i.e. a GPU vendor could implement GL2.0+ without implementing GL_ARB_shader_objects at all!)

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.

### #7WiredCat  Members

Posted 28 September 2012 - 07:49 AM

### #8mhagain  Members

Posted 28 September 2012 - 08:01 AM

Try these: