#include <GL/glut.h> /* OpenGl utility toolkit */
#include <stdlib.h> /* fuer C-Library */
GLuint listName; /* Handle fuer Display-Liste */
void init (void) {
listName = glGenLists (1); /* trage Namen ein */
glNewList (listName, GL_COMPILE); /* erzeuge Display-Liste */
glColor3f (1.0, 0.0, 0.0); /* Farbe rot */
glBegin (GL_TRIANGLES); /* Beginn Dreiecks-Punkte */
glVertex2f (0.0, 0.0); /* Knoten links unten */
glVertex2f (1.0, 0.0); /* Knoten rechts unten */
glVertex2f (0.0, 1.0); /* Knoten links oben */
glEnd (); /* Ende der Dreiecksliste */
glTranslatef (1.5, 0.0, 0.0); /* Verschiebe nach rechts */
glEndList (); /* Ende der Display-Liste */
glShadeModel (GL_FLAT); /* verwende Flat-Shading */
}
void reshape(int w, int h) { /* Reshape-Routine */
GLfloat p = (GLfloat) w / (GLfloat) h; /* Fensterverhaeltnis */
glViewport(0, 0, w, h); /* setze Viewport */
glMatrixMode(GL_PROJECTION); glLoadIdentity(); /* ab jetzt Projektion */
if (p > 1 ) gluOrtho2D (0.0, 2.0*p, -0.5, 1.5); /* links,rechts, unten, oben */
else gluOrtho2D (0.0, 2.0, -0.5/p, 1.5/p); /* links,rechts, unten, oben */
glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* ab jetzt Modelview-Matrix */
}
void display(void) { /* Anzeige-Routine */
GLuint i; /* Integer-Variable */
glClear (GL_COLOR_BUFFER_BIT); /* reset Farb-Puffer */
for (i=0; i<10; i++) glCallList(listName); /* rufe Display-Liste auf */
glBegin (GL_LINES); /* Beginn Linien-Punkte */
glVertex2f (0.0,0.5); /* ein Knoten */
glVertex2f(15.0,0.5); /* noch ein Knoten */
glEnd (); /* Ende Linen-Punkte */
glFlush (); /* direkt ausgeben */
}
int main (int argc, char ** argv) { /* Hauptprogramm */
glutInit(&argc, argv); /* initialisiere GLUT */
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); /* single buffer, true color */
glutInitWindowSize(800, 100); /* initiale Fenstergroesse */
glutInitWindowPosition(112,84); /* initiale Fensterposition */
glutCreateWindow("list"); /* Fenster mit Aufschrift */
init(); /* rufe init auf */
glutDisplayFunc(display); /* registriere display */
glutReshapeFunc(reshape); /* registriere reshape */
glutMainLoop(); return 0; /* beginne Event-Schleife */
}