'develop/SDL'에 해당되는 글 3건
- 2011.12.07 점 찍기
- 2011.03.16 [sdl] SDL_FillRect
- 2011.03.15 [sdl] SDL_MapRGB
점 찍기
develop/SDL 2011. 12. 7. 16:01
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;
}
}
{
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 |
[sdl] SDL_FillRect
develop/SDL 2011. 3. 16. 14:26
include "SDL.h"
int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color);
사각형에 색 채우기
return : success = 0, error = -1
ex)
// clear screen
SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0) );
int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color);
사각형에 색 채우기
return : success = 0, error = -1
ex)
// clear screen
SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0) );
'develop > SDL' 카테고리의 다른 글
점 찍기 (0) | 2011.12.07 |
---|---|
[sdl] SDL_MapRGB (0) | 2011.03.15 |
[sdl] SDL_MapRGB
develop/SDL 2011. 3. 15. 16:47
Uint32 SDL_MapRGB(SDL_PixelFormat *fmt, Uint8 r, Uint8 g, Uint8 b)
색을 만든다.
ex)
Uint32 yellow;
yellow = SDL_MapRGB(screen->format, 0xff, 0xff, 0x00);
색을 만든다.
ex)
Uint32 yellow;
yellow = SDL_MapRGB(screen->format, 0xff, 0xff, 0x00);
'develop > SDL' 카테고리의 다른 글
점 찍기 (0) | 2011.12.07 |
---|---|
[sdl] SDL_FillRect (0) | 2011.03.16 |