renderbuffer objects

  • Follow


Hi!

I am reading about renderbuffer objects (as a part of the fbo extension) 
and know that they can be used to save the depth buffer.
I just wonder how to render this depth buffer efficiently to the screen.

1) I am confused about the values of the depth component. I read 
somewhere that they fall in a range of -1 to 1, another source said 0 to 
1. what is right?

2) If the depth buffer falls into 0 to 1, is there are better way than 
switching the read buffer to my "depth" renderbuffer and copying the 
content to a separate texture, esp. if a texture might not be resident? 
I mean that the copy to a non-resident texture would copy everything 
back to system memory or am I wrong? (-> glCopyTexImage2D)

3) If I have to use glCopyTexImage() which format should I use? my 
normal depth buffer has 24 bits but there is no internal format which 
would fit?

4) If I want to access this depth buffer from a vertex shader. I have to 
set up some kind of depth texture. How to achieve this goal?

Thanks in advance,

David
0
Reply David 10/22/2005 1:49:03 PM

"David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
news:3ruuajFko3arU1@news.dfncis.de...
> Hi!
>
> I am reading about renderbuffer objects (as a part of the fbo 
> extension) and know that they can be used to save the depth buffer.
> I just wonder how to render this depth buffer efficiently to the 
> screen.
>
> 1) I am confused about the values of the depth component. I read 
> somewhere that they fall in a range of -1 to 1, another source said 0 
> to 1. what is right?

    I believe [0,1] is right. But someone better confirm this ;)

> 2) If the depth buffer falls into 0 to 1, is there are better way than 
> switching the read buffer to my "depth" renderbuffer and copying the 
> content to a separate texture, esp. if a texture might not be 
> resident? I mean that the copy to a non-resident texture would copy 
> everything back to system memory or am I wrong? (-> glCopyTexImage2D)
>
> 3) If I have to use glCopyTexImage() which format should I use? my 
> normal depth buffer has 24 bits but there is no internal format which 
> would fit?
>
> 4) If I want to access this depth buffer from a vertex shader. I have 
> to set up some kind of depth texture. How to achieve this goal?

    Instead of using a render buffer, you might want to attach a texture 
to the frame buffer object. You can use the ARB_depth_texture extension 
to get a texture format capable of holding depth values. To render the 
texture (not 'to the texture', to prevent misunderstandings), you should 
be able to use the ARB_shadow extension, using GL_NONE for the 
compare-mode.

    You can access the texture through a sampler with shadow* functions. 
This assumes that your function is a depth texture. Otherwise you would 
use texture* functions. You can read about those in the GLSL Language 
Specification at http://www.opengl.org/documentation/oglsl.html.

hth

-- 
jb

(reply address in rot13, unscramble first) 


0
Reply Jakob 10/22/2005 5:29:53 PM


Hello!

I would like to come back to the depth texture issues.
[...]
>>3) If I have to use glCopyTexImage() which format should I use? my 
>>normal depth buffer has 24 bits but there is no internal format which 
>>would fit?
>>
>>4) If I want to access this depth buffer from a vertex shader. I have 
>>to set up some kind of depth texture. How to achieve this goal?
> 
> 
>     Instead of using a render buffer, you might want to attach a texture 
> to the frame buffer object. You can use the ARB_depth_texture extension 
> to get a texture format capable of holding depth values. To render the 
> texture (not 'to the texture', to prevent misunderstandings), you should 
> be able to use the ARB_shadow extension, using GL_NONE for the 
> compare-mode.
> 
>     You can access the texture through a sampler with shadow* functions. 
> This assumes that your function is a depth texture. Otherwise you would 
> use texture* functions. You can read about those in the GLSL Language 
> Specification at http://www.opengl.org/documentation/oglsl.html.
> 

I managed to set up a FBO and a renderbuffer for my depth buffer 
following the FBO tutorial from the current ATI SDK while using the FBO 
convenience class found at GPGPU.org.

this->fbo=new FramebufferObject();
this->rbo=new Renderbuffer();
this->rbo->Set( GL_DEPTH_COMPONENT24, this->width(), this->height() );
this->fbo->AttachRenderBuffer(GL_DEPTH_ATTACHMENT_EXT,this->rbo->GetId());

Later on I prepared my textures like this:

glGenTextures(1, &frameTex);
glBindTexture(GL_TEXTURE_2D,frameTex);
[some glTexParameteri() ]
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, this->width(), this->height(), 
0, GL_RGB, GL_FLOAT, 0);

// the depth texture
glGenTextures(1, &depthTex);
  glBindTexture(GL_TEXTURE_2D, depthTex);
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, this->width(), 
this->height(), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
[some glTexParameteri() ]
	
fbo->Bind();
fbo->AttachTexture(GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, frameTex);
fbo->Bind();
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_TEXTURE_2D, 
depthTex, 0);

(*REMARK* this->height() and width() are likely to be non-power of two 
although my card doesn't support this. using power-of-two-textures 
didn't change anything...)

I was assuming that this should bind the renderbuffer (=the depth 
component) to a depth texture as defined in ARB_depth_texture. In order 
to render into my FBO I call:

fbo->Bind();
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);

which draws everything fine to the texture associated with my color FBO. 
*but* when I try to bind the depth texture to quad the quad gets drawn 
white although it should contain the depth buffer of the first rendering 
pass. I thought the direct use of this texture should be possible, 
quoting ARB_depth_texture:

"Depth textures can be treated as LUMINANCE, INTENSITY or ALPHA 
textures during texture filtering and application. Initially, depth 
textures are interpreted as LUMINANCE."

So I guess my problem lies somewhere when I fill the buffers. Any ideas?

cheers,

david
0
Reply David 10/23/2005 3:51:45 PM

"David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
news:3s1psmFlne47U1@news.dfncis.de...

> I managed to set up a FBO and a renderbuffer for my depth buffer 
> following the FBO tutorial from the current ATI SDK while using the 
> FBO convenience class found at GPGPU.org.
>
> this->fbo=new FramebufferObject();
> this->rbo=new Renderbuffer();
> this->rbo->Set( GL_DEPTH_COMPONENT24, this->width(), this->height() );
> this->fbo->AttachRenderBuffer(GL_DEPTH_ATTACHMENT_EXT,this->rbo->GetId());
>
> Later on I prepared my textures like this:
>
> glGenTextures(1, &frameTex);
> glBindTexture(GL_TEXTURE_2D,frameTex);
> [some glTexParameteri() ]
> glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, this->width(), 
> this->height(), 0, GL_RGB, GL_FLOAT, 0);
>
> // the depth texture
> glGenTextures(1, &depthTex);
>  glBindTexture(GL_TEXTURE_2D, depthTex);
> glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, this->width(), 
> this->height(), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
> [some glTexParameteri() ]
>
> fbo->Bind();
> fbo->AttachTexture(GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, frameTex);
> fbo->Bind();
> glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_TEXTURE_2D, 
> depthTex, 0);

    You first attach the renderbuffer at the depth-attachment-point then 
