OpenGL with wxDev-C++

Dr. Ross Ashman

Hi all. This a small tutorial on getting started with OpenGL in wxDev-C++. It's very easy to do with such a fabulous RAD IDE. The only hard part is writing the class that looks after the GL stuff. To save time I have included this class to make things easier and so you can see whats going on.

Basically this tutorial will show you how to display OpenGL images in a wxPanel and how to move those images with the mouse ie up down, left right and in and out. So lest get started!

First you create a new Project (let's call it "openGLProject"), which if you've read the other tutorials is easy enough. We want a wxWidgets Frame project as shown

Once that's done you will see the following screen:

Now add a panel (Components->Containers->wxPanel)

At this point we have created a simple form with a panel. Pretty easy! Now we are ready to do some OpenGL stuff. First we need to create a class to looks after the OpenGL stuff. Well I've already done that and have included the files in the zipped package at the bottom of this tutorial. So all we need to do is add it to the project. Go to Project->Add to Project and select the MyGlCanvas.cpp file. Then add the MyGLCanvas.h file.

The class has two primary functions, to draw the image and respond to events, primarily mouse events.

Init() setups the GL environment

Draw() calls the paint function

Paint() basically does all the work and puts the image on the screen

NB: Why the Draw() function? Well, Paint() requires a paramter, an address to a wxDC object. I wanted to have the flexibility of triggering Paint() without having a wxDC to pass, hence Draw(). This function can be called by anything to invoke a Paint().

We will use the second panel as a space in which to display our GL images. To do that we need to add a little something to our project form file.

Now add the following line to the openGLProjectFrm.cpp constructor (highlighted)



pGLCanvas = new MyGLCanvas(WxPanel2, ID_WXPANEL2, wxPoint(0,0), wxSize(377,324));

This basically tells the GLCanvas that its parent is the panel.

In the header file openGLProjectFrm.h add the lines:

#include "MyGLCanvas.h"

and

MyGLCanvas *pGLCanvas;

Now go to Project->Project Options->Parameters. Add -lglu32 to the linker list to link to the glu32 library. It will should now appear in the linker list as shown.



Here's the full list of linker parameters:

-mwindows
-l$(WXLIBNAME)
-l$(WXLIBNAME)_gl
-lwxtiff
-lwxjpeg
-lwxpng
-lwxzlib
-lwxregexu
-lwxexpat
-lkernel32
-luser32
-lgdi32
-lcomdlg32
-lwinspool
-lwinmm
-lshell32
-lcomctl32
-lole32
-loleaut32
-luuid
-lrpcrt4
-ladvapi32
-lwsock32
-lodbc32
-lopengl32
-lglu32

Thats it! Now compile and run the program. Whoala!! You now have a cube in a panel. If you left click on the cube and drag the cube will follow. If you right click and move the mouse in and out the cube will zoom in and out.



I hope this has been of some help to people wanting to use OpenGL in wxDev-C++.

Click here to download the Project Source Code.