#include <GL/glut.h> /* Header fuer OpenGl utility toolkit */ #include <stdlib.h> /* Header fuer C-Library */ GLfloat g=0.0; /* globale Variable */ void init(void) { /* Initialisierung */ glClearColor(0.5, 0.5, 0.5, 0.0); /* setze Grau als Hintergrundfarbe */ glMatrixMode(GL_PROJECTION); /* betrifft Projektionsmatrix */ glLoadIdentity(); /* beginne mit Einheitsmatrix */ gluOrtho2D(0.0, 1.5, 0.0, 1.0); /* Orthogonalprojektions-Clip-Ebenen */ } /* in 2D: left,right, bottom, top */ void display(void){ /* Prozedur zum Zeichnen */ glClear(GL_COLOR_BUFFER_BIT); /* alle Pixel zurecksetzen */ glColor3f(1.0,g,0.0); /* Farbe gemaess RGB-Tripel */ glBegin(GL_TRIANGLES); /* Beginn eines Dreiecks */ glVertex2f(0.25, 0.25); /* links unten */ glVertex2f(0.75, 0.25); /* rechts unten */ glVertex2f(0.25, 0.75); /* links oben */ glEnd(); /* Ende des Dreiecks */ glFlush(); /* direkt ausgeben */ } void mouse(int button,int state,int x,int y){/* Maus-Klick bei Koordinate x,y */ switch(button) { /* analysiere den Mausevent */ case GLUT_LEFT_BUTTON: /* falls linke Taste gedrueckt */ if (state==GLUT_DOWN) g=1.0; /* setzte Gruenanteil auf 1 */ break; case GLUT_RIGHT_BUTTON: /* falls rechte Taste gedrueckt */ if (state==GLUT_DOWN) g=0.0; /* setzte Gruenanteil auf 0 */ break; } glutPostRedisplay(); /* durchlaufe display erneut */ } int main (int argc, char ** argv) { /* Hauptprogramm */ glutInit(&argc, argv); /* initialisiere GLUT */ glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); /* single buffer, true color */ glutInitWindowSize(800, 600); /* initiale Fenstergroesse */ glutInitWindowPosition(0,0); /* initiale Fensterposition */ glutCreateWindow("click"); /* Fenster mit Aufschrift */ init(); /* rufe init auf */ glutDisplayFunc(display); /* registriere display */ glutMouseFunc(mouse); /* registriere mouse */ glutMainLoop(); /* beginne Event-Schleife */ return 0; /* ISO C verlangt Rueckgabe */ }