problems getting the depth buffer
I've been trying to grab the depth buffer, but have had some problems. Whenever I try to grab it, it shows up as pure white, but I know the depth buffer is working since the scene renders without problems. Lately, it's even frozen: not just the app, but the entire computer! This even happens on both my PowerMac and my MacBook Pro! (talk about making it difficult to debug :/) Anyways, I was hoping you guys might be able to catch where I go wrong.
I use texture rectangles, and I this is what I use for the allocation and parameters of the texture.
This is the code that I use to grab it.
I think it started to freeze when I used glCopyTexSubImage as opposed to glCopyTexImage. I'll test that, but I'll do so after I press post so I don't loose what I've written so far if it is the case.
I also tried setting my viewable area to 512x512 and using GL_TEXTURE_2D rather than GL_TEXTURE_RECTANGLE_ARB, and there was no difference.
For the record, I also tried FBOs, and the depth texture still showed up as all white. However, I've been moving away from FBOs since I learned you can't have higher than a 16 bit depth buffer, which was certainly noticeable, even when I moved the far plane forward. (I still use them when I don't need the depth buffer, though; fortunately the performance hit so far has been minimal) Any suggestions would be appreciated. I suppose if it turns out to always have problems I can always create my own depth buffer with a pixel shader, but I would prefer not to since it would require another pass.
Edit: yup, the problem with the freezing was indeed using glCopySubImage. Here is my new line for the copying:
Still has the problem.
I use texture rectangles, and I this is what I use for the allocation and parameters of the texture.
Code:
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, depthTexture);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_DEPTH_COMPONENT16, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL);This is the code that I use to grab it.
Code:
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, depthTexture);
glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, 0, 0, width, height);I think it started to freeze when I used glCopyTexSubImage as opposed to glCopyTexImage. I'll test that, but I'll do so after I press post so I don't loose what I've written so far if it is the case.
I also tried setting my viewable area to 512x512 and using GL_TEXTURE_2D rather than GL_TEXTURE_RECTANGLE_ARB, and there was no difference.For the record, I also tried FBOs, and the depth texture still showed up as all white. However, I've been moving away from FBOs since I learned you can't have higher than a 16 bit depth buffer, which was certainly noticeable, even when I moved the far plane forward. (I still use them when I don't need the depth buffer, though; fortunately the performance hit so far has been minimal) Any suggestions would be appreciated. I suppose if it turns out to always have problems I can always create my own depth buffer with a pixel shader, but I would prefer not to since it would require another pass.
Edit: yup, the problem with the freezing was indeed using glCopySubImage. Here is my new line for the copying:
Code:
glCopyTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_DEPTH_COMPONENT, 0, 0, width, height, 0);
Alright, I think I figured out the problem: it turns out that I just had my near plane too close. When I went really close, it showed up correctly, so I changed it from 0.1 to 1. It now shows up correctly from a sane distance. I would have liked it to be a little closer, but it shouldn't provide any problem. Unfortunately, when the depth buffer is 16 bits (such as with FBOs) it still has some problems. (when I was still trying to be able to use FBOs, I tried it, and it still had errors
)
)
The GLUT examples has a program (decal) that shows one way to do this.
Sir, e^iπ + 1 = 0, hence God exists; reply!
Thanks, but I fixed it.
The problem was the near plane being too close, causing it to show all white.
The problem was the near plane being too close, causing it to show all white.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Depth Buffer Question | AnotherJake | 10 | 4,068 |
Sep 23, 2008 01:43 PM Last Post: AnotherJake |
|
| Drawing to the Depth Buffer | unknown | 12 | 3,874 |
Dec 9, 2005 02:49 PM Last Post: OneSadCookie |
|
| Depth Buffer / Testing basic question... | WhatMeWorry | 5 | 5,911 |
Nov 18, 2005 12:50 AM Last Post: arekkusu |
|
| Reading from the Depth Buffer | Joseph Duchesne | 2 | 2,815 |
Jun 16, 2005 04:51 PM Last Post: OneSadCookie |
|
| Depth Buffer issues. | NitroPye | 7 | 3,809 |
May 30, 2005 01:11 PM Last Post: NitroPye |
|

