Hi,
This is my first post in this community .I am trying to develop a mini opengl project for my college.I now encounter a problem of dragging a square when the left button of my mouse is pressed.Can anyone please help me with this .The following snippet of code has been written by me but doesn’t work as expected
void mousemotion(int x,int y)
{
if(flag==1)
{
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(x,y);
glVertex2f(x-0.5,y);
glVertex2f(x-0.5,y-0.5);
glVertex2f(x,y-0.5);
glEnd();
glFlush();
glutPostRedisplay();
}
}
void mymousehandler(int btn,int state,int x,int y)
{
if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
flag=1;
else
flag=0;
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0,0.0,0.0,0.0);
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(0.0,0.0);
glVertex2f(0.5,0.0);
glVertex2f(0.5,0.5);
glVertex2f(0.0,0.5);
glEnd();
glFlush();
}
Expecting a favorable reply
Regards