Simple DirectMedia Layer



( )

!

#1:

, , SDL_GetVideoInfo().

#2:

, SDL_ListModes().

:

 { SDL_Surface *screen;  screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE); if ( screen == NULL ) {// fprintf(stderr, " 640x480: %s\n", SDL_GetError()); exit(1); }}

  • (pixels)

.

:

, (lock) , , , , (unlock) .

:

 void DrawPixel(SDL_Surface *screen, Uint8 R, Uint8 G, Uint8 B){ Uint32 color = SDL_MapRGB(screen->format, R, G, B);  if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { return; } } // , (bytes per pixel, bpp) switch (screen->format->BytesPerPixel) { case 1: { /* 8-bpp */ Uint8 *bufp;  bufp = (Uint8 *)screen->pixels + y*screen->pitch + x; *bufp = color; } breakcase 2: { /* 15-bpp 16-bpp */ Uint16 *bufp;  bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x; *bufp = color; } breakcase 3: { /* 24-bpp , */ Uint8 *bufp;  bufp = (Uint8 *)screen->pixels + y*screen->pitch + x; *(bufp+screen->format->Rshift/8) = R; *(bufp+screen->format->Gshift/8) = G; *(bufp+screen->format->Bshift/8) = B; } breakcase 4: { /* , 32-bpp */ Uint32 *bufp;  bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x; *bufp = color; } break; } if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } SDL_UpdateRect(screen, x, y, 1, 1);}

<