This is a simple OpenGL example program using the GLUT toolkit for window creation and event management.
This is the code used to create the above window:
//
// shape.c - OpenGL / GLUT example program
// Written by Ted Burke - 14-2-2012
//
// To compile: gcc -o shape shape.c -lglut
//
#include <GL/glut.h>
#include <stdio.h>
void renderScene(void);
int main(int argc, char** argv)
{
int w;
printf("OpenGL / GLUT example program\n");
glutInit(&argc, argv);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 300);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
w = glutCreateWindow("OpenGL / GLUT Example Program");
glutDisplayFunc(renderScene);
glutMainLoop();
return 0;
}
void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(-0.5, -0.5, 0.0);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(+0.5, -0.5, 0.0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(-0.5, +0.5, 0.0);
glEnd();
glutSwapBuffers();
}
To compile this program with gcc, I used the following command:
gcc -o shape shape.c -lglut
I installed GLUT and OpenGL on my CrunchBang Linux netbook using the following command:
sudo apt-get install libglut3-dev