later the texture? If so, you can leave out the renderbuffer altogether. 
Tho that should not make much of a difference (the texture should detach 
the renderbuffer before attaching itself).. but you never know (see next 
paragraph of mine for an explanation). Also, the 5 lines above .. 
shouldn't they be just:

fbo->Bind();
fbo->AttachTexture(GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, frameTex);
fbo->AttachTexture(GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depthTex);

?

> I was assuming that this should bind the renderbuffer (=the depth 
> component) to a depth texture as defined in ARB_depth_texture. In 
> order

    Well, no, you attach either a renderbuffer *or* a texture. I think 
in the FBO specs they are both referred to as 'image objects'. So when 
you attach a texture to the fbo, you are done. The fbo will 
automatically write the stuff to the texture. If you do not need to 
color values, you can even drop the GL_COLOR_ATTACHMENT0_EXT and set the 
read and draw buffers to GL_NONE (for example, when you want to create a 
shadow map).

> to render into my FBO I call:
>
> fbo->Bind();
> glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);

    I never called glDrawBuffer after binding the FBO .. but I'm not too 
sure if that's allowed/necessary. I only call it after having attached 
the depth texture:

glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, m_fbo);
glDrawBuffer (draw_buffer);
glReadBuffer (read_buffer);
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);

    'draw_buffer' and 'read_buffer' are function parameters .. in my 
case GL_NONE in both cases.

> which draws everything fine to the texture associated with my color 
> FBO. *but* when I try to bind the depth texture to quad the quad gets 
> drawn white although it should contain the depth buffer of the first 
> rendering pass. I thought the direct use of this texture should be 
> possible, quoting ARB_depth_texture:
>
> "Depth textures can be treated as LUMINANCE, INTENSITY or ALPHA 
> textures during texture filtering and application. Initially, depth 
> textures are interpreted as LUMINANCE."

    Ah, did not know that. So you do not even need all the ARB_shadow 
stuff I was talking about! :)

> So I guess my problem lies somewhere when I fill the buffers. Any 
> ideas?

    Try checking the status (glCheckFramebufferStatusEXT) after every 
call that has to do with the renderbuffer or the fbo. This way you'll 
find the offending line. Ideally, the status should always be 
GL_FRAMEBUFFER_COMPLETE_EXT. Otherwise, the error might give you a clue 
about what's wrong.

    Also check if depth-testing and depth-buffer-writes are both enabled 
... my apologies if that might sound stupid .. but I made similar 
mistakes before ;)

hth
-- 
jb

(reply address in rot13, unscramble first) 


0
Reply Jakob 10/23/2005 4:18:34 PM

Here are some details although I haven't checked everythinh Jakob wrote.

[...]
> 
> 
>     You first attach the renderbuffer at the depth-attachment-point then 
> later the texture? If so, you can leave out the renderbuffer altogether. 
> Tho that should not make much of a difference (the texture should detach 
> the renderbuffer before attaching itself).. but you never know (see next 
> paragraph of mine for an explanation). Also, the 5 lines above .. 
> shouldn't they be just:
> 
> fbo->Bind();
> fbo->AttachTexture(GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, frameTex);
> fbo->AttachTexture(GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depthTex);
> 
> ?

This made no difference for me.
> 
> 
>>I was assuming that this should bind the renderbuffer (=the depth 
>>component) to a depth texture as defined in ARB_depth_texture. In 
>>order
> 
> 
>     Well, no, you attach either a renderbuffer *or* a texture. I think 
> in the FBO specs they are both referred to as 'image objects'. So when 
> you attach a texture to the fbo, you are done. The fbo will 
> automatically write the stuff to the texture. If you do not need to 
> color values, you can even drop the GL_COLOR_ATTACHMENT0_EXT and set the 
> read and draw buffers to GL_NONE (for example, when you want to create a 
> shadow map).
> 

I would like to have both, the depth buffer and the color buffer, in 
separate textures after one rendering pass. so that I can use the depth 
texture as a "color" texture for a quad as well as the color attachment 
(which already works).
later, I'd like to access the depth texture from a fragment shader to 
look up distances to the camera.
> 
>>to render into my FBO I call:
>>
>>fbo->Bind();
>>glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
> 
> 
>     I never called glDrawBuffer after binding the FBO .. but I'm not too 
> sure if that's allowed/necessary. I only call it after having attached 
> the depth texture:

It should be valid as far as I understood the spec.
> 
> glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, m_fbo);
> glDrawBuffer (draw_buffer);
> glReadBuffer (read_buffer);
> glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
> 
>     'draw_buffer' and 'read_buffer' are function parameters .. in my 
> case GL_NONE in both cases.

but this would disable the color buffer, wouldn't it? that's not exactly 
what I want.
> 

> 
>>So I guess my problem lies somewhere when I fill the buffers. Any 
>>ideas?
> 
> 
>     Try checking the status (glCheckFramebufferStatusEXT) after every 
> call that has to do with the renderbuffer or the fbo. This way you'll 
> find the offending line. Ideally, the status should always be 
> GL_FRAMEBUFFER_COMPLETE_EXT. Otherwise, the error might give you a clue 
> about what's wrong.
> 
>     Also check if depth-testing and depth-buffer-writes are both enabled 
> ... my apologies if that might sound stupid .. but I made similar 
> mistakes before ;)

I know :-) depth test etc. are set:

glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

writing is enabled (isn't this the standard setting?).

my FBO gets "framebuffer complete" after all of the calls I posted 
before. sorry, I forgot to mention this and simply removed the lines of 
code.

david
0
Reply David 10/23/2005 5:32:22 PM

"David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
news:3s1vpcFm1un7U1@news.dfncis.de...

>> fbo->Bind();
>> fbo->AttachTexture(GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, 
>> frameTex);
>> fbo->AttachTexture(GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depthTex);

> This made no difference for me.

    No, it should not make any. I just thought I'd tell you about the 
addition call to Bind which was not needed. :)

    Didn't removing the renderbuffer stuff help either? Tho, as far as I 
understand the docs (just checked), that should not make a difference 
really.

>> glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, m_fbo);
>> glDrawBuffer (draw_buffer);
>> glReadBuffer (read_buffer);
>> glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);

> but this would disable the color buffer, wouldn't it? that's not 
> exactly what I want.

    Right, that was taken from my code, where I only needed the depth 
buffer. Should have mentioned this.

    I'm running out of ideas .. one more tho: When you create the 
texture, are you using the same number of depth bits as you have for 
your app (glGetIntegerv (GL_DEPTH_BITS, ..)? Tho having a format that 
does not work should have raised an error. But you are not getting any 
errors, so .. but maybe this helps. If not, I will try to post a 
sequence of calls I am making to set up the fbo in my app.

hth
-- 
jb

(reply address in rot13, unscramble first) 


0
Reply Jakob 10/23/2005 5:56:12 PM

[...]
> 
> 
>>>glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, m_fbo);
>>>glDrawBuffer (draw_buffer);
>>>glReadBuffer (read_buffer);
>>>glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
> 
> 
>>but this would disable the color buffer, wouldn't it? that's not 
>>exactly what I want.
> 
> 
>     Right, that was taken from my code, where I only needed the depth 
> buffer. Should have mentioned this.

