mario::konrad
programming / C++ / sailing / nerd stuff
wxWidgets Tutorial 2: Basic OpenGL Application
© 2005 / Mario Konrad

This tutorial shows how to build a basic application with OpenGL graphics.

The most important part of this tutorial is the class wxGLCanvas and it derivative, respectively. The OpenGL specific part of three parts:

Initialization of OpenGL

Simple initialization, without eyecandy (well, almost).

glClearColor(0.8, 0.8, 0.8, 0.0);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);

Preserve Aspect Ratio while Resize

FOV (field of view) is constant 45°, while the aspect ratio is calculated from the size of the visible area.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (double)width / (double)height, 0.1, 100.0);
glMatrixMode(GL_MODELVIEW);

Render the simple Scene

Business as usual: clearing the buffers, translate and rotate to the viewers position and draw the objects.

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0, 0.0, -15.0);
glRotatef(30.0, 1.0, 0.0, 0.0);
glColor4f(0.3, 0.3, 0.3, 1.0);
glutWireTeapot(3.0);

Download

Building the executable

Linux:

$ g++ -c gl0.cpp `wx-config --cxxflags`
$ g++ -o gl0 gl0.o `wx-config --libs --gl-libs` -lglut

Windows/Cygwin:

$ g++ -c gl0.cpp `wx-config --cxxflags`
$ g++ -o gl0 gl0.o -lglut32 `wx-config --libs --gl-libs`

Using the makefile:

$ make gl0

Running the Demo

$ ./gl0