Skip to main content

code::blocks and OpenGL

Last time I used OpenGL was in a University project. By that time, I had to connect using telnet (and xterm, I think, but I barely remember) to a SUN sparc station running probably Solaris. I remember it was really exciting being able to view those simple 3D models on the screen and running in real time!

Lately I was reading some DirectX 10 and sudendly I was wondering what happened to OpenGL? Did It die? Is it there any develoment going on? Surprisingly I found that these libraries are alive and well. It's been used in several platforms including the iPhone so ... you can imagine the future of a technology installed in more than 5 million of devices! (Also, this library is used in both PS 3 and wii (add some other million).

After this brief introduction I decided to build a program under linux, c++ and OpenGL. The IDE of choice Code::Blocks. I used this IDE to build an embedded application so I recommend it. It runs really well with no complains.

One cool thing I found is that Code::Blocks already includes templates to create OpenGL applications using GLUT or using OpenGL with direct access to the X windows libraries.

Now, let's go to the practice. Select File->New->Project. This will pop up the following screen:


OpenGL Library with X-windows access:

OpenGL project is straightforward. You only have to follow the wizard. The project will be ready and you will be able to run it immediately:


As you can see, the wizard is clear and people from code::blocks really did a great job! Below, you can see the simple program running. After finishing the wizard, I just hit F9, and Voila!


OpenGL Library using GLUT:

In order yo have GLUT libraries (and of course, the code::blocks template) you will have to install the following packages:

Installing libxxf86vm from synaptics package Manager


freeglut3 being selected in Synaptics Manager

Please note I have installed the freeglut version of GLUT. You can see in the screen above the following message: "This package has been replaced by freeglut3'. Hmm, It looks like there are some restrictions in the GLUT license. (and glut seem to be out of date).

With these packages installed you can run code::blocks and go through the GLUT wizard.

First step is to let code::blocks where is GLUT installed. Usually all installed libraries in Linux are located in /usr.


Follow the wizard to create your project. Finish it and hit F9. Again, you will be able to see this cool screen: solid and wireframe models.


And .. that's all by now.

ps. I also suggest using SDL (Simple DirectMedia Layer). This library controls also Audio and Keyboard. You should install the following libraries in order to have SDL applications working:

Comments

Anonymous said…
Believe it or not, I was stuck trying to figure out the correct GLUT path. Thanks for this post, you saved me Fabián :)
Fabian Mejia said…
I know, these things are usually forgotten as you do those kind of things (like the project setup) only once in a while.
xbass540 said…
hi,
i'm a new linux user

i did as you say and i get the message sh:..../debug/project name permission denied

i also cant't find the libxxf86vm library into my synaptics manager. can i download it from somewhere else?
Fabian Mejia said…
During which process did you get the error? Which code::blocks version are you using?

regarding the libxxf86vm library, it should be libxxf86vm1. It can be downloaded from this alternate location:

https://launchpad.net/ubuntu/+source/libxxf86vm/1:1.0.1-2
Anonymous said…
Thanks Fabian, this post kinda saved me :) Regards, Ole from Norway
Jonas Thomas said…
Thank you so much for posting instructions on how to setup code::blocks for glut.
I was playing around with it before I found you site and thought it was more complicated than it was.
JT
Unknown said…
Great!! Thank you so much!!
NN said…
I know it's an old post, but I'm kind of desperate. I got to the point when I have no compiling errors, all headers are where they should be, but still I got the same error as xbass540, when I run the GLUT demo "sh: project/bin/Debug/GLUT: Permission denied. Process returned 126 (0x7E)". I use 32-bit Code::Blocks 10.05 on Ubuntu 10.10 with X Server 1.9.0. I've installed 1:1.1.0-2 version of libxxf86vm*. If it's important - I have 3.3.0 NVIDIA 260.19.12 version of OpenGL with GeForce 9300M GS/PCI/SSE2 renderer. I don't know what this "permission denied" is about. In case it is about rwx permissions than all are 000 for the GLUT file and I'm running CodeBlocks as root, to be on the safe side. Any ideas?
I try use default example but I got this error : /usr/include/GL/gl.h|97|fatal error: GL/mesa_wgl.h: No such file or directory|
I use F14 and i install this :

# yum install mesa-libGL-devel.i686
# yum install mesa-libGLw-devel.i686
# yum install mesa-libGL.i686
# yum install mesa-libGLU.i686
# yum install mesa-libGLw.i686
# yum install mesa-libOSMesa.i686

I don't see mesa_wgl.h
Any idea ?
Thank you .
Nithin said…
Thanx a lot! had a lot of trouble setting OpenGL bfore stumbling on ur blog!
Mr. Akash said…
It says Segmentation Fault in runtime
Anonymous said…
Thank you! :)