1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>
#include <glut.h>
GLsizei winWidth = 400, winHeight = 400;
float red = 1.0f,blue = 1.0f,green = 1.0f;
void init(void)
{
glClearColor (0.0, 0.0, 1.0, 0.0);
glMatrixMode (GL_PROJECTION);
gluOrtho2D (0.0, winWidth, 0.0, winHeight);
}
void displayFcn (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 0.0, 0.0);
glBegin (GL_POLYGON);
glVertex2i (50,100);
glVertex2i (50,50);
glVertex2i (200,50);
glVertex2i (200,100);
glEnd ();
glFlush ( );
}
void processNormalKeys(unsigned char key, int x, int y) {
if (key == 27)
exit(0);
}
void processSpecialKeys(int key,int x,int y)
{
switch (key)
{
case GLUT_KEY_F1:
red = 1.0;
green = 0.0;
blue = 0.0;
break;
case GLUT_KEY_F2:
red = 0.0;
green = 1.0;
blue = 0.0;
break;
case GLUT_KEY_F3:
red = 0.0;
green = 0.0;
blue = 1.0;
break;
default:
break;
}
}
void main (int argc, char** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition (350, 100);
glutInitWindowSize (winWidth, winHeight);
glutCreateWindow ("Rectangle Program");
glutKeyboardFunc (processNormalKeys);
glutSpecialFunc (processSpecialKeys);
init();
glutDisplayFunc (displayFcn);
glutMainLoop ( );
}
| |