| | | | |
In lugnet.cad, Santeri Piippo wrote:
|
Polygon sorting - help needed
I need a little bit help, however. The polygon sorting algorithm I have right
now does not work properly. Currently its done by calculating the center of
the polygon by simply calculating the means of the coordinates.
How do existing programs - LDView in particular as its an OpenGL one too -
sort polygons? Id appreciate help tremendously here..
|
The only polygons that LDView sorts are transparent ones. Everything else is
handled by the OpenGL depth buffer (glEnable(GL_DEPTH_TEST), followed by
glDepthFunc(GL_LEQUAL)). Transparent polygons need to be sorted before being
drawn, and LDView does what you describe above for those. (Theres more to it
than that for transparent polygons; sorting is just one step.)
Sorting by the distance to the centroid is only an approximation, but its good
enough to look pretty good for transparent polygons. Its not good enough to
be used as the primary means of hiding geometry thats farther away from the
viewer.
--Travis
| | | | | | | | | | | | | In lugnet.cad, Travis Cobbs wrote:
|
In lugnet.cad, Santeri Piippo wrote:
|
Polygon sorting - help needed
I need a little bit help, however. The polygon sorting algorithm I have
right now does not work properly. Currently its done by calculating the
center of the polygon by simply calculating the means of the coordinates.
How do existing programs - LDView in particular as its an OpenGL one too -
sort polygons? Id appreciate help tremendously here..
|
The only polygons that LDView sorts are transparent ones. Everything else is
handled by the OpenGL depth buffer (glEnable(GL_DEPTH_TEST), followed by
glDepthFunc(GL_LEQUAL)). Transparent polygons need to be sorted before
being drawn, and LDView does what you describe above for those. (Theres
more to it than that for transparent polygons; sorting is just one step.)
Sorting by the distance to the centroid is only an approximation, but its
good enough to look pretty good for transparent polygons. Its not good
enough to be used as the primary means of hiding geometry thats farther away
from the viewer.
|
If you prefer not to sort at all you can use glEnable(GL_POLYGON_STIPPLE)
for transparent polygons. It doesnt look nearly as good, but its really
easy to code.
Have fun,
Don
| | | | | | | | | | | | | | | | | | In lugnet.cad, Don Heyse wrote:
|
If you prefer not to sort at all you can use glEnable(GL_POLYGON_STIPPLE)
for transparent polygons. It doesnt look nearly as good, but its really
easy to code.
Have fun,
Don
|
If you want a visual example on stipple, look at my LD4DStudio, it uses it for
transparent stuff.
In combination with depth buffer you dont need to sort anything just push the
triangles and/or quad cords using glDrawElements and optionally vbo.
vbo means the driver will try to put all vertex data in video memory for
rendering, this is about four times faster on most cards.
Ill try to (re)find the tutorials/website I used to get started with LD4DStudio
and post them tonight. But most stuff you can find by doing a search on
glDrawElements and vbo (vertex buffer object)
ps: i suggest moving this to dev
Roland
| | | | | | | | | | | | | | | | --snip--
|
Sorting by the distance to the centroid is only an approximation, but its
good enough to look pretty good for transparent polygons. Its not good
enough to be used as the primary means of hiding geometry thats farther away
from the viewer.
--Travis
|
Out of interest which centroid do you use? I would have thought that the
bounding box center was better than the centre of all corner points (since these
cluster around areas of high detail) but youve presumably tried different
centroid algorithms.
Tim
| | | | | | | | | | | | | | | | | | In lugnet.cad, Timothy Gould wrote:
|
--snip--
|
Sorting by the distance to the centroid is only an approximation, but its
good enough to look pretty good for transparent polygons. Its not good
enough to be used as the primary means of hiding geometry thats farther
away from the viewer.
--Travis
|
Out of interest which centroid do you use? I would have thought that the
bounding box center was better than the centre of all corner points (since
these cluster around areas of high detail) but youve presumably tried
different centroid algorithms.
|
For transparency, LDView sorts triangles, and only triangles, not parts. So the
centroid of each triangle is (p1 + p2 + p3) * (1/3).
All transparent geometry in the whole model goes into one big list of triangles.
While Im at it, I calculate the centroid for each triangle so I only have to do
that at model load time. At the beginning of each frame, I calculate the
distance squared to each triangles centroid based on the current viewing angle.
Then I do a qsort() with those distances. (I used distance squared in order to
avoid an unnecessary square root.)
--Travis
| | | | | | | | | | | | | | | | In lugnet.cad, Travis Cobbs wrote:
|
The only polygons that LDView sorts are transparent ones. Everything else is
handled by the OpenGL depth buffer (glEnable(GL_DEPTH_TEST), followed by
glDepthFunc(GL_LEQUAL)). Transparent polygons need to be sorted before
being drawn, and LDView does what you describe above for those. (Theres
more to it than that for transparent polygons; sorting is just one step.)
Sorting by the distance to the centroid is only an approximation, but its
good enough to look pretty good for transparent polygons. Its not good
enough to be used as the primary means of hiding geometry thats farther away
from the viewer.
--Travis
|
I see.. but problem is that if I use glEnable(GL_DEPTH_TEST) then my polygons
wont render at all. Tutorials related to OpenGL explicitly told not to use
GL_DEPTH_TEST because of this.. how did you avoid it?
| | | | | | | | | | | | | | | | | In lugnet.cad, Santeri Piippo wrote:
|
In lugnet.cad, Travis Cobbs wrote:
|
The only polygons that LDView sorts are transparent ones. Everything else
is handled by the OpenGL depth buffer (glEnable(GL_DEPTH_TEST), followed
by glDepthFunc(GL_LEQUAL)). Transparent polygons need to be sorted before
being drawn, and LDView does what you describe above for those. (Theres
more to it than that for transparent polygons; sorting is just one step.)
Sorting by the distance to the centroid is only an approximation, but its
good enough to look pretty good for transparent polygons. Its not good
enough to be used as the primary means of hiding geometry thats farther
away from the viewer.
--Travis
|
I see.. but problem is that if I use glEnable(GL_DEPTH_TEST) then my
polygons wont render at all. Tutorials related to OpenGL explicitly told not
to use GL_DEPTH_TEST because of this.. how did you avoid it?
|
In order for GL_DEPTH_TEST to work, you have to clear the depth buffer at the
same time you clear the rest of the screen:
glClearDepth(1.0);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
(Note: the glClearDepth() and glClearColor() calls above arent really
necessary, since they pass the OpenGL default values, but just in case you used
some other value, the above is what you want for glClearDepth().)
--Travis
| | | | | | | | | | | | | | | | | In lugnet.cad.dev, Travis Cobbs wrote:
|
In lugnet.cad, Santeri Piippo wrote:
|
In lugnet.cad, Travis Cobbs wrote:
|
The only polygons that LDView sorts are transparent ones. Everything else
is handled by the OpenGL depth buffer (glEnable(GL_DEPTH_TEST), followed
by glDepthFunc(GL_LEQUAL)). Transparent polygons need to be sorted before
being drawn, and LDView does what you describe above for those. (Theres
more to it than that for transparent polygons; sorting is just one step.)
Sorting by the distance to the centroid is only an approximation, but its
good enough to look pretty good for transparent polygons. Its not good
enough to be used as the primary means of hiding geometry thats farther
away from the viewer.
--Travis
|
I see.. but problem is that if I use glEnable(GL_DEPTH_TEST) then my
polygons wont render at all. Tutorials related to OpenGL explicitly told
not to use GL_DEPTH_TEST because of this.. how did you avoid it?
|
In order for GL_DEPTH_TEST to work, you have to clear the depth buffer at
the same time you clear the rest of the screen:
glClearDepth(1.0);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
(Note: the glClearDepth() and glClearColor() calls above arent really
necessary, since they pass the OpenGL default values, but just in case you
used some other value, the above is what you want for glClearDepth().)
--Travis
|
Ah, thank you Travis! I got depth buffering working now. :)
No more problems with polygon sorting..
-Santeri
| | | | | | |