OpenGL 2D Game Programming Book
You have come to the homepage of my upcoming book on writing cross-platform 2D games with OpenGL. From this page you can learn more about the book and download the source code that accompanies the book.
What is the Book About?
The book covers creating cross-platform 2D games with OpenGL and SDL. By cross-platform I mean Linux, Mac OS X, Windows, and any other operating system that supports OpenGL and SDL. One of OpenGL's strengths is it runs on multiple operating systems. It will be nice to have a game programming book that takes advantage of this strength instead of focusing exclusively on Windows
In the book I will create a space shooter game. Each chapter will add a piece to the game: creating a window, drawing the game's background, drawing the player's ship, reading player input to move the ship, background music, sound effects, enemy ships, physics, and so on until a complete game emerges.
Because the book starts out with a simple task, creating a window, and builds a game one step at a time, it will be a nice book for people new to game programming. They can create a simple game without getting overwhelmed. People who already know some game programming for one operating system and want to be able to write code that runs on multiple operating systems will also benefit from the book.
When Will the Book be Finished?
The book is on hold for now because of some other projects. Hopefully I will be able to resume work on the book soon.
Beta Source Code
Game programming books get judged by the source code that accompanies the book. Because I want my code to work for everybody when the book is finished, I am placing beta versions of my source code examples here for you to try out. I have compiled the code for Mac OS X with Xcode and for Windows with CodeWarrior. I would be especially interested in having Linux users and Windows users using environments other than CodeWarrior try to build the code.
The downloads contain the source code files and the necessary data files (graphics, music, etc.) to run the examples. There are no project files included so you will have to create a project in your IDE of choice and add the source code files to your project. You will also have to set up the project so it links against the OpenGL, GLU, SDL, and SDL_image libraries. My article on SDL and OpenGL contains detailed instructions on setting up SDL in Xcode on Mac OS X. The Game Programming Wiki contains detailed instructions on setting up SDL in various build environments.
Some additional disclaimers.
- This is beta code. I can't imagine the code would wreak havoc with your computer, but I can't guarantee it won't.
- The code does not do a great job of error checking. If a problem occurs, the program exits. The most common cause of the program exiting would be the program not being able to locate a data file.
- The programs use placeholder assets. Please don't email me to tell me the graphics stink. I know they do.
- If you're using Linux, you may have to modify the code that includes SDL_opengl.h. Several Linux people told me some code would not compile because I included SDL_OpenGL.h instead of SDL_opengl.h. You may have to change SDL_OpenGL.h to SDL_opengl.h to get the code to compile.
Here are the downloads.
- SDL Texture Load. This program draws a texture map of a star field in a window.
- SDL Animation. This program builds on the SDL Texture Load example. It adds a spaceship you can move around the screen.
- SDL Input. This program adds joystick support to the SDL Animation example.
- SDL Audio. This program adds sound to the SDL Input example.
Instructions on setting up SDL with Visual C++ Express 2005 (PDF, 224 KB).
Questions and Comments
Feel free to email with any questions or comments about the book or source code. You can find my email address in the Read Me file that accompanies the download. You can also find my email address on the Contact page.