hi every body
i implment small program for draw line
the user specify the first and end point and he can use right button to show menu cang color ,think or pattren
the code work proprtly but
i want allowed to user draw more than one line
and change the proprites of line independent way than the others
how i can do that?
this is my code
#include <gl/glut.h>
float red=1.0,blue=0.0,green=0.0,width=1;
int con=0,x1=0,x2=0,y1=0,y2=0,patt=0;
//***********
void selectcolor (int selection )
{ switch (selection)
{ case 1: red=1.0; blue=0.0;green=1.0;
break;
case 2: red=0.0 ; blue=0.0; green=1.0;
break;
case 3: red=0.0;blue=1.0;green=0.0;
break;}
glutPostRedisplay();}
//**************
void selectionstipp (int selectstripp)
{ patt=selectstripp;
glutPostRedisplay();}
//*************
void selectwidth(int selectwidth)
{switch (selectwidth)
{case 7:width=7;
break;
case 8: width=9;
break;
case 9: width=11;
break;
}
glutPostRedisplay();}
//******************* main menu
void select (int selectmain)
{switch(selectmain)
{case 0:exit(0);}
glutPostRedisplay();}
//************************
void reshape(int w,int h)
{glViewport(0,0,300,300);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,300,0.0,300.0);
}
//*****************
void display (void)
{glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_LINE_STIPPLE);
switch(patt)
{case 4:
glLineStipple(1,0xFF00);//dash
break;
case 5:glLineStipple(1,0xE4E4);//dot dash
break;
case 6: glLineStipple(1,0xFFFF);//SOLID
break;}
glLineWidth(width);
//draw line
glBegin(GL_LINES);
glColor3f(red,blue,green);
glVertex2i(x1,y1);
glVertex2i(x2,y2);
glEnd();
glDisable(GL_LINE_STIPPLE);
glFlush();
}
void init (void)
{glClearColor(1.0,1.0,1.0,0);
}
//******************
void mouse (int botton ,int state ,int x , int y)
{
if( (botton==GLUT_LEFT_BOTTON)&&(state==GLUT_DOWN))
if( con==0)
{ x1=x;x2=x;y1=300-y;y2=300-y;con=con+1;}
else {x2=x;y2=300-y; con=con-1;}
glutPostRedisplay();}
//******************
int main (int argc , char **argv)
{ glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
//CREAT WINDOW
glutInitWindowSize(300,300);
glutInitWindowPosition(0,0);
glutCreateWindow(“LINE STIPPLE”);
int menucolor=glutCreateMenu(selectcolor);//submenu for color
glutAddMenuEntry(“RED”,1);
glutAddMenuEntry(“BLUE”,2);
glutAddMenuEntry(“GREEN”,3 );
int menustrippt=glutCreateMenu(selectionstipp);
glutAddMenuEntry(“DASH”,4);
glutAddMenuEntry(“DOT_DASH”,5);
glutAddMenuEntry(“SOLID”,6);
int menuwidth=glutCreateMenu(selectwidth);
glutAddMenuEntry(“WIDTH 1”,7);
glutAddMenuEntry(“WIDTH”,8);
glutAddMenuEntry(“WIDTH”,9);
glutCreateMenu(select);
glutAddSubMenu(“COLOR”,menucolor);
glutAddSubMenu(“pattren”,menustrippt);
glutAddSubMenu(“withness”,menuwidth);
glutAddMenuEntry(“QUIT”,0);
glutAttachMenu(GLUT_RIGHT_BOTTON);
glutMouseFunc(mouse);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;}
===============
my program when user want drae another line the first line earse
regards
MOON_GIRL
[This message has been edited by MOON-GIRL (edited 12-02-2002).]