#include <GL/glut.h> /* OpenGl Utiltiy Toolkit */ #include <stdlib.h> /* C-library */ void init(void) { GLfloat mat_diffuse[] = { 1.0, 0.3, 0.3, 1.0 }; /* diffuse Farbe */ GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; /* spekulare Farbe */ GLfloat mat_shininess[] = { 50.0 }; /* Reflexionskoeffizient */ GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; /* Lichtquellenposition */ glClearColor (0.0, 0.0, 0.0, 0.0); /* Hintergrundfarbe */ glShadeModel (GL_SMOOTH); /* smooth shading */ glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); /* diffuse Farbzuweisung */ glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); /* spekulare Farbzuweisung*/ glMaterialfv(GL_FRONT, GL_SHININESS,mat_shininess); /* Reflexionszuweisung */ glLightfv (GL_LIGHT0,GL_POSITION, light_position); /* Lichtpositionszuweisung*/ glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); /* Beleuchtung aktivieren */ glEnable(GL_DEPTH_TEST); /* Tiefentest aktiveren */ glMatrixMode (GL_PROJECTION); /* ab jetzt Projektion */ glLoadIdentity(); /* lade Einheitsmatrix */ glOrtho(-2.0,2.0,-1.5,1.5,-10.0,10.0); /* links,rechts,unten,oben*/ glMatrixMode(GL_MODELVIEW); /* ab jetzt Modelview */ glLoadIdentity(); /* lade Einheitsmatrix */ glRotatef( 20.0, 1.0, 0.0, 0.0); /* 20 Grad um x-Achse */ } void display(void) { glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); /* reset Buffer */ glRotatef((GLfloat) 1, 0.0, 1.0, 0.2); /* 1 Grad um Drehachse */ glutSolidTeapot(1); /* zeichne Teapot */ glutSwapBuffers(); /* wechsele Puffer */ } int main(int argc, char** argv) { glutInit(&argc, argv); /* initialisiere GLUT */ glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH); /* Double buffer, ... */ glutInitWindowSize (800, 600); /* init. Fenstergroesse */ glutInitWindowPosition (0,0); /* init. Fensterposition */ glutCreateWindow ("teapot-rotate"); /* Fenster mit Aufschrift */ init (); /* Initialisierung */ glutDisplayFunc(display); /* registriere display */ glutIdleFunc(display); /* bei Leerlauf: display */ glutMainLoop(); /* starte Hauptschleife */ return(0); }