But as far as I understand it should be possible to retrieve both 
buffers in one render pass.
> 
>     I'm running out of ideas .. one more tho: When you create the 
> texture, are you using the same number of depth bits as you have for 
> your app (glGetIntegerv (GL_DEPTH_BITS, ..)? Tho having a format that 
> does not work should have raised an error. But you are not getting any 
> errors, so .. but maybe this helps. If not, I will try to post a 
> sequence of calls I am making to set up the fbo in my app.
> 

the z-buffer is 24 bits deep so is the depth texture. I am a little 
frustrated right now :-(
I tried to work with a fragment shader to visualize the whole thing. I 
set up the depth texture as before and passed it to my fragment shader:

GLint location = 
glGetUniformLocation(this->shaderProgram,uniformName.c_str());
glUniform1i(location,depthTex);

(depthTex is the texture name generated by glGenTextures())

that's the fragment shader I use:

uniform sampler2DShadow texture;

void main()
{
	gl_FragColor=vec4(shadow2D(texture,vec3(gl_TexCoord[0].st,1)));
}

this generates a b/w image (black where I placed objects, white for the 
rest) of my scene on a quad, which is exactly similar to the result when 
I pass a color texture. so far no nice greyscale image visible...

I have no more ideas. does anyone out there have some lines of code that 
achieve the following:

1) set up a scene of e.g. some nice GLUT teapots
2) render this to a FBO texture and a RBO depth texture
3) take the color texture and map it on quad A and the depth texture in 
order to map it as a grayscaled image on quad B

the last step should be preferably done with a fragment shader.
I know this sounds as I am lazy and not willing to read the specs but 
I've done this and am still stuck. :-(

thanks,

david
0
Reply David 10/24/2005 9:51:11 AM

"David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
news:3s3p4sFm39rqU1@news.dfncis.de...
> [...]
>>
>>
>>>>glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, m_fbo);
>>>>glDrawBuffer (draw_buffer);
>>>>glReadBuffer (read_buffer);
>>>>glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
>>
>>
>>>but this would disable the color buffer, wouldn't it? that's not 
>>>exactly what I want.
>>
>>
>>     Right, that was taken from my code, where I only needed the depth 
>> buffer. Should have mentioned this.
>
> But as far as I understand it should be possible to retrieve both 
> buffers in one render pass.

    Yes, of course!

>>     I'm running out of ideas .. one more tho: When you create the 
>> texture, are you using the same number of depth bits as you have for 
>> your app (glGetIntegerv (GL_DEPTH_BITS, ..)? Tho having a format that 
>> does not work should have raised an error. But you are not getting 
>> any errors, so .. but maybe this helps. If not, I will try to post a 
>> sequence of calls I am making to set up the fbo in my app.
>>
>
> the z-buffer is 24 bits deep so is the depth texture. I am a little 
> frustrated right now :-(
> I tried to work with a fragment shader to visualize the whole thing. I 
> set up the depth texture as before and passed it to my fragment 
> shader:
>
> GLint location = 
> glGetUniformLocation(this->shaderProgram,uniformName.c_str());
> glUniform1i(location,depthTex);
>
> (depthTex is the texture name generated by glGenTextures())
>
> that's the fragment shader I use:
>
> uniform sampler2DShadow texture;
>
> void main()
> {
> gl_FragColor=vec4(shadow2D(texture,vec3(gl_TexCoord[0].st,1)));
> }
>
> this generates a b/w image (black where I placed objects, white for 
> the rest) of my scene on a quad, which is exactly similar to the 
> result when I pass a color texture. so far no nice greyscale image 
> visible...
>
> I have no more ideas. does anyone out there have some lines of code 
> that achieve the following:
>
> 1) set up a scene of e.g. some nice GLUT teapots
> 2) render this to a FBO texture and a RBO depth texture
> 3) take the color texture and map it on quad A and the depth texture 
> in order to map it as a grayscaled image on quad B
>
> the last step should be preferably done with a fragment shader.
> I know this sounds as I am lazy and not willing to read the specs but 
> I've done this and am still stuck. :-(

    Here's some code snippets from my app. It uses two textures (one 
rgba, and one depth) to store the pixel data of the fbo. Again, you do 
*not* need a renderbuffer, if you want to render the color and depth 
values to a texture (which is what you are apparently trying to do). To 
initialize, I do the following:

//  create fbo
glGenFramebuffersEXT (1, &fbo);

//  create color texture
glGenTextures (1, &color_tex);
glBindTexture (GL_TEXTURE_2D, color_tex);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, 
GL_UNSIGNED_INT, 0);

//  attach that texture to the color
//  attachment point of the fbo
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, fbo);
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, 
GL_TEXTURE_2D, color_tex, 0);
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);    //  unbind

//  create depth texture
glGenTextures (1, &depth_tex);
glBindTexture (GL_TEXTURE_2D, depth_tex);
glTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, 256, 256, 0, 
GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0);

//  attach that texture to the depth
//  attachment point of the fbo
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, fbo);
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, 
GL_TEXTURE_2D, depth_tex, 0);
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);    //  unbind

    Checking the status should result in GL_FRAMEBUFFER_COMPLETE_EXT (it 
does here, gf6800). Now you can start using that fbo:

glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, fbo);
//  usually you also adjut the viewport now, so it matches the fbo

//  do the rendering .. it will all go into the fbo

glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
//  now restore your old viewport

    Now you should be able to bind your textures and access the stuff 
thats just been rendered into them. If that still does not work, try 
creating the minimal example you were speaking of, so I can just plug in 
the fbo code and get that working.

hth
-- 
jb

(reply address in rot13, unscramble first) 


0
Reply Jakob 10/24/2005 6:05:46 PM

Hi,

I'm curious. Are you guys rendering something for a Stereo 3D device ?
If yes, which ?

wpr.
0
Reply wpr 10/25/2005 6:00:36 PM

hello and hi jakob (as you are frequent reader of this column ;-) ).

after I've set up a very simple GLUT program using your code, my FBO is 
still ill. :-(

I'm trying to render a simple rainbow coloured quad into the FBO and 
want to use this as a texture for a new quad, which unfortunately is 
drawn green (!), when launchned from within VS. and black when launched 
directly.

I am code-blind right now and checked my code against the spec and an 
ATI paper but I have no clue.
here's a link to the source:

http://8bit-inferno.de/downloads/quickHack.cpp

everything interesting can be found in init() and display(), so if 
someone out there doesn't mind to take a look... i would appreciate this!

cheers,

david
0
Reply David 10/25/2005 6:19:36 PM

wpr wrote:
> Hi,
> 
> I'm curious. Are you guys rendering something for a Stereo 3D device ?
> If yes, which ?
> 
> wpr.
not really, although I thought about it. but right now I am not able to 
do the simplest stuff like displaying the z-buffer as a simple 
grayscaled texture :-( stay tuned, I guess there will come more.
0
Reply David 10/25/2005 6:23:28 PM

"David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
news:3s7ba0Fmmin6U1@news.dfncis.de...
> hello and hi jakob (as you are frequent reader of this column ;-) ).
>
> after I've set up a very simple GLUT program using your code, my FBO 
> is still ill. :-(
>
> I'm trying to render a simple rainbow coloured quad into the FBO and 
> want to use this as a texture for a new quad, which unfortunately is 
> drawn green (!), when launchned from within VS. and black when 
> launched directly.
>
> I am code-blind right now and checked my code against the spec and an 
> ATI paper but I have no clue.
> here's a link to the source:
>
> http://8bit-inferno.de/downloads/quickHack.cpp
>
> everything interesting can be found in init() and display(), so if 
> someone out there doesn't mind to take a look... i would appreciate 
> this!


    Now this is strange .. it works! I can see the black and white 
texture with the teapot and the black quad partly hiding it. And I can 
also apply the depth texture .. which actually shows more clearly what 
the scene looks like.

    I had to change the code a bit, since I do not use glew. I will post 
the full source as a follow-up to this post (so others can decide to 
skip it), which will include the changes I made. Tho I should have, I 
did not mark the changes now; but a file comparison program should make 
them obvious. Sorry about that. It also includes the loading code for 
the framebuffer object extension, that I use in my app.

hth
-- 
jb

(reply address in rot13, unscramble first) 


0
Reply Jakob 10/25/2005 8:09:43 PM

"wpr" <mlopes_filho@yahoo.com.br> wrote in message 
news:djlrre$52n$1@online.de...
> Hi,
>
> I'm curious. Are you guys rendering something for a Stereo 3D device ?
> If yes, which ?


    No, in my case I am using it to implement shadow mapping.

regards
-- 
jb

(reply address in rot13, unscramble first) 


0
Reply Jakob 10/25/2005 8:10:21 PM

#define GLEW_STATIC 1
//#include <GL/glew.h>
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
#include "glut.h"
#include <math.h>
#include <iostream>






static PFNGLISRENDERBUFFEREXTPROC 
glIsRenderbufferEXT;
static PFNGLBINDRENDERBUFFEREXTPROC 
glBindRenderbufferEXT;
static PFNGLDELETERENDERBUFFERSEXTPROC 
glDeleteRenderbuffersEXT;
static PFNGLGENRENDERBUFFERSEXTPROC 
glGenRenderbuffersEXT;
static PFNGLRENDERBUFFERSTORAGEEXTPROC 
glRenderbufferStorageEXT;
static PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC 
glGetRenderbufferParameterivEXT;

static PFNGLISFRAMEBUFFEREXTPROC 
glIsFramebufferEXT;
static PFNGLBINDFRAMEBUFFEREXTPROC 
glBindFramebufferEXT;
static PFNGLDELETEFRAMEBUFFERSEXTPROC 
glDeleteFramebuffersEXT;
static PFNGLGENFRAMEBUFFERSEXTPROC 
glGenFramebuffersEXT;
static PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC 
glCheckFramebufferStatusEXT;

static PFNGLFRAMEBUFFERTEXTURE1DEXTPROC 
glFramebufferTexture1DEXT;
static PFNGLFRAMEBUFFERTEXTURE2DEXTPROC 
glFramebufferTexture2DEXT;
static PFNGLFRAMEBUFFERTEXTURE3DEXTPROC 
glFramebufferTexture3DEXT;
static PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC 
glFramebufferRenderbufferEXT;
static PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC 
glGetFramebufferAttachmentParameterivEXT;
static PFNGLGENERATEMIPMAPEXTPROC 
glGenerateMipmapEXT;
bool frame_buffer_is_supported ()
{
    static bool is_supp,
                is_checked = false;

    if (!is_checked)
    {
        char const* exts = (const char*) glGetString (GL_EXTENSIONS);
        char const* fboext = strstr (exts, "GL_EXT_framebuffer_object 
");

        if (!fboext)
            is_supp = false;
        else if (fboext == exts)
            is_supp = true;
        else
            is_supp = (*(fboext - 1) == ' ');

        if (is_supp)
        {
            glIsRenderbufferEXT = (PFNGLISRENDERBUFFEREXTPROC) 
wglGetProcAddress ("glIsRenderbufferEXT");
            glBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC) 
wglGetProcAddress ("glBindRenderbufferEXT");
            glDeleteRenderbuffersEXT = (PFNGLDELETERENDERBUFFERSEXTPROC) 
wglGetProcAddress ("glDeleteRenderbuffersEXT");
            glGenRenderbuffersEXT = (PFNGLGENRENDERBUFFERSEXTPROC) 
wglGetProcAddress ("glGenRenderbuffersEXT");
            glRenderbufferStorageEXT = (PFNGLRENDERBUFFERSTORAGEEXTPROC) 
wglGetProcAddress ("glRenderbufferStorageEXT");
            glGetRenderbufferParameterivEXT = 
(PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) wglGetProcAddress 
("glGetRenderbufferParameterivEXT");
            glIsFramebufferEXT = (PFNGLISFRAMEBUFFEREXTPROC) 
wglGetProcAddress ("glIsFramebufferEXT");
            glBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC) 
wglGetProcAddress ("glBindFramebufferEXT");
            glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC) 
wglGetProcAddress ("glDeleteFramebuffersEXT");
            glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC) 
wglGetProcAddress ("glGenFramebuffersEXT");
            glCheckFramebufferStatusEXT = 
(PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) wglGetProcAddress 
("glCheckFramebufferStatusEXT");
            glFramebufferTexture1DEXT = 
(PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) wglGetProcAddress 
("glFramebufferTexture1DEXT");
            glFramebufferTexture2DEXT = 
(PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) wglGetProcAddress 
("glFramebufferTexture2DEXT");
            glFramebufferTexture3DEXT = 
(PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) wglGetProcAddress 
("glFramebufferTexture3DEXT");
            glFramebufferRenderbufferEXT = 
(PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) wglGetProcAddress 
("glFramebufferRenderbufferEXT");
            glGetFramebufferAttachmentParameterivEXT = 
(PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) wglGetProcAddress 
("glGetFramebufferAttachmentParameterivEXT");
            glGenerateMipmapEXT = (PFNGLGENERATEMIPMAPEXTPROC) 
wglGetProcAddress ("glGenerateMipmapEXT");

            is_supp =   glIsRenderbufferEXT &&
                        glBindRenderbufferEXT &&
                        glDeleteRenderbuffersEXT &&
                        glGenRenderbuffersEXT &&
                        glRenderbufferStorageEXT &&
                        glGetRenderbufferParameterivEXT &&
                        glIsFramebufferEXT &&
                        glBindFramebufferEXT &&
                        glDeleteFramebuffersEXT &&
                        glGenFramebuffersEXT &&
                        glCheckFramebufferStatusEXT &&
                        glFramebufferTexture1DEXT &&
                        glFramebufferTexture2DEXT &&
                        glFramebufferTexture3DEXT &&
                        glFramebufferRenderbufferEXT &&
                        glGetFramebufferAttachmentParameterivEXT &&
                        glGenerateMipmapEXT;
        }
    }

    return is_supp;
}








using namespace std;

GLfloat angle=0.0;
GLfloat p1[3]={-0.5,-0.5,-0.5};
GLfloat x=0.0;
GLfloat y=0.75;
GLfloat z=0.0;

GLuint fbo;
GLuint color_tex, depth_tex;
GLint screenWidth=256;
GLint screenHeight=256;

const float PI = 3.14159265358979323846f;

GLubyte minitex[4][4][3] =
{
    { {255,  0,255}, {  0,  0,255}, {  0,  0,255}, {  0,255,255}},
    { {  0,  0,255}, {255,  0,255}, {  0,255,255}, {  0,  0,255}},
    { {  0,  0,255}, {  0,255,255}, {255,  0,255}, {  0,  0,255}},
    { {  0,255,255}, {  0,  0,255}, {  0,  0,255}, {255,  0,255}},
};

void checkFBOStatus(){
GLenum status;
  status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
  switch(status) {
  case GL_FRAMEBUFFER_COMPLETE_EXT: // Everything's OK
      cout << "FRAMEBUFFER COMPLETE !"<<endl;
    break;
  case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
    cout << "glift::CheckFramebufferStatus() ERROR:\n\t"
         << "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT\n";
    break;
  case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
    cout << "glift::CheckFramebufferStatus() ERROR:\n\t"
         << "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT\n";
    break;
  case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT:
    cout << "glift::CheckFramebufferStatus() ERROR:\n\t"
         << "GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT\n";
    break;
  case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
    cout << "glift::CheckFramebufferStatus() ERROR:\n\t"
         << "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT\n";
    break;
  case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
    cout << "glift::CheckFramebufferStatus() ERROR:\n\t"
         << "GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT\n";
    break;
  case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
    cout << "glift::CheckFramebufferStatus() ERROR:\n\t"
              << "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT\n";
    break;
  case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
    cout << "glift::CheckFramebufferStatus() ERROR:\n\t"
         << "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT\n";
    break;
  case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
    cout << "glift::CheckFramebufferStatus() ERROR:\n\t"
         << "GL_FRAMEBUFFER_UNSUPPORTED_EXT\n";
    break;
//  case GL_FRAMEBUFFER_STATUS_ERROR_EXT:
//      cout << "glift::CheckFramebufferStatus() ERROR:\n\t"
//          << "GL_FRAMEBUFFER_STATUS_ERROR_EXT\n";
//      break;
  default:
    cout << "glift::CheckFramebufferStatus() ERROR:\n\t"
         << "Unknown ERROR\n";
}
}

void begin2D(bool withDepthTest){
    // switch to projection mode
    glMatrixMode(GL_PROJECTION);
    // push the current matrix as we need it later to restore the 
perspective view
    glPushMatrix();
    // reset the matrix as we must not multiply it with the new 
projection
    glLoadIdentity();
    glOrtho( 0, screenWidth, 0, screenHeight, 0, 1 );
    //equivalent to: gluOrtho2D(0,screenWidth,0,screenHeight);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    if(!withDepthTest)
    //disable the depth test, so everything will now be painted on top
        glDisable(GL_DEPTH_TEST);
}

void end2D(){
    glEnable(GL_DEPTH_TEST);

    glMatrixMode(GL_PROJECTION);
    // pop the old matrix which should be the right one if begin2D() is 
closed by end3D()
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
}
// 
*************************************************************************************************************************
void reshape(GLsizei w, GLsizei h)
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-1, 1, -1, 1, 1, 100);
    //gluPerspective(90.0,w/h,1,20);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(-1, 1, 2, 0, 0,0, 0, 1, 0);
    glPushMatrix();
}

void colorcube(){
    /*frontside*/
    glBegin(GL_POLYGON);
    glNormal3f(0, 0, 1);
    glColor3f(0,0.5,0.5);
    glTexCoord2f(0, 0);
    glVertex3f(-0.5,-0.5,0.5);
    glTexCoord2f(1, 0);
    glVertex3f(0.5,-0.5,0.5);
    glTexCoord2f(1, 1);
    glVertex3f(0.5,0.5,0.5);
    glTexCoord2f(0, 1);
    glVertex3f(-0.5,0.5,0.5);
    glEnd();

    /*left*/
    glBegin(GL_POLYGON);
    glColor3f(1,0,0);
    glNormal3f(-1, 0, 0);
    glVertex3f(-0.5,-0.5,0.5);
    glVertex3f(-0.5,0.5,0.5);
    glVertex3f(-0.5,0.5,-0.5);
    glVertex3f(-0.5,-0.5,-0.5);
    glEnd();

    /*bottom*/
    glBegin(GL_POLYGON);
    glColor3f(0,1,0);
    glNormal3f(0, -1, 0);
    glVertex3f(-0.5,-0.5,0.5);
    glVertex3f(-0.5,-0.5,-0.5);
    glVertex3f(0.5,-0.5,-0.5);
    glVertex3f(0.5,-0.5,0.5);
    glEnd();

    /*top*/
    glBegin(GL_POLYGON);
    glColor3f(0,0,1);

    glVertex3f(0.5,0.5,-0.5);

    glVertex3f(-0.5,0.5,-0.5);

    glVertex3f(-0.5,0.5,0.5);

    glVertex3f(0.5,0.5,0.5);
    glEnd();

    /*right*/
    glBegin(GL_POLYGON);
    glColor3f(1,0,1);
    glNormal3f(1, 0, 0);
    glVertex3f(0.5,0.5,-0.5);
    glVertex3f(0.5,0.5,0.5);
    glVertex3f(0.5,-0.5,0.5);
    glVertex3f(0.5,-0.5,-0.5);
    glEnd();

    /*back*/
    glBegin(GL_POLYGON);
    glColor3f(0,1,1);
    glNormal3f(0, 0, -1);
    glVertex3f(0.5,0.5,-0.5);
    glVertex3f(0.5,-0.5,-0.5);
    glVertex3f(-0.5,-0.5,-0.5);
    glVertex3f(-0.5,0.5,-0.5);
    glEnd();
}

void display()
{
    GLint currentBuffer=0;
    glGetIntegerv(GL_DRAW_BUFFER, &currentBuffer);

    glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, fbo);
    glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);

    glClearColor(0,0,0,1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBegin(GL_QUADS);
    {
        glColor3f(1,0,0);
        glVertex3f(-0.5, -0.5, 0.5);
        glColor3f(0,1,0);
        glVertex3f( 0.5, -0.5, 0.5);
        glColor3f(0,0,1);
        glVertex3f( 0.5,  0.5, 0.5);
        glColor3f(1,1,1);
        glVertex3f(-0.5,  0.5,0.5);
    }
    glEnd();

    glDisable(GL_TEXTURE_2D);
    glutSolidTeapot(0.5);

    glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
    glDrawBuffer(currentBuffer);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, depth_tex);

    glBegin(GL_QUADS);
    {
        glColor3f(1,1,1);
        glTexCoord2f(0, 0);
        glVertex3f(-1.5, -1.5, 0.5);
        glTexCoord2f(1, 0);
        glVertex3f( 1.5, -1.5, 0.5);
        glTexCoord2f(1, 1);
        glVertex3f( 1.5,  1.5, 0.5);
        glTexCoord2f(0, 1);
        glVertex3f(-1.5,  1.5,0.5);
    }
    glEnd();

    glutSwapBuffers();
}


void idle(){
    //angle+=PI /22.5;
    glutPostRedisplay();
}

void init(){
    GLint zDepth;
    glGetIntegerv(GL_DEPTH_BITS,&zDepth);
    cout << "\n* * * * * * * * * * * * * * * * *\n\nZ-buffer depth: " << 
zDepth << " bit\n\n* * * * * * * * * * * * * * * * *"<<endl;

    //  create fbo
    glGenFramebuffersEXT (1, &fbo);

    //  create color texture
    glGenTextures (1, &color_tex);
    glBindTexture (GL_TEXTURE_2D, color_tex);
    glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, 
GL_UNSIGNED_INT, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    //  attach that texture to the color
    //  attachment point of the fbo
    glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, fbo);
    glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, 
GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, color_tex, 0);
    glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);    //  unbind

    //  create depth texture
    glGenTextures (1, &depth_tex);
    glBindTexture (GL_TEXTURE_2D, depth_tex);
    glTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, 256, 256, 
0,GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    //  attach that texture to the depth
    //  attachment point of the fbo
    glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, fbo);
    glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, 
GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depth_tex, 0);
    glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);    //  unbind

    checkFBOStatus();
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize(256,256);
    glutInitWindowPosition(69,69);

    glutCreateWindow("quick and dirty hacks");

    frame_buffer_is_supported ();
/*
    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
        cout << "GLEW init failed: " << glewGetErrorString(err) <<endl;
    }
    cout << "Using GLEW " << glewGetString(GLEW_VERSION) <<endl;
*/
    glEnable(GL_DEPTH_TEST);
    init();

    glEnable(GL_TEXTURE_2D);
    //glTexImage2D(GL_TEXTURE_2D, 0, 3, 4, 4, 0, GL_RGB, 
GL_UNSIGNED_BYTE, minitex);
    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    glutDisplayFunc(display);

    glutIdleFunc(idle);
    glutReshapeFunc(reshape);

    glutMainLoop();


}

/*

hth
-- 
jb

(reply address in rot13, unscramble first)*/ 


0
Reply Jakob 10/25/2005 8:14:20 PM

Jakob Bieling wrote:
[...]
> 
> 
> 
>     Now this is strange .. it works! I can see the black and white 
> texture with the teapot and the black quad partly hiding it. And I can 
> also apply the depth texture .. which actually shows more clearly what 
> the scene looks like.
> 
>     I had to change the code a bit, since I do not use glew. I will post 
> the full source as a follow-up to this post (so others can decide to 
> skip it), which will include the changes I made. Tho I should have, I 
> did not mark the changes now; but a file comparison program should make 
> them obvious. Sorry about that. It also includes the loading code for 
> the framebuffer object extension, that I use in my app.
> 
> hth
thanks a lot for your patience.
oh, my god! I can compile your code (I use WinXP, VisualStudio .NET and 
an ATI X800 Pro) *but* everything stays weird.
I had to include glew.h (the glewInit() stays commented) for a quick 
check and the results were as seen before. Now I had a grey quad using 
the depth texture and a green one using the color attachment (using a VS 
launch).
An image can be found here:
http://8bit-inferno.de/downloads/strangebrew.gif

you wrote that you can see everything clearly. I conclude that the 
problem should be on my side.

first assumption: maybe the ATI driver (as I read a lot about the 
"quality" of their drivers) has a bug. I use version 6.14.10.5337 (aka 
Catalyst 05.9), according to RealtechVR's extensions viewer 100% 
compatible to OpenGL 2.0 and also supporting FBOs.

2nd assumption: the functions pointers of GLEW are wrong but I think 
this would lead to real crashes.

3rd assumption: bad karma.

does anyone out there have any suggestions or did someone use the posted 
code successfully on ATI hardware?

cheers,

david

ps: my current setup:

ATI Radeon X800 Pro, 256 MB
Windows XP Pro SP 2
ICD Driver 6.14.10.5337 (aka Catalyst 05.9)




0
Reply David 10/25/2005 9:40:27 PM

"David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
news:3s7n2jFmm1p4U1@news.dfncis.de...

> An image can be found here:
> http://8bit-inferno.de/downloads/strangebrew.gif

    Ok, I tried a bit more and noticed that the quad in the fbo should 
have been colored .. which is was not. I changed that just now. See if 
that helps. Here is just the display func:

void display()
{
    GLint currentBuffer=0;
    glGetIntegerv(GL_DRAW_BUFFER, &currentBuffer);

    glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, fbo);
//  glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);

    glClearColor(0,0,0,1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glDisable(GL_TEXTURE_2D);    //  change
    glDisable (GL_LIGHTING);     //  change

    glBegin(GL_QUADS);
    {
        glColor3f(1,0,0);
        glVertex3f(-0.5, -0.5, 0.5);
        glColor3f(0,1,0);
        glVertex3f( 0.5, -0.5, 0.5);
        glColor3f(0,0,1);
        glVertex3f( 0.5,  0.5, 0.5);
        glColor3f(1,1,1);
        glVertex3f(-0.5,  0.5,0.5);
    }
    glEnd();

    glDisable(GL_TEXTURE_2D);
    glutSolidTeapot(0.5);

    glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
//  glDrawBuffer(currentBuffer);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, color_tex);

    glBegin(GL_QUADS);
    {
        glColor3f(1,1,1);
        glTexCoord2f(0, 0);
        glVertex3f(-1.5, -1.5, 0.5);
        glTexCoord2f(1, 0);
        glVertex3f( 1.5, -1.5, 0.5);
        glTexCoord2f(1, 1);
        glVertex3f( 1.5,  1.5, 0.5);
        glTexCoord2f(0, 1);
        glVertex3f(-1.5,  1.5,0.5);
    }
    glEnd();

    glutSwapBuffers();
}

    I also removed the DrawBuffers call, even tho that does not make a 
difference for me.

> first assumption: maybe the ATI driver (as I read a lot about the 
> "quality" of their drivers) has a bug. I use version 6.14.10.5337 (aka 
> Catalyst 05.9), according to RealtechVR's extensions viewer 100% 
> compatible to OpenGL 2.0 and also supporting FBOs.

    Could be .. or I just did it wrong but nVidia is more forgiving. I 
never had a chance to test this on any other system than mine! Maybe you 
can have your app test on other cards that support it.

hth
-- 
jb

(reply address in rot13, unscramble first) 


0
Reply Jakob 10/26/2005 5:08:24 AM

well, I figured out that there's a new ATI driver which I installed 
without results.
The thing I find most distracting is that I can use the color attachment 
as a texture in a fullscreen QT application. the depth buffer texture is 
also working when using a shader, although it should be possible to use 
it directly as a greyscaled texture as said in ARB_depth_texture.
In my case (direct use w/o shader) the textured quad stays almost grey 
(its colour) because the depth buffer needs obviously some kind of gamma 
correction. the texture appears tone in tone. I obviously oversaw this 
before but now the weather changed from sunny to rainy and now I can see it.

I browsed the fairly complex ATI example code that does what I really 
want and found a shader that calculates the color for the depth buffer 
texture as following:

uniform sampler2D texture;
varying vec2 texCoord;

void main(){
	float depth = texture2D(texture, texCoord).x;
	float d=pow(depth, 70.0);
	gl_FragColor = vec4(d);
}

I really wonder what they achieve by taking the incoming color value 
from the depth texture and take it ^70. In my mathematical understanding 
taking a value such as 0.5^70 would make it incredibly small. so all 
values should be around 0 but the far plane that would stay 1.
After running this shader I get a depth buffer texture with a white 
background but ATI gets the more expected black background.

if I try the code in GLUT nothing is working yet. May there be a 
difference between window and fullscreen mode?

Another detail is that when I manually set the depth range:

glDepthRange(0,1);

a call like this:

GLint dr[2];
glGetIntegerv(GL_DEPTH_RANGE,dr);
cout << "GL_DEPTH_RANGE " << dr[0] <<"/"<< dr[1]<<endl;

returns:

GL_DEPTH_RANGE 0/2147482496

while I was expecting 0/1, might this be due a cast problem? (although 
there's no real cast)

any hints, clues or suggestions?

david
0
Reply David 10/26/2005 8:47:30 AM

"David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
news:3s8u5aFn35shU1@news.dfncis.de...

> In my case (direct use w/o shader) the textured quad stays almost grey 
> (its colour) because the depth buffer needs obviously some kind of 
> gamma correction. the texture appears tone in tone. I obviously 
> oversaw this before but now the weather changed from sunny to rainy 
> and now I can see it.

    You could take a screenshot and inspect the output with a graphics 
program ..

> I browsed the fairly complex ATI example code that does what I really 
> want and found a shader that calculates the color for the depth buffer 
> texture as following:
>
> uniform sampler2D texture;
> varying vec2 texCoord;
>
> void main(){
> float depth = texture2D(texture, texCoord).x;
> float d=pow(depth, 70.0);
> gl_FragColor = vec4(d);
> }

    According to the specs, the above is undefined, if 'texture' is a 
depth-texture. depth-textures must be accessed with the shadow* 
accessing functions. In addition, it says there, that depth 
"comparisons" need to be turned on. Now I am not sure if they mean to 
enable depth-testing?

> if I try the code in GLUT nothing is working yet. May there be a 
> difference between window and fullscreen mode?

    Might be .. maybe you only get full support for everything in 
fullscreen .. ?

> Another detail is that when I manually set the depth range:
>
> glDepthRange(0,1);
>
> a call like this:
>
> GLint dr[2];
> glGetIntegerv(GL_DEPTH_RANGE,dr);
> cout << "GL_DEPTH_RANGE " << dr[0] <<"/"<< dr[1]<<endl;
>
> returns:
>
> GL_DEPTH_RANGE 0/2147482496
>
> while I was expecting 0/1, might this be due a cast problem? (although 
> there's no real cast)

    You are requesting the integer range. So this might pretty much be 
correct. Try getting the depth-range with glGetFloatv. That should 
return 0/1

hth
-- 
jb

(reply address in rot13, unscramble first) 


0
Reply Jakob 10/26/2005 2:52:56 PM

Jakob Bieling wrote:
> "David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
> news:3s8u5aFn35shU1@news.dfncis.de...
> 
> 
>>In my case (direct use w/o shader) the textured quad stays almost grey 
>>(its colour) because the depth buffer needs obviously some kind of 
>>gamma correction. the texture appears tone in tone. I obviously 
>>oversaw this before but now the weather changed from sunny to rainy 
>>and now I can see it.
> 
> 
>     You could take a screenshot and inspect the output with a graphics 
> program ..


yepp. I did.
> 
>>I browsed the fairly complex ATI example code that does what I really 
>>want and found a shader that calculates the color for the depth buffer 
>>texture as following:
>>
>>uniform sampler2D texture;
>>varying vec2 texCoord;
>>
>>void main(){
>>float depth = texture2D(texture, texCoord).x;
>>float d=pow(depth, 70.0);
>>gl_FragColor = vec4(d);
>>}
> 
> 
>     According to the specs, the above is undefined, if 'texture' is a 
> depth-texture. depth-textures must be accessed with the shadow* 
> accessing functions. In addition, it says there, that depth 
> "comparisons" need to be turned on. Now I am not sure if they mean to 
> enable depth-testing?

and that's the point, besides the x^70 phenomenon. I am astonished that 
it worked although it was negated in the spec. I hope that I can figure 
this out, because I have no access to other hardware.
Jakob, you used a GeForce didn't you?
0
Reply David 10/26/2005 3:46:55 PM

"David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
news:3s9mo1Fn469tU1@news.dfncis.de...

>>>uniform sampler2D texture;
>>>varying vec2 texCoord;
>>>
>>>void main(){
>>>float depth = texture2D(texture, texCoord).x;
>>>float d=pow(depth, 70.0);
>>>gl_FragColor = vec4(d);
>>>}

>>     According to the specs, the above is undefined, if 'texture' is a

> and that's the point, besides the x^70 phenomenon. I am astonished 
> that it worked although it was negated in the spec. I hope that I can 
> figure this out, because I have no access to other hardware.

    Later, I'll check what this does on my card and post the results ..

> Jakob, you used a GeForce didn't you?

    Yes, GeForce 6800 .. not GT or Ultra .. the normal version.

hth
-- 
jb

(reply address in rot13, unscramble first) 


0
Reply Jakob 10/26/2005 4:06:50 PM

"David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
news:3s9mo1Fn469tU1@news.dfncis.de...

>>>uniform sampler2D texture;
>>>varying vec2 texCoord;
>>>
>>>void main(){
>>>float depth = texture2D(texture, texCoord).x;
>>>float d=pow(depth, 70.0);
>>>gl_FragColor = vec4(d);
>>>}

    It seems to work here, whether I use the shadow or non-shadow 
version. Wouldn't rely on it tho, since thats probably also part of 
being undefined ;)

    About the code above .. it seems like it is making values != 1.0 
really small .. but I do not understand the rationale behind it. A 
simple if statement seems to be less expensive than calling pow.

regards
-- 
jb

(reply address in rot13, unscramble first) 


0
Reply Jakob 10/27/2005 12:57:07 PM

Jakob Bieling wrote:
> "David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
> news:3s9mo1Fn469tU1@news.dfncis.de...
> 
> 
>>>>uniform sampler2D texture;
>>>>varying vec2 texCoord;
>>>>
>>>>void main(){
>>>>float depth = texture2D(texture, texCoord).x;
>>>>float d=pow(depth, 70.0);
>>>>gl_FragColor = vec4(d);
>>>>}
> 
> 
>     It seems to work here, whether I use the shadow or non-shadow 
> version. Wouldn't rely on it tho, since thats probably also part of 
> being undefined ;)
> 
>     About the code above .. it seems like it is making values != 1.0 
> really small .. but I do not understand the rationale behind it. A 
> simple if statement seems to be less expensive than calling pow.
> 
> regards
could you post a screenshot? I'd would like to see your results 
including the whole code you used if this is possible.

about the ^70: I cannot understand why an image appears when all values 
!= 1.0 become almost zero. In my small world this would throw away 
almost everything in the depth buffer.

it's too bad that no one else could test this on an ATI card. I'd like 
to find out if this is a general problem or just mine.
0
Reply David 10/27/2005 1:54:28 PM

"David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
news:3sc4goFnqpmiU1@news.dfncis.de...

> could you post a screenshot? I'd would like to see your results 
> including the whole code you used if this is possible.

    Check your email. Code (based on yours) and images attached. Maybe 
you can upload it somewhere? Oh, and I'd be interested in screenshots of 
yours, using the exact same code, if thats possible. thanks :)

regards
-- 
jb

(reply address in rot13, unscramble first) 


0
Reply Jakob 10/27/2005 6:53:37 PM

Jakob Bieling wrote:
> "David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
> news:3sc4goFnqpmiU1@news.dfncis.de...
> 
> 
>>could you post a screenshot? I'd would like to see your results 
>>including the whole code you used if this is possible.
> 
> 
>     Check your email. Code (based on yours) and images attached. Maybe 
> you can upload it somewhere? Oh, and I'd be interested in screenshots of 
> yours, using the exact same code, if thats possible. thanks :)
> 
> regards

here you go:

http://www.8bit-inferno.de/ati_problem/

I've described the problem and posted my more or less working QT code.

cheers,

David
0
Reply David 10/28/2005 8:37:53 AM

"David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
news:3se6b4Fnkp0sU1@news.dfncis.de...

> http://www.8bit-inferno.de/ati_problem/

    I noticed you're getting errors for the shader. Try calling this 
function for the appropriate shader, instead of outputting "invalid 
shader" .. it should print out the errors ..

void print_log (GLhandleARB h)
{
    GLint e;
    glGetObjectParameterivARB (h, GL_OBJECT_INFO_LOG_LENGTH_ARB, &e);

    GLsizei     llen = 0;
    GLcharARB*  log = new GLcharARB [e + 1];

    glGetInfoLogARB (h, e + 1, &llen, log);

    log [llen] = 0;
    cout << log << endl;

    delete [] log;
}


hth
-- 
jb

(reply address in rot13, unscramble first) 


0
Reply Jakob 10/28/2005 9:05:13 AM

Jakob Bieling wrote:
> "David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
> news:3se6b4Fnkp0sU1@news.dfncis.de...
> 
> 
>>http://www.8bit-inferno.de/ati_problem/
> 
> 
>     I noticed you're getting errors for the shader. Try calling this 
> function for the appropriate shader, instead of outputting "invalid 
> shader" .. it should print out the errors ..
> 
> void print_log (GLhandleARB h)
> {
>     GLint e;
>     glGetObjectParameterivARB (h, GL_OBJECT_INFO_LOG_LENGTH_ARB, &e);
> 
>     GLsizei     llen = 0;
>     GLcharARB*  log = new GLcharARB [e + 1];
> 
>     glGetInfoLogARB (h, e + 1, &llen, log);
> 
>     log [llen] = 0;
>     cout << log << endl;
> 
>     delete [] log;
> }
> 
> 
> hth
yeah. the shader errors are weird. I don't get them when I use my own 
GLSL class and Qt...
0
Reply David 10/28/2005 9:14:30 AM

Jakob Bieling wrote:
> "David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
> news:3se6b4Fnkp0sU1@news.dfncis.de...
> 
> 
>>http://www.8bit-inferno.de/ati_problem/
> 
> 
>     I noticed you're getting errors for the shader. Try calling this 
> function for the appropriate shader, instead of outputting "invalid 
> shader" .. it should print out the errors ..
> 
> void print_log (GLhandleARB h)
> {
>     GLint e;
>     glGetObjectParameterivARB (h, GL_OBJECT_INFO_LOG_LENGTH_ARB, &e);
> 
>     GLsizei     llen = 0;
>     GLcharARB*  log = new GLcharARB [e + 1];
> 
>     glGetInfoLogARB (h, e + 1, &llen, log);
> 
>     log [llen] = 0;
>     cout << log << endl;
> 
>     delete [] log;
> }
> 
> 
> hth
okay. i found the error. you tried to pass a vec4 to vec2 texCoord.
I changed

texCoord = gl_MultiTexCoord0;

to

texCoord = gl_MultiTexCoord0.xy;

and everything compiles. though the left quad becomes perfectly black. :-(
0
Reply David 10/28/2005 9:21:12 AM

"David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
news:3se8sbFkno45U1@news.dfncis.de...

>>>http://www.8bit-inferno.de/ati_problem/

> I changed
>
> texCoord = gl_MultiTexCoord0;
>
> to
>
> texCoord = gl_MultiTexCoord0.xy;
>
> and everything compiles. though the left quad becomes perfectly black. 
> :-(

    Did you change the fragment shader to use the shadow functions for 
texture lookup? Also the type of 'texture' needs to be sampler2DShadow! 
Otherwise, you are still in the realms of the undefined ;)

hth
-- 
jb

(reply address in rot13, unscramble first) 


0
Reply Jakob 10/28/2005 11:46:42 AM

Jakob Bieling wrote:
> "David Zellhoefer" <d.zellhoefer@fhtw-berlin.de> wrote in message 
> news:3se8sbFkno45U1@news.dfncis.de...
> 
> 
>>>>http://www.8bit-inferno.de/ati_problem/
> 
> 
>>I changed
>>
>>texCoord = gl_MultiTexCoord0;
>>
>>to
>>
>>texCoord = gl_MultiTexCoord0.xy;
>>
>>and everything compiles. though the left quad becomes perfectly black. 
>>:-(
> 
> 
>     Did you change the fragment shader to use the shadow functions for 
> texture lookup? Also the type of 'texture' needs to be sampler2DShadow! 
> Otherwise, you are still in the realms of the undefined ;)
> 
> hth

just to close this thread: I could not find out why my ATI needed to 
apply a ^70 to all depth values and why it didn't behaved as it was said 
in the OpenGL spec.
I bought a NVIDIA card and everything works as expected.

thanks for your help!

david
0
Reply David 11/2/2005 8:37:13 PM

Hi,

I'm doing the same as you and although the code Jakob works fine on my
Quadro FX 500, my code is still rendering the back as white instead of
black.

Do you have any idea what it might be ?

Thanks.

0
Reply wpr 11/10/2005 1:50:23 PM

wpr wrote:
> Hi,
> 
> I'm doing the same as you and although the code Jakob works fine on my
> Quadro FX 500, my code is still rendering the back as white instead of
> black.
> 
> Do you have any idea what it might be ?
> 
> Thanks.
> 
the background has to be white. the OpenGL spec said that a depth 
texture will be interpreted as a luminance map when displayed.
the standard depth test assumes the far plane to be 1, which is equal 
full luminance.
if you want to use a black background you could change the depth test or 
you can apply the following formula to your fragments:

-(2(x-0,5))^2+1

where x is your incoming fragment.

cheers,

david
0
Reply David 11/10/2005 2:01:13 PM

30 Replies
377 Views

(page loaded in 0.268 seconds)

Similiar Articles:


















7/15/2012 3:40:39 PM


Reply: