Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glut.h>
- #include <iostream>
- using namespace std;
- float winWid,winHeight;
- float rx=0,ry=0,r=1,g=1,b=1;
- float rotAngle =5;
- void display( void )
- {
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glColor3f(r,g,b);
- glRectf(rx,ry,50+rx,50+ry);
- glutSwapBuffers();
- }
- void motion(int x, int y)
- {
- rx=x;
- ry=winHeight-y;
- if(rx<300 && ry<200)
- {
- r=1;
- g=0;
- b=0;
- }
- if(rx>300 && ry>200)
- {
- r=0;
- g=1;
- b=1;
- }
- if(rx<300 && ry>200)
- {
- r=0;
- g=0;
- b=1;
- }
- if(rx>300 && ry<200)
- {
- r=1;
- g=0;
- b=1;
- }
- }
- void passivemotion(int x, int y)
- {
- rx=x;
- ry=winHeight-y;
- if(rx<300 && ry<200)
- {
- r=1;
- g=0;
- b=0;
- }
- if(rx>300 && ry>200)
- {
- r=0;
- g=1;
- b=1;
- }
- if(rx<300 && ry>200)
- {
- r=0;
- g=0;
- b=1;
- }
- if(rx>300 && ry<200)
- {
- r=1;
- g=0;
- b=1;
- }
- }
- void mousebutton(int button, int state, int x, int y)
- {
- if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
- {
- rx = x; ry = winHeight - y;
- }
- }
- int main(int argc, char *argv[])
- {
- winWid = 600.0;
- winHeight = 400.0;
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
- glutCreateWindow("Basic example");
- glutPositionWindow(200,200);
- glutReshapeWindow(winWid,winHeight);
- glutReshapeWindow(600,400);
- glClearColor(0.0,0.0,0.0,1.0);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0.0,winWid,0.0,winHeight, -100.0, 100.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glutDisplayFunc(display);
- glutIdleFunc(display);
- //glutMotionFunc(motion);
- //glutPassiveMotionFunc(passivemotion);
- //glutMouseFunc( mousebutton);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement