Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
SDL Game Development

You're reading from  SDL Game Development

Product type Book
Published in Jun 2013
Publisher Packt
ISBN-13 9781849696821
Pages 256 pages
Edition 1st Edition
Languages
Author (1):
Shaun Mitchell Shaun Mitchell
Profile icon Shaun Mitchell

Setting up SDL in Visual C++ Express 2010


This book will cover setting up SDL 2.0 in Microsoft's Visual C++ Express 2010 IDE. This IDE was chosen as it is available for free online, and is a widely used development environment within the games industry. The application is available at https://www.microsoft.com/visualstudio/en-gb/express. Once the IDE has been installed we can go ahead and download SDL 2.0. If you are not using Windows to develop games, then these instructions can be altered to suit your IDE of choice using its specific steps to link libraries and include files.

SDL 2.0 is still in development so there are no official releases as yet. The library can be retrieved in two different ways:

  • One is to download the under-construction snapshot; you can then link against this to build your games (the quickest option)

  • The second option is to clone the latest source using mercurial-distributed source control and build it from scratch (a good option to keep up with the latest developments of the library)

Both of these options are available at http://www.libsdl.org/hg.php.

Building SDL 2.0 on Windows also requires the latest DirectX SDK, which is available at http://www.microsoft.com/en-gb/download/details.aspx?id=6812, so make sure this is installed first.

Using Mercurial to get SDL 2.0 on Windows

Getting SDL 2.0 directly from the constantly updated repository is the best way of making sure you have the latest build of SDL 2.0 and that you are taking advantage of any current bug fixes. To download and build the latest version of SDL 2.0 on Windows, we must first install a mercurial source control client so that we can mirror the latest source code and build from it. There are various command-line tools and GUIs available for use with mercurial. We will use TortoiseHg, a free and user-friendly mercurial application; it is available at tortoisehg.bitbucket.org. Once the application is installed, we can go ahead and grab the latest build.

Cloning and building the latest SDL 2.0 repository

Cloning and building the latest version of SDL directly from the repository is relatively straightforward when following these steps:

  1. Open up the TortoiseHg Workbench window.

  2. Pressing Ctrl + Shift + N will open the clone dialog box.

  3. Input the source of the repository; in this case it is listed on the SDL 2.0 website as http://hg.libsdl.org/SDL.

  4. Input or browse to choose a destination for the cloned repository—this book will assume that C:\SDL2 is set as the location.

  5. Click on Clone and allow the repository to copy to the chosen destination.

  6. Within the C:\SDL2 directory there will be a VisualC folder; inside the folder there is a Visual C++ 2010 solution, which we have to open with Visual C++ Express 2010.

  7. Visual C++ Express will throw up a few errors about solution folders not being supported in the express version, but they can be safely ignored without affecting our ability to build the library.

  8. Change the current build configuration to release and also choose 32 or 64 bit depending on your operating system.

  9. Right-click on the project named SDL listed in the Solution Explorer list and choose Build.

  10. We now have a build of the SDL 2.0 library to use. It will be located at C:\SDL2\VisualC\SDL\Win32(or x64)\Release\SDL.lib.

  11. We also need to build the SDL main library file, so choose it within the Solution Explorer list and build it. This file will build to C:\SDL2\VisualC\SDLmain\Win32(or x64)\Release\SDLmain.lib.

  12. Create a folder named lib in C:\SDL2 and copy SDL.lib and SDLmain.lib into this newly created folder.

I have the library; now what?

Now a Visual C++ 2010 project can be created and linked with the SDL library. Here are the steps involved:

  1. Create a new empty project in Visual C++ express and give it a name, such as SDL-game.

  2. Once created, right-click on the project in the Solution Explorer list and choose Properties.

  3. Change the configuration drop-down list to All Configurations.

  4. Under VC++ Directories, click on Include Directories. A small arrow will allow a drop-down menu; click on <Edit…>.

  5. Double-click inside the box to create a new location. You can type or browse to C:\SDL2.0\include and click on OK.

  6. Next, do the same thing under library directories, this time passing in your created lib folder (C:\SDL2\lib).

  7. Next, navigate to the Linker heading; inside the heading there will be an Input choice. Inside Additional Dependencies type SDL.lib SDLmain.lib:

  8. Navigate to the System heading and set the SubSystem heading to Windows(/SUBSYSTEM:WINDOWS).

  9. Click on OK and we are done.

You have been reading a chapter from
SDL Game Development
Published in: Jun 2013 Publisher: Packt ISBN-13: 9781849696821
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}