Мне нужно сделать прогу типа 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 const n=1000;
int x=0,b=0;
int x1,x2;
int y=0,c=0;
int z,z1;
int mas1[n],mas2[n],mas3[n],mas4[n],j,k;
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)
{
b=button;
c=state;
if (state == GLUT_DOWN)
{
down=true;
l=true;
}
else
{
down=false;
l=false;
}
x=ax;
y=ay;
}
void motion(int ax, int ay)
{
x1=x;
z=y;
if (l)
{
x2=ax;
z1=ay;
}
if (!l)
{
x1=ax;
z=ay;
}
glutPostRedisplay();
}
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);
glEnd();
glutSwapBuffers();
}
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);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
//glutPassiveMotionFunc(motion);
glutDisplayFunc (Draw);
//timer();
glutMainLoop ();
cin.get();
cin.get();
}