我想在我的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