[ÀÌÀü] ¸ñÂ÷ [´ÙÀ½]

Simple DirectMedia Layer API »ç¿ëÇϱâ

ºñµð¿À(Video)

  • ºñµð¿À ¸ðµåÀÇ ¼±Åðú ¼³Á¤ (½¬¿î¹æ¹ý)

    ¿©·¯ºÐÀÇ ¸¾¿¡ µå´Â bit-depth ¿Í Çػ󵵸¦ ¼±ÅÃÇÏ¿© ¼³Á¤ÇÑ´Ù!

ÆÁ #1:
SDL_GetVideoInfo() ÇÔ¼ö¸¦ »ç¿ëÇؼ­ Çϵå¿þ¾î¿¡ ÀÇÇØ Áö¿øµÇ´Â °¡Àå ºü¸¥ ºñµð¿À depth ¸¦ ¾òÀ» ¼ö ÀÖ´Ù.

ÆÁ #2:
SDL_ListModes() ÇÔ¼ö¸¦ »ç¿ëÇؼ­ ƯÁ¤ bit-depth ÇÏ¿¡ Áö¿øµÇ´Â ºñµð¿À ÇØ»óµµÀÇ ¸ñ·ÏÀ» ¾òÀ» ¼ö ÀÖ´Ù.

¿¹Á¦:
{ SDL_Surface *screen;

    screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE);
    if ( screen == NULL ) {
        fprintf(stderr, "Unable to set 640x480 video: %s\n", SDL_GetError());
        exit(1);
    }
}
  • È­¸é¿¡ Á¡Âï±â

    È­¸é¿¡ ±×¸®´Â ÀÛ¾÷Àº ±×·¡ÇÈ ÇÁ·¹ÀÓ¹öÆÛ¿¡ Á÷Á¢ ¾´µÚ È­¸é °»½Å ÇÔ¼ö¸¦ È£ÃâÇÔÀ¸·Î½á ¼öÇàµÈ´Ù.

ÆÁ:
¸¸¾à È­¸é¿¡ ±×¸± °ÍÀÌ ¸¹´Ù¸é, ±×¸®±â Àü¿¡ (ÇÊ¿äÇÏ´Ù¸é) È­¸éÀ» Çѹø Àá±×°í °»½ÅµÉ ¿µ¿ªÀÇ ¸ñ·ÏÀ» À¯ÁöÇÏ´Ù°¡ µð½ºÇ÷¹À̸¦ °»½ÅÇϱâ Àü¿¡ ´Ù½Ã È­¸éÀ» Ǫ´Â °ÍÀÌ °¡Àå ÁÁÀº ¹æ¹ýÀÌ´Ù.
¿¹Á¦:

¹«ÀÛÀ§ Æ÷¸ËÀÇ È­¸é¿¡ Á¡Âï±â

#include <SDL_endian.h>	/* ¿£µð¾È-Á¾¼ÓÀûÀÎ 24 bpp ¸ðµå¸¦ À§ÇØ »ç¿ë */

void DrawPixel(SDL_Surface *screen, int x, int y, 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;
        }
    }
    switch (screen->format->BytesPerPixel) {
        case 1: { /* 8-bpp ¶ó°í °¡Á¤ */
            Uint8 *bufp;

            bufp = (Uint8 *)screen->pixels + y*screen->pitch + x;
            *bufp = color;
        }
        break;

        case 2: { /* ¾Æ¸¶ 15-bpp ¾Æ´Ï¸é 16-bpp */
            Uint16 *bufp;

            bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x;
            *bufp = color;
        }
        break;

        case 3: { /* ´À¸° 24-bpp mode, º¸Åë »ç¿ëµÇÁö ¾Ê´Â´Ù */
            Uint8 *bufp;

            bufp = (Uint8 *)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: { /* ¾Æ¸¶ 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);
}
  • À̹ÌÁöÀÇ ·Îµù°ú µð½ºÇ÷¹ÀÌ

    SDLÀº »ç¿ëÀÚ ÆíÀǸ¦ À§ÇÑ SDL_LoadBMP() À̶ó´Â ÇϳªÀÇ À̹ÌÁö ·Îµù ·çƾÀ» Á¦°øÇÑ´Ù. À̹ÌÁö ·ÎµùÀ» À§ÇÑ ¶óÀ̺귯¸®´Â SDL µ¥¸ð ¸ðÀ½¿¡¼­ ¹ß°ßÇÒ ¼ö ÀÖ´Ù.

    SDL_BlitSurface() ¸¦ »ç¿ëÇؼ­ ±×·¡ÇÈ ÇÁ·¹ÀÓ¹öÆÛ·Î À̹ÌÁö¸¦ blit Çϸé È­¸é¿¡ µð½ºÇ÷¹ÀÌÇÒ ¼ö ÀÖ´Ù. SDL_BlitSurface() ´Â ÀÚµ¿ÀûÀ¸·Î blit »ç°¢ÇüÀ» Ŭ¸³(clip)Çϴµ¥, ÀÌ blit »ç°¢ÇüÀº SDL_BlitSurface()¿¡ ³Ñ°ÜÁ® ¹Ù²ï È­¸éÀÇ ¿µ¿ªÀÌ °»½ÅµÇµµ·Ï ÇÑ´Ù.

ÆÁ #1:
¸¸¾à ¿©·¯¹ø ±×·ÁÁú À̹ÌÁö¸¦ ·ÎµùÇÏ·Á¸é, À̹ÌÁö¸¦ ½ºÅ©¸°ÀÇ Æ÷¸ËÀ¸·Î º¯È¯ÇÏ¿© blit ¼Óµµ¸¦ Çâ»ó½Ãų ¼ö ÀÖ´Ù. SDL_DisplayFormat() ÇÔ¼ö°¡ ÀÌ·¯ÇÑ º¯È¯À» ÇØ ÁØ´Ù.

ÆÁ #2:
¸¹Àº ½ºÇÁ¶óÀÌÆ® À̹ÌÁöµéÀº Åõ¸íÇÑ ¹è°æÀ» °¡Áø´Ù. SDL_SetColorKey() ÇÔ¼ö¸¦ »ç¿ëÇؼ­ Åõ¸íÇÑ blit(Ä÷¯Å° blit)À» ÇÒ ¼ö ÀÖ´Ù.

¿¹Á¦:
void ShowBMP(char *file, SDL_Surface *screen, int x, int y)
{
    SDL_Surface *image;
    SDL_Rect dest;

    /* BMP ÆÄÀÏÀ» ¼­ÆäÀ̽º·Î ÀоîµéÀÓ */
    image = SDL_LoadBMP(file);
    if ( image == NULL ) {
        fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
        return;
    }

    /* È­¸é ¼­ÆäÀ̽º¿¡ Blit.
       ¼­ÆäÀ̽º´Â ÀÌ ½ÃÁ¡¿¡¼­ Àá±ÅÁ®ÀÖÁö ¾Ê¾Æ¾ß ÇÑ´Ù. */
    dest.x = x;
    dest.y = y;
    dest.w = image->w;
    dest.h = image->h;
    SDL_BlitSurface(image, NULL, screen, &dest);

    /* È­¸éÀÇ º¯È­µÈ ºÎºÐÀ» °»½Å */
    SDL_UpdateRects(screen, 1, &dest);

    SDL_FreeSurface(image);
}

[ÀÌÀü] ¸ñÂ÷ [´ÙÀ½]