⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guidebasicsinit.html

📁 VC5.6.7的一个扩展库。跟DirectX的功能差不多。
💻 HTML
字号:
<HTML><HEAD><TITLE>Initializing SDL</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="SDL Library Documentation"HREF="index.html"><LINKREL="UP"TITLE="The Basics"HREF="guidethebasics.html"><LINKREL="PREVIOUS"TITLE="The Basics"HREF="guidethebasics.html"><LINKREL="NEXT"TITLE="Graphics and Video"HREF="guidevideo.html"></HEAD><BODYCLASS="SECT1"BGCOLOR="#FFF8DC"TEXT="#000000"LINK="#0000ee"VLINK="#551a8b"ALINK="#ff0000"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">SDL Library Documentation</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="guidethebasics.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 1. The Basics</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="guidevideo.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="GUIDEBASICSINIT"></A>Initializing SDL</H1><P>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 <AHREF="sdlinit.html"><TTCLASS="FUNCTION">SDL_Init</TT></A> (or <AHREF="sdlinitsubsystem.html"><TTCLASS="FUNCTION">SDL_InitSubSystem</TT></A>). <TTCLASS="FUNCTION">SDL_Init</TT> 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:<PRECLASS="PROGRAMLISTING">    SDL_Init ( SDL_INIT_VIDEO );</PRE>To initialize the default subsystems, the Video subsystem and the Timers subsystem you would call:<PRECLASS="PROGRAMLISTING">    SDL_Init ( SDL_INIT_VIDEO | SDL_INIT_TIMER );</PRE></P><P><TTCLASS="FUNCTION">SDL_Init</TT> is complemented by <AHREF="sdlquit.html"><TTCLASS="FUNCTION">SDL_Quit</TT></A> (and <AHREF="sdlquitsubsystem.html"><TTCLASS="FUNCTION">SDL_QuitSubSystem</TT></A>). <TTCLASS="FUNCTION">SDL_Quit</TT> shuts down all subsystems, including the default ones. It should always be called before a SDL application exits.</P><P>With <TTCLASS="FUNCTION">SDL_Init</TT> and <TTCLASS="FUNCTION">SDL_Quit</TT> 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, <TTCLASS="FUNCTION">SDL_Init</TT>, 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 <TTCLASS="FUNCTION">SDL_GetError</TT>. Use this often, you can never know too much about an error.</P><DIVCLASS="EXAMPLE"><ANAME="AEN60"></A><P><B>Example 1-1. Initializing SDL</B></P><PRECLASS="PROGRAMLISTING">#include "SDL.h"   /* All SDL App's need this */#include &#60;stdio.h&#62;int main(int argc, char *argv[]) {        printf("Initializing SDL.\n");        /* Initialize defaults, Video and Audio */    if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)==-1)) {         printf("Could not initialize SDL: %s.\n", SDL_GetError());        exit(-1);    }    printf("SDL initialized.\n");    printf("Quiting SDL.\n");        /* Shutdown all subsystems */    SDL_Quit();        printf("Quiting....\n");    exit(0);}&#13;</PRE></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="guidethebasics.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="index.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="guidevideo.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">The Basics</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="guidethebasics.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Graphics and Video</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -