quake2 map reader

I have a big problem…
I have made i fuctional worldcraft map reader, and render, but
when i render the image, i have some problems, that i don’t even
know why they happen.
When i’m near a wall, everything is nice and ok, when i start moving away from the wall, the connections to the other walls, begin to look strange, and i can eve see, what’s behind the wall
Could you look at these screenshots, to see what do i mean?
If you are wondering, those walls are made of just one quad…, but in the picture it looks like there is more than 3 or 4 quads in the wall.
any ideas on whats happening??

The pictures are at: www.geocities.com/brunomtc/screen1.jpg www.geocities.com/brunomtc/screen2.jpg www.geocities.com/brunomtc/screen3.jpg


Man, is that dark in there.
Looks a little like z-buffer bleeding. Check out the ratio between zFar/zNear clipping planes of your viewing frustum. Make the zFar/zNear as small as possible to gain more precision from the available depth bits.

Yes, it looks like you have set too large z distance and/or running app on 16-bit zbuffer.

Yes, indeed the room in very long, but that shouldn’t be a problem, or should?
How do i do that znear/zfar?

I have done this, but it doens’t do anything when i increase the 10.



NEVER SET zNear to ZERO!!!

“Depth-buffer precision is affected by the values specified for znear and zfar. The greater the ratio of zfar to znear is, the less effective the depth buffer will be at distinguishing between surfaces that are near each other. If r=zFar/zNear roughly log (2) r bits of depth buffer precision are lost. Because r approaches infinity as znear approaches zero, you should never set znear to zero.”

but how the hell to i calculate my znear, zfar??

Here is how glFrustum works:

glFrustum(left, right, bottem, top, zNear, zFar);

I have the same problem in my Q3-viewer but I still don´t know how to solve it ´cause I already set zNear=-1 + zFar=5000…And I cannot make the dist between zNear and zFar smaller ´cause I need at least 5000 depth in those really big levels(q3ctf4…).And I use a 32bit depth-buffer…

P.s.:I´m not really sure if I have the same problem in my viewer what is happening is that vertices begin to “swim” if you move away from them…If you are near those objects\vertices everything looks correct…

Any ideas?

Thanx in advance,XBTC!

[This message has been edited by XBCT (edited 07-27-2000).]

Usually, you just choose what you want them to be. In some cases you might be better off determining zfar from the size of the map, if the map is fairly open in nature, i.e. big map which allows you to see most of map from end to end. You can store in each leaf of the bsp, the maximum distance viewable (as determined by the pvs), then use the relative offset as the zfar. I believe Q3 does this as I notice that it resets the projection matrix for every single frame. Something you are generally told to set and forget.

[This message has been edited by DFrey (edited 07-27-2000).]

DDFrey:Yes your idea seems to prevent this effect from happening if I am in a small room but in those big outdoor places in Q3 the problem would still appear with your approach…And look at Q3,at least on my machine there is no problem like that…


Actually, when I’m in 16 bpp mode (16 bit depth buffer) on my TNT, Z artifacts do occur in Q3 on the larger maps like Q3DM17, and Q3CTF4. But when in 32 bpp (24 bit depth buffer), the artifacts vanish. And I am using the latest drivers too.

Well XBTC, my problem seems exactly the same as yours…, when i’m near the vertices (200) everyting is ok, when i move away, it gets strange…, bu i don’t think that the problem is in frustum…, if the problem was that, if we make znear 0,1 and zfar 10000 then the world should look ok, shouldn’t it?


DFrey…, your technique also works if i have a small world…, but in largers worlds…not a chance, and in quake2 they have pretty large worlds

Well then I don’t know what you are doing then because for me, it worked just as good as Quake3 does (for me, even Quake3 has z artifacts on the largest levels). You just have to realize that there is only so much precision available and most of it is going to be towards the near end. The only ways to really deal the z-aliasing on really large open levels is to either use more precision (more depth buffer bits), or hide it with fog, or just let it be. Quake3 appears to just let it be. At least on my TNT with the 5.22 drivers it does. I’ll gladly post a screenshot if you don’t believe Quake3 suffers from z-aliasing.

[This message has been edited by DFrey (edited 07-27-2000).]

If you say Quake3 as this problem in your computer, it’s because q3 as this problem, you don’t need to post a screenshot
How do i increase the depth buffer bits?
Are you talking about the bits we select when creating the win32 window?


Yes, particularly when selecting the pixel format. Instead of requesting a 16 bit depth buffer, request a 24 bit depth buffer. You may only be able to get a 24 bit depth buffer in 32 bpp color mode on some video cards though. For example, on my TNT, I’ve never been able to get a 24 bit depth buffer in 16 bpp mode, I can only get 16 bits at best.

Thanks a lot, but it still doens’t work

What are you setting zNear to? In my Q3 map viewer I used 4 for zNear and determined zFar from the size of the map. It worked just as good as Quake3 when I did this.

[This message has been edited by DFrey (edited 07-27-2000).]

I was setting znear to 2, and zfar to 1000.
With 4, it doens’t work also.
Can i send you my source code, maybe i’m missing something???


Sure I’ll take look at it.
Send it to dfrey@shreve.net