Computergraphik_Hopp/Code/helloWorld.c

53 lines
1.7 KiB
C
Raw Normal View History

2018-10-17 12:50:35 +02:00
#include <GL/glut.h>
#include <string.h>
2018-10-24 15:03:05 +02:00
static int width = 640;
static int height = 480;
2018-10-17 12:50:35 +02:00
void init(int argc, char** argv)
{
glutInit(&argc, argv); // Initialisierung der GLUT Bibliothek
glutInitDisplayMode(GLUT_SINGLE); // Initialisierung des Single Buffer Modes
glutInitWindowSize(width, height); // Fenstergröße in Pixel (Breite, Hoehe)
glutInitWindowPosition(
100, 100); // Fensterposition in Pixel, ausgehend vom Ursprung des Window Systems
glViewport(0, 0, width, height);
glutCreateWindow("Hello world"); // Erstellen des Fensters
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, width, 0, height);
glMatrixMode(GL_MODELVIEW);
}
void display(void)
{
2018-10-17 15:08:44 +02:00
char* myText = "Hello World!";
2018-10-24 15:03:05 +02:00
unsigned long j;
2018-10-17 12:50:35 +02:00
2018-10-17 15:08:44 +02:00
glClear(GL_COLOR_BUFFER_BIT);
2018-10-17 12:50:35 +02:00
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_POLYGON);
glVertex3f((width / 2) - (width / 4), (height / 2) - (height / 4), 0.0);
glVertex3f((width / 2) + (width / 4), (height / 2) - (height / 4), 0.0);
glVertex3f((width / 2) + (width / 4), (height / 2) + (height / 4), 0.0);
glVertex3f((width / 2) - (width / 4), (height / 2) + (height / 4), 0.0);
glEnd();
glColor3f(1.0, 1.0, 1.0);
glRasterPos2i((width / 2) - (width / 4) + 10, (height / 2) - (height / 4) + 10);
2018-10-24 15:03:05 +02:00
for (j = 0ul; j < strlen(myText); j++) {
2018-10-17 12:50:35 +02:00
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, myText[j]);
}
glFlush();
}
int main(int argc, char** argv)
{
init(argc, argv);
glutDisplayFunc(display); // Callback-Funktion für das Fenster
glutMainLoop(); // Abgabe der Kontrolle an GLUT-Bibliothek
return 0;
}