Мне нужно сделать прогу типа Paint. Я с помощью glutMotionFunc сделал чтобы рисовалась линия и ее можно было крутить и растягивать как пожелаешь, но когда рисуешь вторую линию, первая пропадает. Как сделать чтоб первая и все последующие линии оставались (чтоб ими можно было рисовать). Вот код, подскажите что может поменять или добавить
Код | #include <windows.h> #include <iostream> #include "GL/gl.h" #include "GL/glu.h" #include "GLAUX.h" #include <glut.h> using namespace std; int x=0,b=0; int x1,x2; int y=0,c=0; int z,z1; bool down=false, l=false; unsigned char kei; void keyboard ( unsigned char key, int x, int y) { switch (key) {
case 'q':
exit(0);
break; } }
void reshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity();
gluOrtho2D(0, w, h, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }
void mouse(int button, int state, int ax, int ay) { if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { down=true; l=true; } else { down=false; l=false; } x=ax; y=ay; cout<<x<<" "; cout<<y<<endl;
} void motion(int ax, int ay) { x1=x; z=y; if (!l) { x1=ax; z=ay; } else { x2=ax; z1=ay; }
b=ax; c=ay; }
void Draw() { glClear (GL_COLOR_BUFFER_BIT); glLineWidth(5); glBegin (GL_LINES); glColor3f (0.0, 1.0, 0.0); glVertex2f (x1, z); glVertex2f (x2, z1); //glVertex2f (x2, z1); //glVertex2f (x1, z1);
glColor3f (0.0, 1.0, 0.0); glBegin (GL_LINES);
glVertex3f (100, 900, 0.0); glVertex3f (100, 0, 0.0);
glEnd(); glutSwapBuffers(); glutPostRedisplay(); } void timer(int=0) { Draw();
glutTimerFunc (1,timer,0);
} void Initialize() { glClearColor (1.0, 1.0, 1.0, 1.0); glMatrixMode (GL_PROJECTION); glLoadIdentity(); glOrtho (0, 1280, 1024, 0, -1, 1); } int main(int iArgc,char** cppArgv) { glutInit (&iArgc, cppArgv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); glutInitWindowPosition (0, 0); glutCreateWindow ("GRAF"); Initialize(); glutFullScreen(); glutReshapeFunc (reshape); glutMouseFunc(mouse); glutDisplayFunc (Draw); glutKeyboardFunc(keyboard); glutMotionFunc(motion); //glutPassiveMotionFunc(motion); timer(); glutMainLoop (); glutSwapBuffers();
cin.get(); cin.get(); }
|
|