我想在我的OpenGL和C++程序中用我的鼠标绘制多个线段。现在我可以绘制一个,一旦我开始绘制另一个,前一个消失。在OpenGL中绘制多行与鼠标
下面是我的与鼠标绘图相关的代码。有关如何绘制多条线的任何建议?
LineSegment seg;
void mouse(int button, int state, int x, int y) {
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { // if left button is clicked, that is the start point
seg.x1 = seg.x2 = x;
seg.y1 = seg.y2 = y;
}
if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) { // once they lift the mouse, thats the finish point
seg.x2 = x;
seg.y2 = y;
}
}
void motion(int x, int y) {
seg.x2 = x;
seg.y2 = y;
glutPostRedisplay(); // refresh the screen showing the motion of the line
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT); // clear the screen
glBegin(GL_LINES); // draw lines
glVertex2f(seg.x1, seg.y1);
glVertex2f(seg.x2, seg.y2);
glEnd();
glutSwapBuffers();
}
我第二是**强烈劝喻**;那个OpenGL石器时代的军团显然被弃用了。 –
是的。我习惯于每个从Java循环,所以这样的怪癖对我来说还不是很明显。 – Xirema
当你开始学习现代版本时,学习旧的openGL可以派上用场。 – OpenGLmaster1992