SDL_Surface(3)

๐Ÿ“ฆ version 1.2.15, in debian bookworm, nixos 26.05, nixpkgs unstable, ubuntu jammy

๐Ÿ’– SDL_Surface(3) ๐Ÿ’–

okay so bestie, you've stumbled into the SDL API Reference and this is the page about surfaces โ€” the single most important lil struct in all of SDL graphics. buckle up, hydrate, and let's go ๐ŸŒธ


โœจ NAME โœจ

SDL_Surface โ€” Graphical Surface Structure ๐ŸŽจ


๐ŸŽ€ STRUCTURE DEFINITION ๐ŸŽ€

here's the whole vibe, laid out exactly how it lives in the header, no cap:

typedef struct SDL_Surface {
        Uint32 flags;                           /* Read-only */
        SDL_PixelFormat *format;                /* Read-only */
        int w, h;                               /* Read-only */
        Uint16 pitch;                           /* Read-only */
        void *pixels;                           /* Read-write */

        /* clipping information */
        SDL_Rect clip_rect;                     /* Read-only */

        /* Reference count -- used when freeing surface */
        int refcount;                           /* Read-mostly */

     /* This structure also contains private fields not shown here */
} SDL_Surface;
๐Ÿ‘€ notice the comments on each field, they tell you what you're allowed to touch. read them. respect them.

๐Ÿฆ‹ STRUCTURE DATA ๐Ÿฆ‹

  • flags โ€” the surface flags, aka the whole personality of your surface ๐Ÿšฉ
  • format โ€” the pixel format
  • w, h โ€” width and height of the surface ๐Ÿ“
  • pitch โ€” length of a surface scanline, in bytes
  • pixels โ€” pointer to the actual pixel data, the real MVP ๐Ÿ’…
  • clip_rect โ€” the surface clip rectangle โœ‚๏ธ

๐ŸŒˆ DESCRIPTION ๐ŸŒˆ

SDL_Surface's represent areas of "graphical" memory โ€” memory that can be drawn to. that's literally the whole point of them, they're canvases you can paint on ๐Ÿ’–

the video framebuffer is returned as a SDL_Surface by SDL_SetVideoMode and SDL_GetVideoSurface. so yes, your whole screen is lowkey just a surface. main character energy fr.

most of the fields should be pretty obvious. w and h are the width and height of the surface in pixels. pixels is a pointer to the actual pixel data, and โ€” listen โ€” the surface should be locked before accessing this field. do not skip that step, i'm begging ๐Ÿซ 

the clip_rect field is the clipping rectangle as set by SDL_SetClipRect.


๐ŸŒŸ the flags field ๐ŸŒŸ

the following are supported in the flags field. there's a lot of them, and each one is a whole mood:

  • SDL_SWSURFACE โ€” surface is stored in system memory ๐Ÿง 
  • SDL_HWSURFACE โ€” surface is stored in video memory ๐ŸŽฎ
  • SDL_ASYNCBLIT โ€” surface uses asynchronous blits if possible โšก
  • SDL_ANYFORMAT โ€” allows any pixel-format (Display surface) ๐ŸŒˆ
  • SDL_HWPALETTE โ€” surface has exclusive palette ๐ŸŽจ
  • SDL_DOUBLEBUF โ€” surface is double buffered (Display surface) ๐Ÿชž
  • SDL_FULLSCREEN โ€” surface is full screen (Display Surface) ๐Ÿ–ฅ๏ธ
  • SDL_OPENGL โ€” surface has an OpenGL context (Display Surface) ๐Ÿ”บ
  • SDL_OPENGLBLIT โ€” surface supports OpenGL blitting (Display Surface) โœจ
  • SDL_RESIZABLE โ€” surface is resizable (Display Surface) โ†”๏ธ
  • SDL_HWACCEL โ€” surface blit uses hardware acceleration ๐ŸŽ๏ธ
  • SDL_SRCCOLORKEY โ€” surface use colorkey blitting ๐Ÿ”‘
  • SDL_RLEACCEL โ€” colorkey blitting is accelerated with RLE ๐Ÿ’จ
  • SDL_SRCALPHA โ€” surface blit uses alpha blending ๐Ÿซฅ
  • SDL_PREALLOC โ€” surface uses preallocated memory ๐Ÿ“ฆ
several of these are tagged (Display surface) or (Display Surface) โ€” that's not decoration, that's telling you they only apply to the display surface, iykyk ๐Ÿ‘‘

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

  • SDL_PixelFormat

and that's the page, bestie!! you ate that ๐Ÿ’… this was the SDL_Surface(3) page from the SDL API Reference, dated Tue 11 Sep 2001, 23:01 โ€” yes, an absolute icon from an absolute era, we stan a vintage queen ๐Ÿ‘‘๐Ÿซถ mwah, go lock your surface before you touch pixels, love u bye ๐ŸŽ€๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from