One of SDL Study Notes

Source: Internet
Author: User
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:

  1. Void drawpixel (sdl_surface * screen, int X, int y, uint8 R, uint8 g, uint8 B)
  2. {
  3. Unit32 color = sdl_maprgb (screen-> Format, R, G, B );
  4. Switch (screen-> Format-> bytesperpixel)
  5. {
  6. Case 1: // assuming 8-bpp
  7. {
  8. Uint8 * bufp;
  9. Bufp = (uint8 *) screen-> pixels + y * screen-> pitch + X;
  10. * Bufp = color;
  11. }
  12. Break;
  13. Case 2: // probable 15-bpp or 16-bpp
  14. {
  15. Uint16 * bufp;
  16. Bufp = (uint16 *) screen-> pixels + y * screen-> pitch + x * 3;
  17. If (sdl_byteorder = sdl_lil_endian)
  18. {
  19. Bufp [0] = color;
  20. Bufp [1] = color> 8;
  21. Bufp [2] = color> 16;
  22. } Else {
  23. Bufp [2] = color;
  24. Bufp [1] = color> 8;
  25. Bufp [0] = color> 16;
  26. }
  27. }
  28. Break;
  29. Case 4: // probable 32-bpp
  30. {
  31. Uint32 * bufp;
  32. Bufp = (uint32 *) screen-> pixels + y * screen-> pitch/4 + X;
  33. * Bufp = color;
  34. }
  35. Break;
  36. }
  37. }

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.

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.