My first opengl program in Linux!

SDL and OpenGL playing nicely under linux

I had my first look at SDL some years ago, when Wing Extrem from Wildbits told me about a library which could work either in Windows or Linux and was very nice for making games. I remember that I managed to compile the .lib for visual studio but didn't manage to go much further.

Since then, I have been finding lots of projects which use SDL as their base, which makes them really portable across platforms, and I decided to have a more in-depth look at it this time, since there's no point in fighting the masses :-)

So I was toying with some tutorials, specially Sol's Graphics for beginners tutorials and the Me and Mark Publishing SDL and OpenGL tutorial and wondered if it would be possible to get the same main.cpp compiled and working on our ubuntu computer...

I had absolutely no idea of how to get something compiled with SDL and OpenGL in linux; the last time I tried to compile a demo for linux it ended up being a frustrating experience which almost caused me a trauma, so I was slightly scared of trying it again. But I decided to go ahead since it was just a plain .cpp file!

Googled a bit and found an straightforward way of compiling:

gcc main.cpp -o main.o `sdl-config --cflags --libs` -lGL -lGLU

If that's not ridiculously simple you tell me what it is. In Mac, for being able to get a [Cocoa] window, you need to prepare a tedious series of files and Objective C wrappers, just for being able to open a window and having decent event processing. Thanks god the nice people from SDL provide some XCode templates for getting started!

Immediate conclusion: apparently it's easier to develop OpenGL stuff in Linux than in Mac, unless there's some hidden automagic going on without my knowledge.

Of course there are a couple of minor details; because this is a computer which acts primarily as a file server, we have never bothered to make OpenGL work and all that, and as a consequence, it doesn't have hardware acceleration. This forced me to comment out the multisampling part, or I would get a Couldn't find matching GLX visual error message each time I tried to execute the program. It's also reporting that polygon stipple is being done by software rendering, but at least it does it.

This has left me wondering why there's not more people making demos for linux. I still need to find out how it would work with more complicated code bases and things like cmake, but it looks as truly doable now that I managed to get my first program working. Hmmm...

Sources

Should you want to fully experience the 0xFF00FF background plus a randomly noise-texturized rotating triangle, simply compile this little file using this ultrasimple bash script and let yourself carried away :-)