Add a GLPainter class to do all the OpenGL drawing stuff
This commit is contained in:
@@ -948,7 +948,7 @@ void View3DInventorViewer::actualRedraw(void)
|
||||
vv.projectToScreen(pt, pt);
|
||||
int tox = (int)(pt[0] * size[0]);
|
||||
int toy = (int)((1.0f-pt[1]) * size[1]);
|
||||
flag->drawLine(tox, toy);
|
||||
flag->drawLine(this, tox, toy);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1506,181 +1506,6 @@ void View3DInventorViewer::viewSelection()
|
||||
root->unref();
|
||||
}
|
||||
|
||||
// Draw routines
|
||||
void View3DInventorViewer::drawRect(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
// Make current context
|
||||
SbVec2s view = this->getGLSize();
|
||||
this->glLockNormal();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrtho(0, view[0], 0, view[1], -1, 1);
|
||||
|
||||
// Store GL state
|
||||
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
||||
GLfloat depthrange[2];
|
||||
glGetFloatv(GL_DEPTH_RANGE, depthrange);
|
||||
GLdouble projectionmatrix[16];
|
||||
glGetDoublev(GL_PROJECTION_MATRIX, projectionmatrix);
|
||||
|
||||
glDepthFunc(GL_ALWAYS);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDepthRange(0,0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
glEnable(GL_COLOR_LOGIC_OP);
|
||||
glLogicOp(GL_XOR);
|
||||
glDrawBuffer(GL_FRONT);
|
||||
glLineWidth(3.0f);
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
glLineStipple(2, 0x3F3F);
|
||||
glColor4f(1.0, 1.0, 0.0, 0.0);
|
||||
glViewport(0, 0, view[0], view[1]);
|
||||
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glVertex3i(x1, view[1]-y1, 0);
|
||||
glVertex3i(x2, view[1]-y1, 0);
|
||||
glVertex3i(x2, view[1]-y2, 0);
|
||||
glVertex3i(x1, view[1]-y2, 0);
|
||||
glEnd();
|
||||
|
||||
glFlush();
|
||||
glDisable(GL_LINE_STIPPLE);
|
||||
glDisable(GL_COLOR_LOGIC_OP);
|
||||
|
||||
// Reset original state
|
||||
glDepthRange(depthrange[0], depthrange[1]);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixd(projectionmatrix);
|
||||
|
||||
glPopAttrib();
|
||||
glPopMatrix();
|
||||
|
||||
// Release the context
|
||||
this->glUnlockNormal();
|
||||
}
|
||||
|
||||
void View3DInventorViewer::drawLine (int x1, int y1, int x2, int y2)
|
||||
{
|
||||
// Make current context
|
||||
SbVec2s view = this->getGLSize();
|
||||
this->glLockNormal();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrtho(0, view[0], 0, view[1], -1, 1);
|
||||
|
||||
// Store GL state
|
||||
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
||||
GLfloat depthrange[2];
|
||||
glGetFloatv(GL_DEPTH_RANGE, depthrange);
|
||||
GLdouble projectionmatrix[16];
|
||||
glGetDoublev(GL_PROJECTION_MATRIX, projectionmatrix);
|
||||
|
||||
glDepthFunc(GL_ALWAYS);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDepthRange(0,0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
glLineWidth(1.0f);
|
||||
glColor4f(1.0, 1.0, 1.0, 0.0);
|
||||
glViewport(0, 0, view[0], view[1]);
|
||||
|
||||
glEnable(GL_COLOR_LOGIC_OP);
|
||||
glLogicOp(GL_XOR);
|
||||
glDrawBuffer(GL_FRONT);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glVertex3i(x1, view[1]-y1, 0);
|
||||
glVertex3i(x2, view[1]-y2, 0);
|
||||
glEnd();
|
||||
|
||||
glFlush();
|
||||
glLogicOp(GL_COPY);
|
||||
glDisable(GL_COLOR_LOGIC_OP);
|
||||
|
||||
// Reset original state
|
||||
glDepthRange(depthrange[0], depthrange[1]);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixd(projectionmatrix);
|
||||
|
||||
glPopAttrib();
|
||||
glPopMatrix();
|
||||
|
||||
// Release the context
|
||||
this->glUnlockNormal();
|
||||
}
|
||||
|
||||
void View3DInventorViewer::drawLine (int x1, int y1, int x2, int y2, GLfloat line,
|
||||
GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha,
|
||||
GLenum op)
|
||||
{
|
||||
// Make current context
|
||||
SbVec2s view = this->getGLSize();
|
||||
this->glLockNormal();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrtho(0, view[0], 0, view[1], -1, 1);
|
||||
|
||||
// Store GL state
|
||||
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
||||
GLfloat depthrange[2];
|
||||
glGetFloatv(GL_DEPTH_RANGE, depthrange);
|
||||
GLdouble projectionmatrix[16];
|
||||
glGetDoublev(GL_PROJECTION_MATRIX, projectionmatrix);
|
||||
|
||||
glDepthFunc(GL_ALWAYS);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDepthRange(0,0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
glLineWidth(line);
|
||||
glColor4f(red, green, blue, alpha);
|
||||
glViewport(0, 0, view[0], view[1]);
|
||||
|
||||
if (op > 0) {
|
||||
glEnable(GL_COLOR_LOGIC_OP);
|
||||
glLogicOp(op);
|
||||
}
|
||||
glDrawBuffer(GL_FRONT);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glVertex3i(x1, view[1]-y1, 0);
|
||||
glVertex3i(x2, view[1]-y2, 0);
|
||||
glEnd();
|
||||
|
||||
glFlush();
|
||||
if (op) {
|
||||
glLogicOp(GL_COPY);
|
||||
glDisable(GL_COLOR_LOGIC_OP);
|
||||
}
|
||||
|
||||
// Reset original state
|
||||
glDepthRange(depthrange[0], depthrange[1]);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixd(projectionmatrix);
|
||||
|
||||
glPopAttrib();
|
||||
glPopMatrix();
|
||||
|
||||
// Release the context
|
||||
this->glUnlockNormal();
|
||||
}
|
||||
|
||||
/*!
|
||||
Decide if it should be possible to start a spin animation of the
|
||||
model in the viewer by releasing the mouse button while dragging.
|
||||
|
||||
Reference in New Issue
Block a user