Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Graphics in C with SDL (part 0)
Index -> Programming, C -> C Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
CodeMonkey2000




PostPosted: Tue Apr 27, 2010 12:13 am   Post subject: Graphics in C with SDL (part 0)

Introduction
So you wanna move on the C/C++ so you can make ?real? game eh? Well it's a lot of work. There are many starting points, and many ways to get confused and do things the wrong way. Hopefully I will be able to lead you the right way. I will only be using pure C, and be compiling with makefiles. This tutorial probably will (initially) share some similarities to Lazy Foo's tutorials, but I intend to go more indepth and contain topics that he didn't cover. The example at the end just creates a window that you can resize and move around. Don't worry if it is a bit glitchy. All constructive criticism are appreciated and welcome Very Happy

A little FYI, I am assuming that you are a decent C programmer.

What is SDL?
SDL stands for Simple DirectMedia Layer. It is an API for C that provides many functionality like having a window and drawing stuff on that window, and polling events (ie for things like mouse movement and keyboard inputs). It is simple and easy to use.

Why SDL?
It's simple (as the name would suggest), cross-platform. One can also use SDL with openGL, and you get a nice environment for openGL. OpenGL is great since it is much faster at rendering than SDL, and openGL can do 3D rendering. There are a bunch of examples of this in the C++ submission section.

Installing gcc, make and SDL


With Windows
This will be a quick speed run of gandalf's excelent tutorial. First off grab the minGW installer from here (click on the green download now button). Run that, and when prompted select minGW make and C&C++. Install everything into C:\MinGW (should be the default). After everything is installed, go into the minGW file, go into bin. Change mingw32-make to make (it's easier this way).

Now right click the computer icon on your desktop.
Select properties, go into advanced system settings. Select the advanced tab in the new window, then click on environment variables. Now scroll down until you see path. Select it, and then press edit. Now at the end of everything, past in :
code:
;C:\MinGW\bin\


Now to make sure this works, open up command promt (you should make a shortcut to this), and type make. You should get something like ?** no target specified?. Do the same thing with gcc, and you should see a similar type of message. All my tutorials are going to be using make files, so you want to grab something like scite (I recommend this).

Ok now it's time to install SDL.
Go to here . Scroll down Development Libraries, then look for win32. Download the minGW version. Extract it. Open the file, go into include. You should see a folder called SDL. Copy this folder. Now go into minGW/include and paste it here. Now go back in the SDL file you extracted. Go into lib. Copy everything here. Now go into minGW/lib and paste it there. Now go back into the extracted SDL folder. Go in to bin. Copy SDL.dll. Now go into C:\Windows\system . Paste it here.

Now you may test the program. Run the makefile in the sample code (extract the folder, open the makefile in scite and hit f7).

With Linux
If you are using arch linux just go in the terminal and do:
code:
pacman -S scite base-devel sdl

and you are done. For ubuntu users you have a similar option:
code:
apt-get install build-essential scite libsdl1.2-dev libsdl1.2debian


should work.

With Mac
I've never used a Mac, so you're on your own (or you could try lazyfoo's tutorial, but you'll have to research make files).



test.zip
 Description:
Test this file.

Download
 Filename:  test.zip
 Filesize:  716 Bytes
 Downloaded:  566 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
DtY




PostPosted: Tue Apr 27, 2010 5:58 pm   Post subject: RE:Graphics in C with SDL (part 0)

About running on a Mac, it's a bit of a pain.

There are a few ways:

- Installing with macports
Macports includes a package for SDL, it acts like SDL on Linux

- Binary installer from the official website
The SDL website has a mac os download, but it acts weird. Instead of being a series of dynamic libraries, it uses a mac framework, which is just a way to group a bunch of dynamic libraries and their headers into one file (which is the preferred way to do it on Mac os). This is all well and good, but you need different linker flags to compile (which makes it harder to write cross platform software).

[edit] You can always build from source, or use Fink (I think)
Insectoid




PostPosted: Sat Nov 19, 2011 12:55 pm   Post subject: RE:Graphics in C with SDL (part 0)

I used lazyfoo's tutorial to install SDL. It's rather a bitch, 'cause lazyfoo and SDL assume that you really want to use Xcode, which in my case is not true. I couldn't find any instruction on compiling an SDL-based program from the command line, anywhere.
Display posts from previous:   
   Index -> Programming, C -> C Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: