SDL2.0 Learning Note-The first test program under Windows 1

Source: Internet
Author: User
Tags php download

SDL Full name is simple DirectMedia Layer, is an open-source, cross-platform (WIN32,LINUX,MAC) multimedia development of the C language library.

Official website http://www.libsdl.org/

The first step is to download the source file

First go to this page http://www.libsdl.org/tmp/download-2.0.php download the relevant resource files, directly download Sdl2-2.0.0.zip to compile their own, or download the relevant development resources (bin and include) on your own system. After extracting the resource bundle, the contents are as follows:

The Include directory is the head file, and the SRC directory is the source C file of SDL.

In order to easily write SDL programs under VS, you can place the contents of the include in the Include Directory of the development environment, as in C:\Program Files\Microsoft Visual Studio 11.0\vc\ Include the new SDL directory to place all SDL header files.

(You can also use junction link, using mklink/j "C:\Program Files\Microsoft Visual Studio 11.0\vc\include\sdl"./sdl2.0.../include command to complete)

Step two, compile SDL (If you download the relevant development resources, you can skip this step directly)

Enter the VisualC directory, you can see the sln file of VS, support vs2008,vs2010,vs2012, according to their own VS version selection related solution Open, compile, respectively can get SDL2.lib, SDL2main.lib, SDL2test.lib, SDL2.dll files.


SDL2.lib is the core of the static link library file, SDL2main.lib defines the SDL under the Windows Platform entry function (which is explained later), SDLtest.lib for testing (belonging to the Sdltest library, you can use it to test your current system or platform of the SDL function support).

Step three, write the first SDL program

Create a project, a new C or CPP source file. Start with a simple coding to test:

1 #include <sdl/SDL.h> 2 #include <iostream> 3  4//due to the internal redefinition of main in SDL, the main function must be this form, specifically, followed by a detailed description of the 5 int main (int argc, char * argv[]) 6 {7     //Initialize SDL 8     if ((Sdl_init (sdl_init_video| Sdl_init_audio) = =-1)  9     {         //initialization failed, typing error, note sdl_geterror Returns a string, readability is good, isn't it?         printf ("Could not initialize SDL:%s.\n", Sdl_geterror ());     }13     else14     {         printf ("SDL Initialize ok! ");     }17     //End SDL18     sdl_quit ();     GetChar ();     return 0;21}


Here are some points to note:

1, the entry function can not be written as main (), must have parameters, because SDL will have implemented inside the entry function, here is actually sdl_main.

2. If you are using VS in a Windows environment, pay attention to the following settings for the test project:

(1) Project Properties-Configuration Properties-linker-System: Subsystem (select Console (/subsystem:console) or window (/subsystem:windows)).

(2) Project Properties-Configuration Properties-c/c++: Additional Include directory: Select the Include directory for SDL.

(3) Add SDL2.lib, SDL2main.lib to the project. Add to Project Properties-Configuration Properties-linker-Input: Additional dependencies, or directly as a file.

SDL2.0 Learning Note-The first test program under Windows 1

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.