Subject:
|
Re: Type 5 lines, BFC relevance, and OpenGL
|
Newsgroups:
|
lugnet.cad.dev
|
Date:
|
Fri, 1 Apr 2005 06:37:09 GMT
|
Viewed:
|
2140 times
|
| |
| |
In lugnet.cad.dev, Don Heyse wrote:
|
Hmmm, draw the edge twice and flip the stencil bit eh? It sounds
like it could work. Ill have to read up on edge flags. I havent
used them for anything yet.
By the way, you should be able to get all the info you need from
the type 5 line itself, without examining the adjacent polygons
A and B. Remember the type 5 line has 4 points: Two on the line
itself, and two from the adjacent polys (or somewhere equivalent
enough for this algorithm).
Lets see it in some code.
|
Well, I tried this in LDView, and it seems to work fine. I havent yet put the
new stuff in a display list, so its drawing all the type 5 line geometry in
immediate mode. Consequently, Im not yet sure how fast it will be (its very
similar performance to my old way currently).
Having said that, here is what I did:
// First, save some state info
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_STENCIL_BUFFER_BIT);
glEnable(GL_STENCIL_TEST);
glEnable(GL_CULL_FACE);
// Save some more state info (we'll pop this after drawing
// the stencil triangles, but before drawing the actual lines.
glPushAttrib(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthMask(GL_FALSE);
glStencilMask(0xFFFFFFFF);
glStencilFunc(GL_ALWAYS, 0x7FFFFFFF, 0xFFFFFFFF);
glStencilOp(GL_INVERT, GL_KEEP, GL_INVERT);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// Draw two triangles for each conditional line.
// Note that I'm drawing triangles for all conditional
// lines in the model at once. Note also that depth
// testing is still turned on. (It doesn't work right
// without depth testing unless the model itself is
// being drawn in wireframe. I assume this is due to
// the fact that I'm doing everything in one go.
// If index1 and index2 are the endpoints of the line
// and cpIndex1 and cpIndex2 are the control points,
// the actual triangle drawing looks like so (note that
// this will be repeated for every type 5 line in the file):
// Note that I ordered my drawing to have the fewest
// possible calls to glEdgeFlag, going on the assumption
// that like other OpenGL state changes, calling that
// takes some amount of time. Note also that I'm assuming
// that the edge flag is TRUE coming in here (the default),
// and I leave it TRUE on the way out.
loop
{
// First triangle
glVertex3fv(vertices[index1]);
glEdgeFlag(GL_FALSE);
glVertex3fv(vertices[index2]);
glVertex3fv(vertices[cpIndex1]);
// Second triangle
glVertex3fv(vertices[index1]);
glVertex3fv(vertices[cpIndex2]);
glEdgeFlag(GL_TRUE);
glVertex3fv(vertices[index2]);
}
// Assume the above drew all the triangles.
// Restore the state necessesary for the line drawing.
glPopAttrib(); // GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
glStencilFunc(GL_NOTEQUAL, 0, 0xFFFFFFFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
// Now draw every single conditional line. You can
// use vertex arrays if you want to here.
drawLines()
// Restore the rest of our GL state back to the way it was.
glPopAttrib();
|
|
Hope this helps.
--Travis
|
|
Message has 1 Reply: | | Re: Type 5 lines, BFC relevance, and OpenGL
|
| So, I got the code updated so the conditional drawing happens in a display list, and then built LDView with full optimizations turned on in the compiler, and the new method actually runs slightly slower than the old method. (This is on an ATI Radeon (...) (20 years ago, 3-Apr-05, to lugnet.cad.dev, FTX)
|
Message is in Reply To:
| | Re: Type 5 lines, BFC relevance, and OpenGL
|
| Hmmm, draw the edge twice and flip the stencil bit eh? It sounds like it could work. I'll have to read up on edge flags. I haven't used them for anything yet. By the way, you should be able to get all the info you need from the type 5 line itself, (...) (20 years ago, 29-Mar-05, to lugnet.cad.dev)
|
9 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|