4 >Initializing SDL</TITLE
7 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
10 TITLE="SDL Library Documentation"
11 HREF="index.html"><LINK
14 HREF="guidethebasics.html"><LINK
17 HREF="guidethebasics.html"><LINK
19 TITLE="Graphics and Video"
20 HREF="guidevideo.html"></HEAD
31 SUMMARY="Header navigation table"
40 >SDL Library Documentation</TH
48 HREF="guidethebasics.html"
56 >Chapter 1. The Basics</TD
62 HREF="guidevideo.html"
76 NAME="GUIDEBASICSINIT"
80 >SDL is composed of eight subsystems - Audio, CDROM, Event Handling, File I/O, Joystick Handling, Threading, Timers and Video. Before you can use any of these subsystems they must be initialized by calling <A
87 HREF="sdlinitsubsystem.html"
90 >SDL_InitSubSystem</TT
95 > must be called before any other SDL function. It automatically initializes the Event Handling, File I/O and Threading subsystems and it takes a parameter specifying which other subsystems to initialize. So, to initialize the default subsystems and the Video subsystems you would call:
97 CLASS="PROGRAMLISTING"
98 > SDL_Init ( SDL_INIT_VIDEO );</PRE
100 To initialize the default subsystems, the Video subsystem and the Timers subsystem you would call:
102 CLASS="PROGRAMLISTING"
103 > SDL_Init ( SDL_INIT_VIDEO | SDL_INIT_TIMER );</PRE
109 > is complemented by <A
116 HREF="sdlquitsubsystem.html"
119 >SDL_QuitSubSystem</TT
124 > shuts down all subsystems, including the default ones. It should always be called before a SDL application exits.</P
132 > firmly embedded in your programmers toolkit you can write your first and most basic SDL application. However, we must be prepare to handle errors. Many SDL functions return a value and indicates whether the function has succeeded or failed, <TT
135 >, for instance, returns -1 if it could not initialize a subsystem. SDL provides a useful facility that allows you to determine exactly what the problem was, every time an error occurs within SDL an error message is stored which can be retrieved using <TT
138 >. Use this often, you can never know too much about an error.</P
146 >Example 1-1. Initializing SDL</B
149 CLASS="PROGRAMLISTING"
150 >#include "SDL.h" /* All SDL App's need this */
151 #include <stdio.h>
153 int main(int argc, char *argv[]) {
155 printf("Initializing SDL.\n");
157 /* Initialize defaults, Video and Audio */
158 if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)==-1)) {
159 printf("Could not initialize SDL: %s.\n", SDL_GetError());
163 printf("SDL initialized.\n");
165 printf("Quiting SDL.\n");
167 /* Shutdown all subsystems */
170 printf("Quiting....\n");
181 SUMMARY="Footer navigation table"
192 HREF="guidethebasics.html"
210 HREF="guidevideo.html"
226 HREF="guidethebasics.html"
234 >Graphics and Video</TD