SDL video Subsystem

Source: Internet
Author: User

The most common subsystem in SDL is the video subsystem. The video here refers not to movies we normally play, but to things that are displayed on the screen. If you need to show pictures and texts on the screen, you must use the video subsystem, otherwise, nothing can be seen. The video subsystem supports: Setting the video mode or creating a video window; supporting direct image frame buffering; supporting Alpha pixel mixing; supporting Blit bit Block Transmission and hardware acceleration ); supports window management and graphic rendering.

To use the video subsystem, you must first create an SDL window or set the display mode of SDL:

/*
Function: Create an SDL display surface.
Parameter: int width. The window width is measured in pixels.
Int height window height in pixels
The number of pixels in the int bpp window. If it is 0, the default Prime Number of the current window is used.
Unit32 flags, indicating window features
Returned value: SDL_Surface *. The window pointer is returned successfully; otherwise, NULL is returned.
*/

  SDL_Surface *SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags);

To create a window, you must click it to display everything in the future. The Return Value of the function is SDL_Surface *, and SDL_Surface is also called a surface or a skin). It is something to be displayed. It may be an image or a string. We may need to display a lot of things in our applications, so we may create a lot of surfaces, but remember that no matter how many surfaces there are, but only useSurface Generated by SDL_SetVideoMode FunctionOr window) to display, any other surface must be flushed to this window to display, this is very important. For example, this window is like a whiteboard. You need to paste the display items on the whiteboard to display them, and the pasted items will overwrite the previous items. The following code creates a display window:

/* Function: Create an SDL display window by csl Date: 2012-5-4 */# include <stdio. h> # include <stdlib. h> # include "SDL. h "SDL_Surface * gpScreen; // display surface int main (int argc, char * argv []) {if (SDL_Init (SDL_INIT_VIDEO) =-1 )) // initialize the video subsystem {printf ("Unable to init SDL: % s \ n", SDL_GetError (); exit (-1);} atexit (SDL_Quit ); // register SDL_Quit and call it upon exit so that the program is automatically cleared upon exit // create a 32-bit 600*480 window gpScreen = SDL_SetVideoMode (600,480, 32, SDL_HWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF); if (! GpScreen) {exit (1);} SDL_Delay (3000); // pause SDL_FreeSurface (gpScreen) for 3 seconds; // system ("pause") must be released before exiting the program "); return 0 ;}

GpScreen is the pointer to the display window, a global variable. The display window is created in Row 3. flags is a bid indicating the window features. Common labels are already displayed in bold:

SDL_SWSURFACE

Create a surface in system memory

SDL_HWSURFACE

On the Display memory creation Surface

Sdl_asyncb.pdf

Displays asynchronous updates on the table, which reduces the performance of the cpu but increases the speed on the multi-processor.

SDL_ANYFORMAT

Generally, if the pixel depth on the surface is not available, for example, you specify 64, but not on your machine), SDL will simulate a shadow surface. This flag prohibits this practice. This will enable SDL to use this surface without considering bpp

SDL_DOUBLEBUF

Use double buffering

SDL_FULLSCREEN

Full Screen mode

SDL_OPENGL

Create an OpenGL rendering environment

SDL_RESIZABLE

Create a variable size window

SDL_NOFRAME

Create a window without borders and titles.

These constants can be used in combination. For example, SDL_FULLSCREEN | SDL_DOUBLEBUF | SDL_HWSURFACE indicates creating a full screen window in the video memory and using double buffering. Note: Dual buffering is generally used in full screen mode, and dual buffering is also used if it is used in the display memory creation surface. We recommend that you use SDL_HWSURFACE | SDL_DOUBLEBUF. If an error occurs, try SDL_SWSURFACE.

After calling the function, check whether gpScreen is empty. If it is empty, end the program. Before exiting the program, you must call SDL_FreeSurface to release the window resource referred to by gpScreen.

The SDL_Surface details are described in detail in the basic concepts of the video subsystem.


This article is from the "Learning Joy" blog, please be sure to keep this source http://chengshaolei.blog.51cto.com/1994169/1291966

Related Article

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.