1. initialize SDL: sdl_init (mode );
Mode:
Sdl_init_timer
Sdl_init_audio
Sdl_init_video
Sdl_init_cdrom
Sdl_init_joystick
Sdl_init_noparachute
Sdl_init_eventthread
Sdl_init_everything
2. Get the error expression:
Sdl_geterror ();
3. Exit the program and clear the system: sdl_quit ();
Atexit (sdl_quit );
4. In SDL, everything is visible!
Sdl_surface * screen;
Screen = sdl_setvideomode (800,600, 32, sdl_hwsurface | sdl_doublebuf );
Last flag:
Sdl_swsurface creates a video surface (software) in the system memory );
Sdl_hwsurface creates a video surface (hardware) in the video memory );
Sdl_asyncb.pdf enabling asynchronous update of the display surface will slow down bitmap replication of a single processor, but will accelerate in SMP.
Sdl_anyformat must also be used when invalid BPP is specified, instead of using projection surface simulation for SDL.
Sdl_hwpalette specifies that SDL exclusively accesses the color palette. Otherwise, when you use sdl_setcolors or sdl_setpalette, you may not always get the desired color.
Sdl_doublebuf must be used together with sdl_hwsurface to enable hardware dual-cache. Call sdl_flip to swap the buffer and update the display. Otherwise, sdl_flip only executes sdl_updaterect throughout the screen.
Sdl_fullscreen full screen mode. If the hardware resolution is not supported, a window is displayed in the black background center with a higher resolution.
Sdl_opengl creates an OpenGL rendering environment. Before that, you need to use sdl_gl_setattribute to pre-set the OpenGL display attribute.
Sdl_openglbloud creates a glrc with the same name, but allows common block replication operations.
Sdl_resizable creates a window that can be adjusted. When the window size is changed, an sdl_videoresize event is generated. You can call sdl_setvideomode with a new size.
If sdl_noframe is possible, sdl_noframe will generate a window without a title bar or borders. This attribute is automatically available in full screen mode.
5. SDL Data Type
The same unsigned char, such as uint8;
Uint16/32/64/16/32/64-bit unsigned integer;
Sint8, 16/32, and 64 are the same as above. The corresponding signed type is used;
6. Sometimes, when initialization fails, you can continue: sdl_wasinit ().
If (sdl_wasinit () & sdl_init_audio) Sound = true;
7. Code for drawing pixels:
- Void drawpixel (sdl_surface * screen, int X, int y, uint8 R, uint8 g, uint8 B)
- {
- Unit32 color = sdl_maprgb (screen-> Format, R, G, B );
- Switch (screen-> Format-> bytesperpixel)
- {
- Case 1: // assuming 8-bpp
- {
- Uint8 * bufp;
- Bufp = (uint8 *) screen-> pixels + y * screen-> pitch + X;
- * Bufp = color;
- }
- Break;
- Case 2: // probable 15-bpp or 16-bpp
- {
- Uint16 * bufp;
- Bufp = (uint16 *) screen-> pixels + y * screen-> pitch + x * 3;
- If (sdl_byteorder = sdl_lil_endian)
- {
- Bufp [0] = color;
- Bufp [1] = color> 8;
- Bufp [2] = color> 16;
- } Else {
- Bufp [2] = color;
- Bufp [1] = color> 8;
- Bufp [0] = color> 16;
- }
- }
- Break;
- Case 4: // probable 32-bpp
- {
- Uint32 * bufp;
- Bufp = (uint32 *) screen-> pixels + y * screen-> pitch/4 + X;
- * Bufp = color;
- }
- Break;
- }
- }
8. Before drawing, you sometimes need to lock the screen: sdl_locksurface (screen)/sdl_unlocksurface (screen );
If (sdl_mustlock (screen) sdl_locksurface (screen );
If (sdl_mustlock (screen) sdl_unlocksurface (screen );
9. SDL message processing:
Sdl_evnet ent;
Deliver the message until there is no message: While (sdl_pollevent (& ent )){};
Message Type: sdl_quit, sdl_keydown, etc;
Key-character ing: sdlk_xxx, such as sdlk_escape;
Ent. Key. keysym. sym, which is included in the sdl_keysym.h file.