OpenGL Best way to test the depth?

This topic is 4518 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I have a heightmap that i test the depth in a special + faster way. & now i need models on this heightmap, then i need to test the depth of all models only. But I think that OpenGL will test with all the triangles I've already drawn (the H-Map). & if i draw the H-Map last the models will get overlapped by it. Im I able to use my own way to test the depth & then use OpenGL's in a fast way? If not then: Is the depth tested in the Graphics card? (im thinking of calculating the depth myself in the CPU) Thanx!

Share on other sites
Not sure I follow. Wouldn't you want the heightmap to overlap models where occlusion occures? If a part of the heightmap is in front of a model, it should be obscured, no?

Share on other sites
Im not 100% sure what i want yet.. So it is hard to explain. Im testing a weird technique... But can someone please answer this: Is the depth tested in the Graphics card?

[Edited by - masterviking on April 29, 2006 6:26:55 AM]

Think so, yeah.

Share on other sites
Im sorry but a "think so" is not enough... I now know what I want. Question:
Can I calculate the depth of only a single soup of triangles? (Using OpenGL's built in system!?)
a_a _ a_ a_ a_
\_||_||_||_||_/
|\||_||_||_||/|
|_\|_|SOUP|/_|
|_|\_||_||_/|_|
|_||\||_||/||_|
aaaaa\aa/
aaaaaa\/
aaaaa_cam

The squares is heightmap squares :)

& then draw that soup at a position while drawing the heightmap sqares from the top to the bottom?

Share on other sites
EDIT: Oh wait, I think I misinterpreted your question.

If you want to draw a height map, you simply have to put the z coordinate of the heights further away from the screen than your models. The graphics card's rasteriser and OpenGL's vertex transformations will take care of your z-ordering for you. It will also run very fast. :) Do not try to calculate depth from the camera on the CPU, unless you want your program to run very slowly. The GPU does all that these days.

For reference, could you clarify, are you doing a 2D or 3D effect? It appears that you are talking about a 2D effect, in which case, even in orthographic mode, OpenGL uses a z coordinate for ordering polygons' distances from screen.

[Edited by - Leo_E_49 on May 7, 2006 6:12:50 PM]

Share on other sites
Thanx for trying to answer :)
But I really want a faster way to do this, because I see that it whould be possible... But its maybe alot of work.

\________/
a\_Soup_/
aa\____/
aaa\aa/
aaaa\/
aaa_cam

The line above the soup is a wall & also the line below.

If it whould be possible to render the scene in 3 steps then it whould work fine - first the wall above then the soup & then the wall below. [But only if it is possible to render it in 3 steps inthis way!]

Simple:
Then this became another question:
Are you able to send triangles to the graphics card & then tell it to render them & after that send in new triangles to be rendered over them?

Haha, yes! (know the answer) The power of intelligent questions have shown up!

To make other learn on this topic, i will answer the question: You can actually use the function "SwapBuffers([pointer to a hardware device context])", & not clear the screen in-between.
Like this:
DrawWall1();
SwapBuffers(hdc);
DrawSoup();
SwapBuffers(hdc);
DrawWall2();
SwapBuffers(hdc);

But now we can discuss if this way is faster :) ..hmm..

EDIT: & I will have to use the "Swap" function 100-1000 times... So that doesn't sound very good...

Share on other sites
Yes, that's what I meant.

Just call the SwapBuffers() function only once:
DrawWall1();DrawSoup();DrawWall2();SwapBuffers(hdc);

Everything is handled by OpenGL for you. :)

From what I understand, the SwapBuffers function is very slow compared to the rest of OpenGL, so you should only call it once per scene render.

OpenGL uses the graphics hardware so it is very much faster than processing on the CPU and sending the data to the graphics card so many times. OpenGL sends all the data from the scene at once to the graphics card to speed up the rendering (this is usually called batch processing).

I will give you a basic explanation of how this all works so you understand. The following is called the "Graphics Pipeline" (It's a general version, not an official OpenGL version):

1. You enter all your vertex data and matrices into the program.
1a. Your vertex data and matrices are sent to the graphics card.
2. Your vertices are transformed in the GPU by a world matrix into "world space".
3. Lighting is performed on all your vertices.
4. Your vertices are transformed by a view matrix into "view space".
5. Your vertices are projected by a projection matrix into "screen space".
6. Triangles are created from your vertices.
7. The triangles are clipped to the screen coordinates.
8. The triangles are rasterized to a graphical buffer by a rasterizer.
9. Textures and colours are applied to the buffer where your triangles are.
10. The buffer is copied to screen.

This happens once every frame. (P.S. If anyone sees anything wrong with this, please correct me)

2 to 5 can be replaced with a vertex shader. 9 can be replaced with a fragment shader.

A full description of this can be found here: clicky

Sorry to confuse you earlier. I made a mistake and didn't understand what you were talking about. :(

[Edited by - Leo_E_49 on May 7, 2006 6:19:49 PM]

Share on other sites
"A full description of this can be found here: clicky"
That is alot of text, but thank you. I will read it.

This text I didn't see:
"OpenGL uses a z coordinate for ordering polygons' distances from screen."
That's only if you enable GL_DEPTH_TEST... & that function is very undesirable to use when you can draw some triangles in the right order.. But what im talking about is that I can draw most triangles in the right order but some I cannot.

Ok - now I see that it whould be resource eating to use SwapBuffers(hdc); all the time... I know that there is no way to exactly do this with a simple function, but Im looking for some way to send blocks/soups of triangles that the graphics card should calculate the depth on (on each block you send [but not check what blocks is closest/furthest from cam]) & then I just give a 3D position where the block should be drawn, & in what order they should be drawn (in the order that i sent the blocks in).

So the graphics card should check the depth of only some triangles that I send in, not all. But I have heard that GL_DEPTH_TEST checks the depth on all tris. Or?

Share on other sites
Well, you can disable GL_DEPTH_TEST and test depths of objects yourself by sorting them. However, it's unlikely that your depth sorting algorithm will be able to match the speed of OpenGL anyway. Furthermore, using GL_DEPTH_TEST, depths are tested per pixel. So if an object appears infront of as well as behind another object, it will draw correctly. Where as, if the objects are just simply drawn in order without GL_DEPTH_TEST enabled, it will be impossible to do this (unless you do the test for every triangle, which will be very slow and also not as accurate).

GL_DEPTH_TEST will automatically handle your triangles so you do not need to sort them. It uses something called the "painter's algorithm" on every pixel to do this.

http://en.wikipedia.org/wiki/Painter's_algorithm

I'm not sure why you say that GL_DEPTH_TEST is very undesireable to use? What makes you say that? It works well for most people.

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5

• 9
• 12
• 9
• 33
• 13
• Forum Statistics

• Total Topics
632595
• Total Posts
3007267

×