/* * Simple OpenGL test: the famous triangle. * * Compile as: * * gcc simple-opengl-test.c -o simple-opengl-test -Wall -ggdb -O0 -pthread -lm -lglut `pkg-config --cflags gl glu` `pkg-config --libs gl glu` * * Author: Alejandro PiƱeiro Iglesias * */ #include #define GL_GLEXT_PROTOTYPES #include #include #include #include int width; int height; int window; int fullscreen; void on_key_press (unsigned char key, int x, int y) { glutDestroyWindow (window); exit (0); } void scene_render (void) { glBegin(GL_TRIANGLES); glColor3f(1.0f,0.0f,0.0f); glVertex3f(0, 0, -5); glColor3f(0.0f,1.0f,0.0f); glVertex3f(width, 0, -5); glColor3f(0.0f,0.0f,1.0f); glVertex3f(width/2, height, -5); glEnd(); glutSwapBuffers(); glutPostRedisplay(); } static void setup () { glClearColor (0.0, 0.0, 0.0, 1.0); glClear (GL_COLOR_BUFFER_BIT); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glViewport (0, 0, width, height); glOrtho (0, width, 0, height, -100, 100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc, char *argv[]) { if (argc < 4) { printf ("Usage: ./simple-opengl-test width height full-screen\n"); exit (0); } width = atoi (argv[1]); height = atoi (argv[2]); fullscreen = atoi (argv[3]); glutInit (&argc, argv); glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE); glutInitWindowSize (width, height); window = glutCreateWindow (argv[0]); setup(); glutDisplayFunc (scene_render); glutKeyboardFunc (on_key_press); printf ("GL_VERSION = %s\n", (char *) glGetString (GL_VERSION)); if (fullscreen) glutFullScreen(); glutMainLoop(); return 0; }