'DrawPixel'에 해당되는 글 1건

  1. 2011.12.07 점 찍기

점 찍기

void DrawPixel(SDL_Surface *dst, Uint32 x, Uint32 y, Uint8 R, Uint8 G, Uint8 B)
{
    Uint32 color = SDL_MapRGB(dst->format, R, G, B);

    switch( dst->format->BytesPerPixel )
    {
        case 1: // Assuming 8-bpp
            {
                Uint8 *bufp;
                bufp = (Uint8 *)dst->pixels + y * dst->pitch + x;
                *bufp = color;
            }
            break;

        case 2: // probably 15-bpp or 16-bpp
            {
                Uint16 *bufp;
                bufp = (Uint16 *)dst->pixels + y * dst->pitch/2 + x;
                *bufp = color;
            }
            break;

        case 3: // slow 24-bpp mode, usually not used
            {
                Uint8 *bufp;
                bufp = (Uint8 *)dst->pixels + y * dst->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: // probably 32-bpp
            {
                Uint32 *bufp;
                bufp = (Uint32 *)dst->pixels + y * dst->pitch/4 + x;
                *bufp = color;
            }
            break;
    }

}


'develop > SDL' 카테고리의 다른 글

[sdl] SDL_FillRect  (0) 2011.03.16
[sdl] SDL_MapRGB  (0) 2011.03.15
prev 1 next