Replace fudging of coordinates with glPolygonOffset().

[git-p4: depot-paths = "//depot/solvespace/": change = 1721]
solver
Jonathan Westhues 2008-05-13 03:27:32 -08:00
parent aa5c621d82
commit 21c0c87d8e
2 changed files with 13 additions and 12 deletions

View File

@ -508,15 +508,16 @@ Quaternion Entity::PointGetQuaternion(void) {
void Entity::LineDrawOrGetDistance(Vector a, Vector b) { void Entity::LineDrawOrGetDistance(Vector a, Vector b) {
if(dogd.drawing) { if(dogd.drawing) {
// This fudge guarantees that the line will get drawn in front of glPolygonOffset(-5, -5);
// anything else at the "same" depth in the z-buffer, so that it glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// goes in front of the shaded stuff. // Have to draw this as a polygon in order to make the offset work.
Vector n = SS.GW.projRight.Cross(SS.GW.projUp); glBegin(GL_TRIANGLES);
n = n.WithMagnitude(3/SS.GW.scale); glxVertex3v(a);
glBegin(GL_LINE_STRIP); glxVertex3v(b);
glxVertex3v(a.Plus(n)); glxVertex3v(b);
glxVertex3v(b.Plus(n));
glEnd(); glEnd();
glPolygonOffset(0, 0);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
} else { } else {
Point2d ap = SS.GW.ProjectPoint(a); Point2d ap = SS.GW.ProjectPoint(a);
Point2d bp = SS.GW.ProjectPoint(b); Point2d bp = SS.GW.ProjectPoint(b);
@ -596,17 +597,15 @@ void Entity::DrawOrGetDistance(int order) {
Vector r = SS.GW.projRight.ScaledBy(s/SS.GW.scale); Vector r = SS.GW.projRight.ScaledBy(s/SS.GW.scale);
Vector d = SS.GW.projUp.ScaledBy(s/SS.GW.scale); Vector d = SS.GW.projUp.ScaledBy(s/SS.GW.scale);
// The usual fudge, to make this appear in front.
Vector gn = SS.GW.projRight.Cross(SS.GW.projUp);
v = v.Plus(gn.ScaledBy(4/SS.GW.scale));
glxColor3d(0, 0.8, 0); glxColor3d(0, 0.8, 0);
glPolygonOffset(-10, -10);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glxVertex3v(v.Plus (r).Plus (d)); glxVertex3v(v.Plus (r).Plus (d));
glxVertex3v(v.Plus (r).Minus(d)); glxVertex3v(v.Plus (r).Minus(d));
glxVertex3v(v.Minus(r).Minus(d)); glxVertex3v(v.Minus(r).Minus(d));
glxVertex3v(v.Minus(r).Plus (d)); glxVertex3v(v.Minus(r).Plus (d));
glEnd(); glEnd();
glPolygonOffset(0, 0);
} else { } else {
Point2d pp = SS.GW.ProjectPoint(v); Point2d pp = SS.GW.ProjectPoint(v);
// Make a free point slightly easier to select, so that with // Make a free point slightly easier to select, so that with

View File

@ -1085,6 +1085,8 @@ void GraphicsWindow::Paint(int w, int h) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH); glEnable(GL_LINE_SMOOTH);
glEnable(GL_POLYGON_OFFSET_LINE);
glEnable(GL_POLYGON_OFFSET_FILL);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glEnable(GL_NORMALIZE); glEnable(GL_NORMALIZE);