SDL: Make Linux Interest Simple Direct Media Layer Lab to Linux Sam Lantingaloki Entertainment Software Programmer in September 1999
Content: What is SDL? SDL's origin SDL future reference about the author
SAM Lantinga is the author of the Simple DirectMedia Layer and the chief developer of Loki Entertainment, and he will introduce you to an excellent tool to transplant the game to Linux. SDL is an ideal tool for cross-platform code transplant, which supports many platforms such as Linux, Solaris, Irix, FreeBSD, and Macos, which makes it a lot for Linux developers who think that the commercial software can be developed on Linux. He taught SDL to the community to make Linux users to enjoy the best game on any platform, and how SDL helps developers with the requirements of the next generation of computer game fans. Since Linus starts to develop Linux, it is now that Linux has become all hackers' dreams and all over the world, one of the most important elements in Linux is the quality and availability of the OS on the OS. The game is our entertainment and leisure. They can improve creativity and expand their ideas. The game can also be used to measure the performance of the operating system. Because the game is getting more complex, they force each subsystem to approximate the limits. Whenever I assemble a system, the first thing to do is to load a game and try to play, with the performance of each item. The game on Linux already has a long time. From the early Nettrek, to the highly praised doom! And Ray God, people can already play games on Linux. But the problem is not enough game. No big company creates a sensational effect for Linux. However, this situation is beginning to improve because the operating system becomes increasingly popular. The earliest game on Linux uses the X11 protocol. But for the game, the X11 is too slow because it is a protocol designed for menus-based applications on the network. Using its game usually does not have a beautiful picture, and it is quite slow. Doom! Is a payable exception, although it uses X11, but it can make the animation more smooth and provide realistic three-dimensional effect by using the MIT shared memory extension. There are also some games using the SVGA graphics library, SvGalib. An old game my favorite is a gravity wave, which has made significant changes to its simulated old Amiga game Gravity Force. But using SVGALIB can only apply to a small number of supported graphics cards.
Early X11 game, a picture of the crust. Myth 2 (Myth 2), LOKI, today, game developers have more choices. You can still use the X toolbox or full screen API, such as Svgalib or FBCON, but now there are still many gaming libraries available. The Simple DirectMedia Layer library is one of the best low-level game development APIs on Linux. What is SDL? Simple DirectMedia Layer Library, referred to as SDL, is one of the free software libraries used in numerous commercial game development companies. It provides cross-platform 2D frame buffer graphics and audio services that support Linux, Win32, and Beos. Other platforms are also supported varying degrees, including Solaris, Irix, FreeBSD, and MacOS. In addition to a large number of services, including threads, independent of the macro and CD audio of byte storage, SDL also provides a simple API, which allows you to be as close as possible to this machine hardware. Use SDL to have triple advantages: stable, simple and flexible. stable. If SDL does not provide reliable support to the API, then those enthusiasts and commercial companies can use it. Because of the use of SDL, it adds an error correction and enhances performance, and also strengthens the strongness of the API. As the core development is step-by-step, the development of SDL is also stepped step-by-step, some of which is a reliable and stable API, and the other part is a new feature and a sandbox. simple. SDL is designed as a simple API to achieve your idea with the least code. For example, I have recently transplanted some demo procedures from the Linux demo group Optimum, and I replace their X11 code to SDL code (see the list below). You can see that the SDL code is very easy to write and understand. X11 code
INT init_x (int X, int y,
INT W, INT H, INT BPP,
Const char * name) {
XpixmapFormatvalues * formatList;
Int formatcount;
INT I;
Int formatok;
Int scanLineLength;
XGcValues gcval;
Unsigned long gcmask;
DIS = XOpendisplay (null);
IF (DIS == NULL) {
FPRINTF (stderr, "error: / n");
FPRINTF (stderr, "cannot connect to display./n");
Exit (1);
}
Screen = Defaultscreen (DIS);
DEPTH = DefaultDepth (DIS, Screen);
Width = DisplayWidth (Dislike);
Height = DisplayHeight (DIS, SCREEN);
WinRoot = Defaultrootwindow (DIS);
Winattr.Border_pixel = BlackPixel (DIS, Screen);
Winattr.Background_pixel = BlackPixel (DIS, Screen);
Winmask = CWBackPixel | CWBORDERPIXEL;
FormatList = XListpixmapFormats (Disnors & FormatCount); if (FormatList == NULL) {
FPRINTF (stderr, "cannot get pixmap list / n");
Exit (1);
}
Formatok = -1;
For (i = 0; Ibytes_Per_Line * Xim-> Height,
IPC_CREAT | 0777);
XIM-> DATA = shminfo.shmaddr = (char *) Shmat (shminfo.shmid, 0, 0);
Shminfo.readonly = false;
Xshmattach (DIS, & Shminfo);
XSync (DIS, FALSE);
Buffer = (unsigned char *) XIM-> DATA;
#ELSE
Buffer = (unsigned char *) Calloc (w * h, pixmapformat.bits_per_pixel / 8);
Xim = XcreateImage (DIS, COPYFROMPARENT, DEPTH, ZPIXMAP, 0,
(char *) BUFFER, W, H,
Pixmapformat.scanline_pad, scanlinength;
IF (XIM == NULL) {
FPRINTF (stderr, "couldnt create ximage ../ n");
EXIT (-1);
}
#ENDIF
GcVal.Foreground = 0;
GcVal.background = 0;
GCMask = gcForeground | gcBackground;
GC = Xcreategc (DIS, WIN, GCMASK, & GCVAL);
IF (depth == 24)
Depth = pixmapformat.bits_per_pixel;
Return (depth);
} SDL code
INT init_x (int X, int y,
INT W, INT H, INT BPP,
Const char * name) {
INT I;
IF (SDL_INIT (SDL_INIT_VIDEO) <0)
{
FPRINTF (stderr, "erreur: / n");
FPRINTF (stderr, "Impossible de SE Connecter Au Display / N");
Exit (1);
}
Screen = SDL_SETVIDEOMODE (W, H, BPP, SDL_SWSURFACE | SDL_HWPALETTE);
IF (screen == null)
{
FPRINTF (stderr, "erreur: / n");
FPRINTF (stderr, "Impossible de SE Connecter Au Display / N");
Exit (1);
}
SDL_WM_SETCAPTION (Name, Name);
For (i = SDL_Noevent; IFORMAT-> BitsPerpixel;
Width = Screen-> W;
HEIGHT = Screen-> H;
Buffer = (unsigned char *) Screen-> Pixels;
Return (depth);
} Flexible. Returns to the Optimum Demo Code Example of the above, as long as you move to SDL, and determine some data assumptions, you don't have to change the code at all, the presentation can run on Win32, Beos, and Linux consoles. On the other hand of flexibility, it is reflected in although the code is completely cross-platform, you will not separate you and the underlying. SDL provides functions SDL_GETWMINFO () that allows you to access private window information for the underlying driver. Loki Entertainment Software uses this technology to interact to their game intelligence window manager. Optimum Demo Edition screen snapshot This is a strongly stable stable, simple and powerful combination has brought some extremely fascinating games, including Maelstrom, Hopkins FBI, Civilization: Covilization: Call to Power ), The sky rotation 2 (Descent 2), myth 2: Soulblighter (Mythii: Soulighter), Railway Tycoon 2 (Railroad Tycoon II), etc. The fact that programming enthusiasts and commercial companies use this library indicates that it is increasing its functionality and stability. This is in line with the actual needs of the actual game.
Civilization: Cvilizational: Call to Power Picture of the picture of SDL 2 (Descent 2) SDL's origin SDL is two years ago, at the time I was working from the Macintosh emulator Executor to Win32 transplantation. I noticed that the same function is basically implemented in the same way on several platforms. All goals require access to the screen, mapping the mouse and keyboard input, and playing sound. I think: Why don't you write a basic service that many people will use? Application developers only need to write an API, which greatly simplifies their work, but also allows their code to run quickly on multiple platforms to attract as many viewers as possible. I started to do it, after more than a year, the first stable SDL release was born. The first step in creating SDL is to identify the desired function. According to analytical Executor and past transplant experience, I have already had a good idea. The next step is to build a valid prototype running on Win32 and Linux. I know that the biggest test for the API is working under the actual application, so the first thing I have to use is to use it to complete the transplant from Executor to Win32. During this time, I constantly add API's body and transplant it to the BEOS. Then, use the latest DOM! Source code, in just three days, it allows it to run smoothly on all three supported platforms. One year later, I now use it to port some of the world's best games to the world's most popular operating system Linux. Although I have a business company, this library itself is free, and it is an embodiment of the open source concept. The associated library SDL is a widely available large tool set. As a video API, SDL provides a simple frame buffer for custom bitmap or special effects. Using SDL can complete a complete file file with special demonstration and visual enjoyment, you can also try the GGI and PTC libraries, which are also very popular in the game and presentation. As the sound API, SDL supports automatic audio conversion and transparent Esound support. In the sample file, there is even a complete sample mixing, but you can also try the ALSA and GSI libraries. For three-dimensional images, using Mesa is definitely a good way. As a window toolbox, GTK is very popular. The freedom in Linux, some of which is the freedom of choice, contributing. It is a proof of Linux ideals and freedom. Contribute to SDL Press GNU Lesser General Public License, which means that the free software and business programs can be used, and each person can share this change after the change of the source code is added to the public source. Welcome to the SDL to send the patch to the development version of the SDL. Provide a mailing list for developers, you can subscribe to the mail list by sending messages containing the "Subscribe SDL" to Majordomo@lokigames.com. This mailing list is a newsgroup on news: //news.lokigames.com/loki.open-source.sdl. Join this mailing list to get the latest announcements and new features about using SDL, incorrectly correct, and use SDL's preview versions. The following SDL's future is the next year's SDL some new and exciting development directions:
Game lever support. A great game lever API is built in the latest nucleolry of Linux. I intend to integrate this support into the SDL event model that allows any event filtration, callback, and asynchronous event assignment. Garrett Banuk has written the most implementation that will be added to the latest SDL development branch. Linux Frame Buffer Console Support. The latest Linux kernel contains the console support of the native graphic in the form of a frame buffer driver, and its creator is Gert UyTerhoeven. SDL has an initial driver with native console keyboard and PS / 2 mouse driver, which can perform this support. SCITECH MGL support. Scitech has a great graphics library for Win32, DOS, Linux, OS / 2 and QNX. But it is a commercial library, and the VESA console driver is free for Linux. Therefore, the VESA console driver in SDL can be supported. MESA is integrated into a GLX layer. OpenGL is definitely a way to develop three-dimensional games on Linux. However, the method of the GLX API handling event is not as flexible as SDL. Some people requested integration of extensions similar to GLX to SDL to use it as an input interface of GL-based games. Redesign the architecture to allow multiple display and multiple inputs. The current architecture compiles the SDL function to the stub module and dynamically loads the low-level driver during runtime. This cross-platform execution will result in a buffore to use, and generate a complex header file. For me, the most tight thing is to redesign the construction process, so all drivers can be compiled into a library, then dynamically select at runtime. The advantage of this is that there are multiple activities display and input methods at the same time. Imagine running on the console and remote X11 monitor at the same time! more games! The improvement of SDL will make more and more people use this library, and more and more games will appear on Linux. On http://www.devolution.com/~slouken/sdl/introb/toc.html, you can find a very good introduction of the SDL API, and list of items using the SDL API. I am very excited to get involved in Linux games, I hope to continue to work to bring joy for the Linux world, because Linux is too good. As they said, the penguin also likes to be happy. I will soon write a follow-up article, which will bring you the tutorial for how to write the game using SDL. Reference AN Introduction To The SDL API The Scitech Graphics Library Download Some of the best games on Linux: