#include<GL/gl.h>
#include<GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT );
glBegin(GL_TRIANGLES);
glVertex2f(0.0,0.4);
glVertex2f(-0.4,-0.4);
glVertex2f(0.4,-0.4);
glEnd();
glFlush();
}
void processMouse(int button,int state,int x,int y)
{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
{
glColor3f(1.0,0.0,0.0);
}
else if(button==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
{
glColor3f(0.0,1.0,0.0);
}
else
{
glColor3f(1.0,1.0,0.0);
}
glutPostRedisplay();
}
void processActiveMotionMouse(int x,int y)
{
if(x<300)
{
glColor3f(1.0,0.0,0.0);
}
else if(x>300)
{
glColor3f(0.0,1.0,0.0);
}
else
{
glColor3f(1.0,1.0,0.0);
}
glutPostRedisplay();
}
void processPassiveMotionMouse(int x,int y)
{
if(x<300)
{
glColor3f(1.0,0.0,0.0);
}
else if(x>300)
{
glColor3f(0.0,1.0,0.0);
}
else
{
glColor3f(1.0,1.0,0.0);
}
glutPostRedisplay();
}
void processEntryMouse(int state)
{
if(state==GLUT_LEFT)
{
glColor3f(1.0,0.0,0.0);
}
else
{
glColor3f(1.0,1.0,0.0);
}
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize (500, 500);
glutInitWindowPosition (150, 150);
glutCreateWindow ("Mouse Events");
glutDisplayFunc(display);
glutMouseFunc(processMouse);
//glutMotionFunc(processActiveMotionMouse);
//glutPassiveMotionFunc(processPassiveMotionMouse);
//glutEntryFunc(processEntryMouse);
glutMainLoop();
return 0;
}
OUTPUT

#include<GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT );
glBegin(GL_TRIANGLES);
glVertex2f(0.0,0.4);
glVertex2f(-0.4,-0.4);
glVertex2f(0.4,-0.4);
glEnd();
glFlush();
}
void processMouse(int button,int state,int x,int y)
{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
{
glColor3f(1.0,0.0,0.0);
}
else if(button==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
{
glColor3f(0.0,1.0,0.0);
}
else
{
glColor3f(1.0,1.0,0.0);
}
glutPostRedisplay();
}
void processActiveMotionMouse(int x,int y)
{
if(x<300)
{
glColor3f(1.0,0.0,0.0);
}
else if(x>300)
{
glColor3f(0.0,1.0,0.0);
}
else
{
glColor3f(1.0,1.0,0.0);
}
glutPostRedisplay();
}
void processPassiveMotionMouse(int x,int y)
{
if(x<300)
{
glColor3f(1.0,0.0,0.0);
}
else if(x>300)
{
glColor3f(0.0,1.0,0.0);
}
else
{
glColor3f(1.0,1.0,0.0);
}
glutPostRedisplay();
}
void processEntryMouse(int state)
{
if(state==GLUT_LEFT)
{
glColor3f(1.0,0.0,0.0);
}
else
{
glColor3f(1.0,1.0,0.0);
}
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize (500, 500);
glutInitWindowPosition (150, 150);
glutCreateWindow ("Mouse Events");
glutDisplayFunc(display);
glutMouseFunc(processMouse);
//glutMotionFunc(processActiveMotionMouse);
//glutPassiveMotionFunc(processPassiveMotionMouse);
//glutEntryFunc(processEntryMouse);
glutMainLoop();
return 0;
}
OUTPUT
No comments:
Post a Comment