Simple OpenGL Application for Beginners

A friend of mine recently complained that starting OpenGL on Linux is too confusing. In helping him out, I figured out that like most beginners, he couldn’t figure out how to display anything on the screen without 200 lines of confusing code from some tutorial site he found. Furthermore, probably 3/4 these tutorial sites are targeted towards Windows users, so getting it running on Linux is even more confusing!

Learning how to draw an OpenGL triangle on Linux shouldn’t be hard. Most beginners just want a basic scratchpad they can tinker with, not an expansive explanation of what’s going on, and what window manager is doing what, etc. They just want a function that they can plug the beginning OpenGL concepts into.

All you want to see if just starting out is something like this:
So, I whipped up some simple code to do so! Here it is! simple_gl20_triangle.tar.gz


#include "stdio.h"
#include "GL/glut.h"

void render()
		glColor3f(  1.0, 0.0, 0.0);
		glVertex3f(-0.5, 0.0, 0.0);

		glColor3f(  0.0, 0.0, 1.0);
		glVertex3f( 0.0, 0.5, 0.0);

		glColor3f(  0.0, 1.0, 0.0);
		glVertex3f( 0.5, 0.0, 0.0);



int main(int argc, char **argv)
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);


	return 0;

Use the makefile included in the tar package, or compile and run like this:

gcc -o gl gl.c -lglut -lGL -lGLU -lX11 -lXmu -lXi -lm

Just put whatever commands you want to tinker with in the render() function. I included a makefile to compile. Make sure you have the libglut3-dev and libgl1-mesa-dev packages installed.

Now, there are no animations, and no responses to keyboard or mouse input. (This is possible with glut, but not implemented here). But, this chunk of code should be very useful for trying out just the basics of OpenGL with a linux client for beginners on Linux!

This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Simple OpenGL Application for Beginners

  1. Pingback: Opengl

Leave a Reply

Your email address will not be published. Required fields are marked *