2009
01.06

Hey ya’ll.

Before i start on my little blog adventure here, i’d first like to say, this probably isn’t the most efficient way, or the best way to achieve a simple game using SDL and OpenGL. My good friend over at TheNewHorizon is a freak for making sure everything is as good as can be possible and most optimised. I am too, but not when i’m learning :) Not that it’s a bad way to learn of course.

First off, the boring bit. Let’s setup our environment so we can compile against SDL and OpenGL, of course using C++.

Now, i use Ubuntu (much to my friend mentioned aboves disgust…) 8.10 Intrepid Ibex as my OS, and have done for a few months now, had no need what-so-ever to boot into windows. It’s great :)

So, this will be mainly aimed at people using Ubuntu, over at TheNewHorizon there is a blog post about setting up Visual Studio Express 2008 for use with SDL and OpenGL.

Let’s begin.

Fire up a console, we need to install packages so we can compile some c++ code. (I am starting a fresh here with a brand new virtual machine, feel free to jump to the relevant step for you…)

Run the following command (will require an internet connection)

sudo apt-get install g++

Once this has completed, we now have a C++ Compiler on your system.

So we can compile the SDL/OpenGL application, right? Not quite yet, we need to install the libraries, and their development headers.

sudo apt-get install libsdl1.2-dev libsdl-ttf2.0-dev libglew1.5-dev;

What was that?

libsdl1.2-dev are the development headers required to compile against SDL v1.2.
libsdl-ttf2.0-dev are the development headers required to use TTF Fonts inside of SDL.
libglew1.5-dev are the development headers required to compile against OpenGL.

Once these are all installed (should run through fine, comment with your issues!) we are able to compile our Pong game. Of course, you’re not able to, but thats in another blog post coming next. This was just to setup your compiler ready for SDL and OpenGL.

So, download the attached zip file, extract it to a folder of your choice, then in your console navigate to the Pong folder. It should look just like this when you run an ‘ls’.

dean@dean-desktop:~/Documents/Eclipse Projects/CPP/Blog/Step 1$ ls
Makefile  src

Now just run this command…

make

And it should spit out a load of output like this…

g++ -O2 -g -Wall -fmessage-length=0   -c -o src/main.o src/main.cpp
g++ -o Pong	 src/main.o -lSDL -lGL -lSDL_ttf

Congratulations, you just compiled your first application that is linked in with SDL, OpenGL and SDL_TTF. Run it by typing in

./Pong

Now, for the IDE. I personally use the Eclipse CC++ IDE, straight from the Eclipse website. It’s around 68mb, excluding the Java Runtime you will need to install. You can use anything that can edit a text file. Vim is very nice, i just prefer the IDE Feel.

In the next blog post, we will be initializing a simple window, and clearing it a specific colour!

No Comment.

Add Your Comment

Spiked Software Coding Articles is Digg proof thanks to caching by WP Super Cache