검색결과 리스트
글
mouse.cpp
#include<gl/glut.h>
GLint topLeftX, topLeftY, bottomRightX, bottomRightY;
void MyDisplay()
{
glViewport(0,0,300,300);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.5,0.5,0.5);
glBegin(GL_POLYGON);
glVertex3f(topLeftX/300.0,(300-topLeftY)/300.0,0.0);
glVertex3f(topLeftX/300.0,(300-bottomRightY)/300.0,0.0);
glVertex3f(bottomRightX/300.0,(300-bottomRightY)/300.0,0.0);
glVertex3f(bottomRightX/300.0,(300-topLeftY)/300.0,0.0);
glEnd();
glFlush();
}
void MyMouseClick(GLint button, GLint state, GLint x, GLint y)
{
if(button==GLUT_LEFT_BUTTON && state ==GLUT_DOWN)
{
topLeftX=x;
topLeftY=y;
}
}
void MyMouseMove(GLint x, GLint y)
{
bottomRightX=x;
bottomRightY=y;
glutPostRedisplay();
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(300,300);
glutInitWindowPosition(0,0);
glutCreateWindow("Mouse Test");
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glClearColor(1.0,1.0,1.0,1.0);
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
glutDisplayFunc(MyDisplay);
glutMouseFunc(MyMouseClick);
glutMotionFunc(MyMouseMove);
glutMainLoop();
}