| 1 | |
|---|
| 2 | |
|---|
| 3 | #include <stdio.h> |
|---|
| 4 | #include <stdlib.h> |
|---|
| 5 | |
|---|
| 6 | #include <GL/glut.h> |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | static GLfloat spin = 0.0; |
|---|
| 10 | |
|---|
| 11 | void init( void ) { |
|---|
| 12 | |
|---|
| 13 | glClearColor( 0.0, 1.0, 0.0, 0.0 ); |
|---|
| 14 | glShadeModel( GL_FLAT ); |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | void display( void ) { |
|---|
| 19 | |
|---|
| 20 | glClear( GL_COLOR_BUFFER_BIT ); |
|---|
| 21 | glPushMatrix(); |
|---|
| 22 | glRotatef( spin, 0.0, 0.0, 1.0 ); |
|---|
| 23 | glColor3f( 1.0, 1.0, 1.0 ); |
|---|
| 24 | glRectf( -25.0, -25.0, 25.0, 25.0 ); |
|---|
| 25 | glColor3f(1.0, 0.0, 0.0); |
|---|
| 26 | glRectf(-5.0, -5.0, 5.0, 5.0); |
|---|
| 27 | |
|---|
| 28 | glPointSize(4.0); |
|---|
| 29 | glColor3f(0.0, 0.0, 1.0); |
|---|
| 30 | glBegin(GL_POINTS); |
|---|
| 31 | glVertex2f(6.0, 2.0); |
|---|
| 32 | glVertex2f(15.0, 14.0); |
|---|
| 33 | glVertex2f(12.0, 20.0); |
|---|
| 34 | glVertex2f(-3.0, 17.0); |
|---|
| 35 | glEnd(); |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | glPopMatrix(); |
|---|
| 39 | glutSwapBuffers(); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | void spinDisplay( void ) { |
|---|
| 44 | |
|---|
| 45 | spin = spin + 2.0; |
|---|
| 46 | if( spin > 360.0 ) |
|---|
| 47 | spin = spin - 360.0; |
|---|
| 48 | glutPostRedisplay(); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | void reshape(int w, int h) { |
|---|
| 53 | |
|---|
| 54 | glViewport( 0, 0, (GLsizei) w, (GLsizei) h); |
|---|
| 55 | glMatrixMode(GL_PROJECTION); |
|---|
| 56 | glLoadIdentity(); |
|---|
| 57 | glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0 ); |
|---|
| 58 | glMatrixMode(GL_MODELVIEW); |
|---|
| 59 | glLoadIdentity(); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | void mouse( int button, int state, int x, int y ) { |
|---|
| 64 | |
|---|
| 65 | switch( button ) { |
|---|
| 66 | case GLUT_LEFT_BUTTON: |
|---|
| 67 | if (state == GLUT_DOWN) |
|---|
| 68 | glutIdleFunc(spinDisplay); |
|---|
| 69 | break; |
|---|
| 70 | case GLUT_RIGHT_BUTTON: |
|---|
| 71 | if (state == GLUT_DOWN) |
|---|
| 72 | glutIdleFunc(NULL); |
|---|
| 73 | break; |
|---|
| 74 | default: |
|---|
| 75 | break; |
|---|
| 76 | } |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | int main( int argc, char** argv ) { |
|---|
| 82 | |
|---|
| 83 | glutInit(&argc, argv); |
|---|
| 84 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); |
|---|
| 85 | glutInitWindowSize(250, 250); |
|---|
| 86 | glutInitWindowPosition(100, 100); |
|---|
| 87 | glutCreateWindow("rock-it"); |
|---|
| 88 | init(); |
|---|
| 89 | glutDisplayFunc(display); |
|---|
| 90 | glutReshapeFunc(reshape); |
|---|
| 91 | glutMouseFunc(mouse); |
|---|
| 92 | glutMainLoop(); |
|---|
| 93 | |
|---|
| 94 | return 0; |
|---|
| 95 | } |
|---|