Jump to content

  • Log In with Google      Sign In   
  • 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.

  • You cannot reply to this topic
7 replies to this topic

#1 WiredCat   Members   -  Reputation: 236

Like
0Likes
Like

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);
glGenTextures(1, &shadowMapTexture);
glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
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);
//Read the depth buffer into the shadow map texture
glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
   // glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowMapSize, shadowMapSize);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24,
0, 0, shadowMapSize, shadowMapSize, 0);
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

Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 7802

Like
0Likes
Like

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.


#3 WiredCat   Members   -  Reputation: 236

Like
0Likes
Like

Posted 25 September 2012 - 06:08 AM

i cant fetch some adresses like: glShaderSourceARB
i did
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)wglGetProcAddress("glShaderSourceARB"); but i have NULL

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


#4 gradbot   Members   -  Reputation: 113

Like
0Likes
Like

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;

#5 Kaptein   Prime Members   -  Reputation: 2034

Like
0Likes
Like

Posted 26 September 2012 - 01:12 AM

i cant fetch some adresses like: glShaderSourceARB
i did
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)wglGetProcAddress("glShaderSourceARB"); but i have NULL


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"

#6 mhagain   Crossbones+   -  Reputation: 7802

Like
0Likes
Like

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.


#7 WiredCat   Members   -  Reputation: 236

Like
0Likes
Like

Posted 28 September 2012 - 07:49 AM

I cant find anything about loading shaders in gl 2.0 everything i have found uses glshaderSourceARB

#8 mhagain   Crossbones+   -  Reputation: 7802

Like
0Likes
Like

Posted 28 September 2012 - 08:01 AM

Try these:

http://www.arcsynthesis.org/gltut/Basics/Tut01%20Making%20Shaders.html
http://samplecodebank.blogspot.ie/2011/05/glshadersource-example.html

The first one is a more general GL 3.0 tutorial but the procedure for creating shaders is the very same.

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.





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.



PARTNERS