#include <GL/glut.h> /* OpenGl Utiltiy Toolkit */
#include <stdlib.h> /* C-library */
int g; /* Variable fuer Gradzahl */
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 */
}
void display(void) {
glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); /* reset Buffer */
glLoadIdentity(); /* lade Einheitsmatrix */
glRotatef((GLfloat) g, 0.0, 1.0, 0.0); /* g grad Grad um y-Achse */
glRotatef( 20.0, 1.0, 0.0, 0.0); /* 20 Grad um x-Achse */
glutSolidTeapot(1); /* zeichne Teapot */
glutSwapBuffers(); /* wechsele Puffer */
}
void spinDisplay(void) {
g = (g + 1) % 360; /* Gradzahl um 1 erhoehen */
glutPostRedisplay(); /* display erneut aufrufen*/
}
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 (112, 84); /* init. Fensterposition */
glutCreateWindow ("teapot-rotate"); /* Fenster mit Aufschrift */
init (); /* Initialisierung */
glutDisplayFunc(display); /* registriere display */
glutIdleFunc(spinDisplay); /* registriere spinDisplay*/
glutMainLoop(); /* starte Hauptschleife */
return(0);
}