本文整理汇总了C++中SDL_SetColors函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_SetColors函数的具体用法?C++ SDL_SetColors怎么用?C++ SDL_SetColors使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_SetColors函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GraphicPlayerPixels
/**
** Change current color set to new player.
**
** FIXME: use function pointer here.
**
** @param player Pointer to player.
** @param sprite The sprite in which the colors should be changed.
*/
void GraphicPlayerPixels(CPlayer *player, const CGraphic *sprite)
{
Assert(PlayerColorIndexCount);
if (sprite->Surface->format->palette == NULL) {
// Cannot set the player colors when there is no palette.
return;
}
// Skip units whose color palette does not cover the indexes
// for the player color.
if (sprite->Surface->format->palette->ncolors < PlayerColorIndexStart + PlayerColorIndexCount) {
return;
}
SDL_LockSurface(sprite->Surface);
SDL_SetColors(sprite->Surface, player->UnitColors.Colors,
PlayerColorIndexStart, PlayerColorIndexCount);
if (sprite->SurfaceFlip) {
// The flipped surface is supposed to have a similar palette.
Assert(sprite->SurfaceFlip->format->palette->ncolors
== sprite->Surface->format->palette->ncolors);
SDL_SetColors(sprite->SurfaceFlip,
player->UnitColors.Colors, PlayerColorIndexStart, PlayerColorIndexCount);
}
SDL_UnlockSurface(sprite->Surface);
}
示例2: VID_SetIcon
static void VID_SetIcon (void)
{
SDL_Surface *icon;
SDL_Color color;
Uint8 *ptr;
int i, mask;
# include "xbm_icon.h"
icon = SDL_CreateRGBSurface(SDL_SWSURFACE, HOT_ICON_WIDTH, HOT_ICON_HEIGHT, 8, 0, 0, 0, 0);
if (icon == NULL)
return;
SDL_SetColorKey(icon, SDL_SRCCOLORKEY, 0);
color.r = 255;
color.g = 255;
color.b = 255;
SDL_SetColors(icon, &color, 0, 1); /* just in case */
color.r = 128;
color.g = 0;
color.b = 0;
SDL_SetColors(icon, &color, 1, 1);
ptr = (Uint8 *)icon->pixels;
for (i = 0; i < sizeof(HOT_ICON_bits); i++)
{
for (mask = 1; mask != 0x100; mask <<= 1)
{
*ptr = (HOT_ICON_bits[i] & mask) ? 1 : 0;
ptr++;
}
}
SDL_WM_SetIcon(icon, NULL);
SDL_FreeSurface(icon);
}
示例3: SDLGui_Init
/**
* Initialize the GUI.
*/
int SDLGui_Init(void)
{
SDL_Color blackWhiteColors[2] = {{255, 255, 255, 255}, {0, 0, 0, 255}};
if (pSmallFontGfx && pBigFontGfx)
{
/* already initialized */
return 0;
}
/* Initialize the font graphics: */
pSmallFontGfx = SDLGui_LoadXBM(font5x8_width, font5x8_height, font5x8_bits);
pBigFontGfx = SDLGui_LoadXBM(font10x16_width, font10x16_height, font10x16_bits);
if (pSmallFontGfx == NULL || pBigFontGfx == NULL)
{
fprintf(stderr, "Error: Can not init font graphics!\n");
return -1;
}
/* Set color palette of the font graphics: */
SDL_SetColors(pSmallFontGfx, blackWhiteColors, 0, 2);
SDL_SetColors(pBigFontGfx, blackWhiteColors, 0, 2);
/* Set font color 0 as transparent: */
SDL_SetColorKey(pSmallFontGfx, (SDL_SRCCOLORKEY|SDL_RLEACCEL), 0);
SDL_SetColorKey(pBigFontGfx, (SDL_SRCCOLORKEY|SDL_RLEACCEL), 0);
return 0;
}
示例4: SetSDLIcon
static void
SetSDLIcon()
{
#include "q2icon.xbm"
SDL_Surface *icon;
SDL_Color color;
Uint8 *ptr;
int i, mask;
icon = SDL_CreateRGBSurface(SDL_SWSURFACE, q2icon_width, q2icon_height, 8, 0, 0, 0, 0);
if (icon == NULL)
return; /* oh well... */
SDL_SetColorKey(icon, SDL_SRCCOLORKEY, 0);
color.r = 255;
color.g = 255;
color.b = 255;
SDL_SetColors(icon, &color, 0, 1); /* just in case */
color.r = 0;
color.g = 16;
color.b = 0;
SDL_SetColors(icon, &color, 1, 1);
ptr = (Uint8 *) icon->pixels;
for (i = 0; i < sizeof(q2icon_bits); i++) {
for (mask = 1; mask != 0x100; mask <<= 1) {
*ptr = (q2icon_bits[i] & mask) ? 1 : 0;
ptr++;
}
}
SDL_WM_SetIcon(icon, NULL);
SDL_FreeSurface(icon);
}
示例5: set_rgb_color
void set_rgb_color(byte co, byte r, byte g, byte b)
{
SDL_Color col;
col.r = (r << 2);
col.g = (g << 2);
col.b = (b << 2);
SDL_SetColors(real_screen, &col, co, 1);
SDL_SetColors(screen, &col, co, 1);
}
示例6: main
int main() {
SDL_Init(SDL_INIT_VIDEO);
SDL_Surface *screen = SDL_SetVideoMode(600, 400, 8, SDL_HWSURFACE | SDL_HWPALETTE);
//initialize sdl palette
//with red green and blue
//colors
SDL_Color pal[3];
pal[0].r = 255;
pal[0].g = 0;
pal[0].b = 0;
pal[0].unused = 0;
pal[1].r = 0;
pal[1].g = 255;
pal[1].b = 0;
pal[1].unused = 0;
pal[2].r = 0;
pal[2].g = 0;
pal[2].b = 255;
pal[2].unused = 0;
SDL_SetColors(screen, pal, 0, 3);
SDL_FillRect(screen, NULL, 0);
{
SDL_Rect rect = { 300, 0, 300, 200 };
SDL_FillRect(screen, &rect, 1);
}
{
SDL_Rect rect = { 0, 200, 600, 200 };
SDL_FillRect(screen, &rect, 2);
}
//changing green color
//to yellow
pal[1].r = 255;
SDL_SetColors(screen, &pal[1], 1, 1);
{
SDL_Rect rect = { 300, 200, 300, 200 };
SDL_FillRect(screen, &rect, 1);
}
printf("you should see red, blue and yellow rectangles\n");
SDL_Quit();
return 0;
}
示例7: SDL_CreateRGBSurface
bool CSprite::createSurface(Uint32 flags, SDL_Color *Palette)
{
mpSurface = SDL_CreateRGBSurface( flags, m_xsize, m_ysize, 8, 0, 0, 0, 0);
SDL_SetColors( mpSurface.get(), Palette, 0, 255);
SDL_SetColorKey( mpSurface.get(), SDL_SRCCOLORKEY, COLORKEY ); // One black is the color key. There is another black, as normal color
mpMasksurface = SDL_CreateRGBSurface( flags, m_xsize, m_ysize, 8, 0, 0, 0, 0);
SDL_SetColors( mpMasksurface.get(), Palette, 0, 255);
SDL_SetColorKey( mpMasksurface.get(), SDL_SRCCOLORKEY, COLORKEY ); // color key.
return ( mpSurface.empty() && mpMasksurface.empty() );
}
示例8: Vid_SetMode
static void Vid_SetMode()
{
int n;
int w, h;
int flags = 0;
printf("CGA Screen Emulation\n");
printf("init screen: ");
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("failed\n");
fprintf(stderr, "Unable to initialise video subsystem: %s\n",
SDL_GetError());
exit(-1);
}
srand(time(NULL));
set_icon(symbol_plane[rand() % 2][rand() % 16]);
w = SCR_WDTH;
h = SCR_HGHT;
if (vid_double_size) {
w *= 2;
h *= 2;
}
flags = SDL_HWPALETTE;
if (vid_fullscreen)
flags |= SDL_FULLSCREEN;
screen = SDL_SetVideoMode(w, h, 8, flags);
if (screen) {
printf("initialised\n");
} else {
printf("failed to set mode\n");
fprintf(stderr, "cant init SDL\n");
exit(-1);
}
SDL_EnableUNICODE(1);
for (n = 0; n < NUM_KEYS; ++n)
keysdown[n] = 0;
SDL_WM_SetCaption("SDL Sopwith", NULL);
SDL_SetColors(screen, cga_pal, 0, sizeof(cga_pal)/sizeof(*cga_pal));
SDL_SetColors(screenbuf, cga_pal, 0, sizeof(cga_pal)/sizeof(*cga_pal));
SDL_ShowCursor(0);
}
示例9: GraphicPlayerPixels
/**
** Change current color set to new player.
**
** FIXME: use function pointer here.
**
** @param player Pointer to player.
** @param sprite The sprite in which the colors should be changed.
*/
void GraphicPlayerPixels(CPlayer *player, const CGraphic *sprite)
{
Assert(PlayerColorIndexCount);
SDL_LockSurface(sprite->Surface);
SDL_SetColors(sprite->Surface, player->UnitColors.Colors,
PlayerColorIndexStart, PlayerColorIndexCount);
if (sprite->SurfaceFlip) {
SDL_SetColors(sprite->SurfaceFlip,
player->UnitColors.Colors, PlayerColorIndexStart, PlayerColorIndexCount);
}
SDL_UnlockSurface(sprite->Surface);
}
示例10: gr_refresh_palette
void gr_refresh_palette()
{
int n ;
if ( sys_pixel_format->depth > 8 )
{
if ( sys_pixel_format->palette )
{
for ( n = 0 ; n < 256 ; n++ )
{
sys_pixel_format->palette->colorequiv[ n ] = gr_map_rgb
(
sys_pixel_format,
sys_pixel_format->palette->rgb[ n ].r,
sys_pixel_format->palette->rgb[ n ].g,
sys_pixel_format->palette->rgb[ n ].b
) ;
}
}
}
else if ( sys_pixel_format->depth == 8 )
{
if ( sys_pixel_format->palette )
{
for ( n = 0 ; n < 256 ; n++ )
{
palette[ n ].r = sys_pixel_format->palette->rgb[ n ].r;
palette[ n ].g = sys_pixel_format->palette->rgb[ n ].g;
palette[ n ].b = sys_pixel_format->palette->rgb[ n ].b;
}
}
else
{
uint8_t * pal = default_palette;
for ( n = 0 ; n < 256 ; n++ )
{
palette[ n ].r = *pal++;
palette[ n ].g = *pal++;
palette[ n ].b = *pal++;
}
}
if ( scale_screen )
SDL_SetColors( scale_screen, palette, 0, 256 ) ;
else
SDL_SetColors( screen, palette, 0, 256 ) ;
}
palette_changed = 0;
trans_table_updated = 0 ;
}
示例11: SDL_SetColors
/* change FG/BG colors and transparency */
void GUI_TermWin::SetColoring(Uint8 fr,Uint8 fg,Uint8 fb, int bg_opaque,
Uint8 br, Uint8 bg, Uint8 bb)
{
SDL_Color colors[3]={{br,bg,bb,0},{fr,fg,fb,0}};
if (bg_opaque)
{
SDL_SetColors(font,colors,0,2);
SDL_SetColorKey(font,0,0);
}
else
{
SDL_SetColors(font,&colors[1],1,1);
SDL_SetColorKey(font,SDL_SRCCOLORKEY,0);
}
}
示例12: fb_open
int fb_open() {
int i;
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(LCD_WIDTH, LCD_HEIGHT, 8, SDL_SWSURFACE);
if (!screen) {
SDL_Quit();
printf ("Could not set 160x128x8 video mode: %s\n", SDL_GetError());
return 1;
}
/* set palette */
for (i = 0; i < 256; i+= 4) {
ipod_palette[i] = white;
ipod_palette[i + 1] = ltgrey;
ipod_palette[i + 2] = dkgrey;
ipod_palette[i + 3] = black;
}
SDL_SetColors(screen, ipod_palette, 0, 256);
SDL_ShowCursor(SDL_DISABLE);
return 0;
}
示例13: gr_palette_load
void gr_palette_load( ubyte *pal )
{
int i, j;
SDL_Palette *palette;
SDL_Color colors[256];
for (i=0; i<768; i++ ) {
gr_current_pal[i] = pal[i];
if (gr_current_pal[i] > 63) gr_current_pal[i] = 63;
}
palette = screen->format->palette;
if (palette == NULL) {
return; // Display is not palettised
}
for (i = 0, j = 0; j < 256; j++) {
//changed on 980913 by adb to fix palette problems
colors[j].r = (min(gr_current_pal[i++] + gr_palette_gamma, 63)) * 4;
colors[j].g = (min(gr_current_pal[i++] + gr_palette_gamma, 63)) * 4;
colors[j].b = (min(gr_current_pal[i++] + gr_palette_gamma, 63)) * 4;
//end changes by adb
}
SDL_SetColors(screen, colors, 0, 256);
gr_palette_faded_out = 0;
init_computed_colors();
}
示例14: native_updaterect
static int native_updaterect (SADisplay *display, VisRectangle *rect)
{
SDLNative *native = SDL_NATIVE (display->native);
SDL_Surface *sdlscreen = native->screen;
if (sdlscreen->format->BitsPerPixel == 8) {
SDL_Color colors[256];
VisPalette *pal = display->screen->pal;
visual_mem_set (colors, 0, sizeof (colors));
if (pal != NULL && pal->ncolors <= 256) {
int i;
for (i = 0; i < pal->ncolors; i++) {
colors[i].r = pal->colors[i].r;
colors[i].g = pal->colors[i].g;
colors[i].b = pal->colors[i].b;
}
SDL_SetColors (sdlscreen, colors, 0, 256);
}
}
if (native->requested_depth == VISUAL_VIDEO_DEPTH_GL)
SDL_GL_SwapBuffers ();
else
SDL_UpdateRect (sdlscreen, rect->x, rect->y, rect->width, rect->height);
return 0;
}
示例15: I_SetPalette
void I_SetPalette (byte* palette)
{
register int i;
register int c;
static boolean firstcall = true;
// TODO: add SDL mode check
{
// initialize the colormap
if (firstcall)
{
firstcall = false;
}
// set the X colormap entries
for (i=0 ; i<256 ; i++)
{
c = gammatable[usegamma][*palette++];
colors[i].r = (c<<8) + c;
c = gammatable[usegamma][*palette++];
colors[i].g = (c<<8) + c;
c = gammatable[usegamma][*palette++];
colors[i].b = (c<<8) + c;
}
// store the colors to the current colormap
SDL_SetColors(screen, colors, 0, 256);
}
}