PDA

View Full Version : help!!mouse actions



09-30-2004, 11:24 AM
my code is not chnaging the color of the line drawn

# include<GL/glut.h>

void init(void)
{

glClearColor(1.0,1.0,1.0,1.0);
gluOrtho2D(0.0,500.0,0.0,500.0);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glColor3f(1.0,0.0,0.0);
glPointSize(5.0);

glFlush();

}

/*void mouse(int button,int state,int x, int y)
{
int screenheight=300;
if(button==GLUT_LEFT_BUTTON&&state==GLUT_DOWN)
{

int mouseX =x ; //grab the mouse position
int mouseY= screenheight - y ; //flip y position

glBegin(GL_POINTS);
glVertex2i(mouseX,mouseY);
glEnd();
glFlush();
}}*/



void menu(int ID)
{
if(ID==1)

{

glColor3f(0.0,1.0,0.0);
}
if (ID==2)
{
glPointSize(1.0);

}

if(ID==3)
{
exit(1);
}}

void blotPoint(GLint x,GLint y)
{
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
}
void motion(GLint x,GLint y)
{
blotPoint(x,y);
//glutPostRedisplay();
glFlush();

}

int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitWindowSize(400,300);
glutInitWindowPosition(50,100);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutCreateWindow("interaction");
init();
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutCreateMenu(menu);
glutAddMenuEntry("change color",1);
glutAddMenuEntry("thickness",2);
glutAddMenuEntry("quit",3);
glutAttachMenu(GLUT_RIGHT_BUTTON);
//glutPostRedisplay();
glutMainLoop();

return 0;
}

09-30-2004, 11:50 AM
Because everytime display() is called you set it back to
glColor3f(1.0,0.0,0.0);The same is true for the pointsize.