Tille - I can see you, read those man pages!   Tille's Site

So you know a bit of C

If you don't, get yourself a copy of The C programming language (ISBN 0-13-110163-3) or A Book on C (ISBN 0-333-36821-5).

What is SDL?

Simple DirectMedia Layer is a cross-platform multimedia library designed to provide level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. It is used by MPEG playback software, emulators, and many popular games.

Simple DirectMedia Layer supports Linux, Windows, BeOS, MacOS Classic, MacOS X, FreeBSD, OpenBSD, BSD/OS, Solaris, and IRIX.

SDL is written in C, but works with C++ natively, and has bindings to several other languages, including Ada, Eiffel, Java, Lua, ML, Perl, PHP, Pike, Python, and Ruby.

Why SDL?

In short: you can do something on your system with SDL very quickly, without the requirement of having an in-depth knowledge about special libraries, interfaces, hardware, system calls or parameters. A minimal knowledge of the C programming language is the only thing you need. Read on if you want to hear the real reasons, or go directly to the course.

This might just have well been called the "getting started with C and Linux" notes, or "your first steps with Xlib". Let me tell you how it happened to be about SDL.

When you've read a couple of books about basic C programming, and you know how the standard C library works, more or less, it is time to do something real with that knowledge, on a real system, but where to start? You learn it in highschool, they say. But I'm not a programmer, I'm an engineer, and while I was studying, the most sublime usage of computers was drawing something with the AutoCAD program, which, at least, ran on HP-UX workstations. Therefore, we benefited from about 2 hours explanation of very basic UNIX commands, but that's as far as school teaching went. So, those books on C were a good start, but then?

You download yourself a couple of sources, read the README, where it says to run configure, make and make install, which usually works. Big deal. If it doesn't work, it says in the README to edit the Makefile, which usually involves changing a path or setting a variable. After you've seen a couple of hundred, you can manage. But where do programmers get all these ideas? What is it with me that I can edit a Makefile but that I can not seem to be able to compile anything, because nobody ever told me about Makefiles for my own programs? I've been hearing "RTFM" for over a decade now. But here are a couple of man pages nobody ever bothered to point to - probably assuming it was too difficult.

I've had that feeling for a long time now, because I didn't know about all the steps between writing your program and running it. But I didn't know that it was those things that I didn't know, and so I was told to read the Advanced Programming in the UNIX Environment guide, by Mr. W. Richard Stevens, which describes the UNIX libraries, so as you can include some interesting stuff and maybe interface with your hardware a bit, that kind of stuff. But there are literally thousands of those libraries, which is very depressing. How do you find out, as a newbie, what libraries exist and which ones you need? Complaining about this led me through Java, which is even worse, so I dropped the libraries for a while and wrote a Bash course instead, but I'm again kind of being pushed to do something real.

I was told a couple of times that a screensaver wouldn't be a bad idea to start with, it is supposed to be simple and there are lots of examples. So I faithfully started downloading the sources and reading the docs, wrote myself a very simple screensaver, but used somewhat too advanced sources, which wouldn't even compile without me changing stuff. Very depressing. Again, I complained a lot about there being enough materials to start with, and enough docs to become a guru, but nothing in between to close the gap. I guess by now I was really convincing some people that programming is not a field of expertise that women can master. Still, nobody came with the simple suggestion that I should maybe read this or that exact doc.

Worse still, I got the suggestion to try yet another way, this time with SDL, because being an abstraction layer to write games in, it is supposedly even easier than including Xlib functions. After gathering strength for a couple of days, I started on the /usr/docs/SDL-devel**/ docs, which contain examples of how stuff was done in the previous version, so that delayed me a couple of days. But luckily, there's a tutorial online, at http://www.libsdl.org. Simple enough, I thought to myself. But again, it didn't compile. Not even after one week. I was on the verge of never ever editing one single line of code again. I told my friends, but they didn't think about Makefiles or man pages, they just thought how funny it was that I should be so frustrated about something that always works for them. But the description of the problem is more than half the solution, and if you don't know what your problem is exactly, no solution comes up.

So I started asking around for some real beginner's advise, and all of a sudden, all missing parts fell in place. I understood why I was having such difficulties all the time when aspiring to create a program. Somewhere along the line some basics were left out, that everybody assumes everybody else knows about. Well I didn't. I also never planned to writing any programming-related stuff, although I was encouraged to write some introductional guide on C programming and people argued that Bash programming is also programming. But with Bash, I don't feel like writing a program, I feel like I'm writing a script.

Anyway, there's a lot that I've learned here, and I thought it might be useful to other newbies (yes, even after ten years you can be a newbie).

So why SDL?

If you want to do something practical with the system, SDL is ideal for getting results quickly. It is a form of unified access to system components. For a basic SDL program, you only need to include the SDL headers in your C program, while as other programs dealing with system hardware often need a whole bunch of mysterious libraries, which is way too difficult to get started with. I think this can help speed up the learning curve for first time Linux programmers who only have a basic knowledge of C. After practicing with SDL, other programs will be easier because you started off with something simple and built upon that.

Now let's get on with it.

© 1995-2010 Machtelt Garrels - tille - Powered by vIm - Best viewed with your eyes - Validated by W3C - Last update 20100511