Beispiel #1
0
/**
 * Initialize the GUI.
 */
int SDLGui_Init(void)
{
	SDL_Color blackWhiteColors[2] = {{255, 255, 255, 0}, {0, 0, 0, 0}};

	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_SetPaletteColors(pSmallFontGfx->format->palette, blackWhiteColors, 0, 2);
	SDL_SetPaletteColors(pBigFontGfx->format->palette, blackWhiteColors, 0, 2);

	/* Set font color 0 as transparent: */
	SDL_SetColorKey(pSmallFontGfx, (SDL_TRUE|SDL_RLEACCEL), 0);
	SDL_SetColorKey(pBigFontGfx, (SDL_TRUE|SDL_RLEACCEL), 0);

	return 0;
}
Beispiel #2
0
// seg000:22C8
void __pascal far load_title_images(int bgcolor) {
	dat_type* dathandle;
	dathandle = open_dat("TITLE.DAT", 0);
	chtab_title40 = load_sprites_from_file(40, 1<<11, 1);
	chtab_title50 = load_sprites_from_file(50, 1<<12, 1);
	close_dat(dathandle);
	if (graphics_mode == gmMcgaVga) {
		// background of text frame
		SDL_Color color;
		if (bgcolor) {
			// RGB(4,0,18h) = #100060 = dark blue
			set_pal((find_first_pal_row(1<<11) << 4) + 14, 0x04, 0x00, 0x18, 1);
			color.r = 0x10;
			color.g = 0x00;
			color.b = 0x60;
			color.a = 0xFF;
		} else {
			// RGB(20h,0,0) = #800000 = dark red
			set_pal((find_first_pal_row(1<<11) << 4) + 14, 0x20, 0x00, 0x00, 1);
			color.r = 0x80;
			color.g = 0x00;
			color.b = 0x00;
			color.a = 0xFF;
		}
		if (NULL != chtab_title40) {
			SDL_SetPaletteColors(chtab_title40->images[0]->format->palette, &color, 14, 1);
		}
	} else if (graphics_mode == gmEga || graphics_mode == gmTga) {
		// ...
	}
}
SDL_Surface *sdl_surface_8bit_copy(SDL_Surface *src)
{
	Uint32 rmask,gmask,bmask,amask;
	SDL_Surface *out;

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
	rmask = 0xff000000;
	gmask = 0x00ff0000;
	bmask = 0x0000ff00;
	amask = 0x000000ff;
#else
	rmask = 0x000000ff;
	gmask = 0x0000ff00;
	bmask = 0x00ff0000;
	amask = 0xff000000;
#endif
	if (!src)
		return NULL;
	if (src->format->BitsPerPixel != 8)
		return NULL;

	out = SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 8,
			rmask, gmask, bmask, amask);
	if (!out)
		return NULL;
	memcpy(out->pixels, src->pixels, src->h * src->pitch);

	SDL_SetPaletteColors(out->format->palette, sdl_palette, 0, PALETTE_SIZE);

	return out;
}
Beispiel #4
0
/*
  Draw a text string.
*/
void SDLGui_Text(int x, int y, const char *txt, int col)
{
  int i;
  char c;
  SDL_Rect sr, dr;

#if SDL_VERSION_ATLEAST(2, 0, 0)
  SDL_SetPaletteColors(fontgfx->format->palette, &gui_palette[col], 1, 1);
#else
  SDL_SetColors(fontgfx, &gui_palette[col], 1, 1);
#endif

  for (i = 0 ; txt[i] != 0 ; i++)
  {
    c = txt[i];
    sr.x = fontwidth * (c % 16);
    sr.y = fontheight * (c / 16);
    sr.w = fontwidth;
    sr.h = fontheight;

    dr.x = x + (fontwidth * i);
    dr.y = y;
    dr.w = fontwidth;
    dr.h = fontheight;

    SDL_BlitSurface(fontgfx, &sr, sdlscrn, &dr);
  }
}
std::shared_ptr<SDL_Surface> CSprite::createCopySDLSurface(
        const std::shared_ptr<SDL_Surface>& original)
{
    std::shared_ptr<SDL_Surface> surface;

    if(original->format->BitsPerPixel < 16)
    {
        surface.reset(SDL_CreateRGBSurface( 0, m_xsize, m_ysize, 8, 0, 0, 0, 0), &SDL_FreeSurface);
#if SDL_VERSION_ATLEAST(2, 0, 0)
        SDL_SetPaletteColors(surface->format->palette, original->format->palette->colors, 0, 255);
        SDL_SetColorKey(surface.get(), SDL_TRUE, COLORKEY);
#else
        SDL_SetColors( surface.get(), original->format->palette->colors, 0, 255);
        SDL_SetColorKey( surface.get(), SDL_SRCCOLORKEY, COLORKEY ); // One black is the color key. There is another black, as normal color
#endif

        auto *origSfcPtr = original.get();

        SDL_FillRect( surface.get(), NULL, COLORKEY );
        SDL_BlitSurface( origSfcPtr, NULL, surface.get(), NULL);
    }
    else
    {
        surface.reset(SDL_ConvertSurface(original.get(),original->format,0));
    }

    return surface;
}
Beispiel #6
0
//-------- Begin of function SurfaceSDL::activate_pal ----------//
//
// Activate a palette to the current direct draw surface buffer.
//
int SurfaceSDL::activate_pal(SDL_Color *pal, int firstcolor, int ncolors)
{
	return SDL_SetPaletteColors(surface->format->palette,
				    pal,
				    firstcolor,
				    ncolors);
}
Beispiel #7
0
//
// SDLVideoDriver::FinishUpdate
//
// Push the newest frame to the display.
//
void SDLVideoDriver::FinishUpdate()
{
   // haleyjd 10/08/05: from Chocolate DOOM:
   UpdateGrab(window);

   // Don't update the screen if the window isn't visible.
   // Not doing this breaks under Windows when we alt-tab away 
   // while fullscreen.   
   if(!(SDL_GetWindowFlags(window) & SDL_WINDOW_SHOWN))
      return;

   if(setpalette)
   {
      if(primary_surface)
         SDL_SetPaletteColors(primary_surface->format->palette, colors, 0, 256);

      setpalette = false;
   }

   // haleyjd 11/12/09: blit *after* palette set improves behavior.
   if(primary_surface)
   {
      // Don't bother checking for errors. It should just cancel itself in that case.
      SDL_BlitSurface(primary_surface, nullptr, rgba_surface, nullptr);
      SDL_UpdateTexture(sdltexture, nullptr, rgba_surface->pixels, rgba_surface->pitch);
      SDL_RenderCopy(renderer, sdltexture, nullptr, destrect);
   }

   // haleyjd 11/12/09: ALWAYS update. Causes problems with some video surface
   // types otherwise.
   SDL_RenderPresent(renderer);
}
Beispiel #8
0
void osinterface_update_palette(char* colours, int start_index, int num_colours)
{
	SDL_Color base[256];
	SDL_Surface *surface;
	int i;

	surface = SDL_GetWindowSurface(_window);
	if (!surface) {
		RCT2_ERROR("SDL_GetWindowSurface failed %s", SDL_GetError());
		exit(1);
	}

	for (i = 0; i < 256; i++) {
		base[i].r = colours[2];
		base[i].g = colours[1];
		base[i].b = colours[0];
		base[i].a = 0;
		colours += 4;
	}

	if (SDL_SetPaletteColors(_palette, base, 0, 256)) {
		RCT2_ERROR("SDL_SetPaletteColors failed %s", SDL_GetError());
		exit(1);
	}
}
Beispiel #9
0
void EmuinoSDL::postsetup()
{
    TileLayerInfo layer_info;
    
    // set up the palettes
    for (int i = 0; i < NUM_PALETTES; i++) {
        palettes[i] = SDL_AllocPalette(NUM_PALETTE_ENTRIES);
        
        SDL_Color colors[NUM_PALETTE_ENTRIES];
        SharedRAM.read(PALETTE(i) | 0x8000, colors, NUM_PALETTE_ENTRIES * 4);
        
        for (int z = 0; z < NUM_PALETTE_ENTRIES; z++)
            colors[z].a = 255;
        
        SDL_SetPaletteColors(palettes[i], colors, 0, NUM_PALETTE_ENTRIES);
    }
    
    screenSurface = SDL_CreateRGBSurface(0, 320, 240, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
    screenTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, 320, 240);
    
    // create the tile textures
    for (int i = 0; i < NUM_TILE_LAYERS; i++) {
        tileMapSurfaces[i] = SDL_CreateRGBSurface(0, 32 * 16, 32 * 16, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
        tileMapTextures[i] = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 32 * 16, 32 * 16);
        SDL_SetTextureBlendMode(tileMapTextures[i], SDL_BLENDMODE_BLEND);
    }
    
    setup = true;
}
Beispiel #10
0
int SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors) {
	if (surface->format->palette) {
		return !SDL_SetPaletteColors(surface->format->palette, colors, firstcolor, ncolors) ? 1 : 0;
	} else {
		return 0;
	}
}
Beispiel #11
0
int display_init() {
	memset(&display, 0, sizeof(display));

	if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
		return 0;

	display.window = SDL_CreateWindow("Gamebuino",
			SDL_WINDOWPOS_UNDEFINED,
			SDL_WINDOWPOS_UNDEFINED,
			84*DISPLAY_SCALE_X, 48*DISPLAY_SCALE_Y, 0);
	if (display.window == NULL)
		return 0;

	display.renderer = SDL_CreateRenderer(display.window, -1,
			SDL_RENDERER_PRESENTVSYNC);

	display.texture = SDL_CreateTexture(display.renderer,
			SDL_PIXELFORMAT_RGB332,
			SDL_TEXTUREACCESS_STREAMING, 84, 48);
	if (display.texture == NULL)
		return 0;

	SDL_Surface* numbers_surface = SDL_CreateRGBSurfaceFrom((void*) numbers_bitmap,
			numbers_bitmap_width, numbers_bitmap_height, 1, numbers_bitmap_width / 8,
			0x80000000, 0x80000000, 0x80000000, 0xFFFFFFFF);
	SDL_Palette* palette = SDL_AllocPalette(2);
	SDL_SetPaletteColors(palette, numbers_palette_colors, 0, 2);
	SDL_SetSurfacePalette(numbers_surface, palette);
	display.numbers_texture = SDL_CreateTextureFromSurface(display.renderer, numbers_surface);
	if (display.numbers_texture == 0)
		return 0;
	SDL_FreeSurface(numbers_surface);

	return 1;
}
Beispiel #12
0
//update depth debug window
void VIZDepthBuffer::Update() {
    SDL_Surface* surf = SDL_CreateRGBSurfaceFrom(this->buffer, this->bufferWidth, this->bufferHeight, 8,
                                                 this->bufferWidth, 0, 0, 0, 0);
    SDL_SetPaletteColors(surf->format->palette, colors, 0, 256);
    SDL_BlitSurface(surf, NULL, this->surface, NULL);
    SDL_UpdateWindowSurface(this->window);
}
Beispiel #13
0
void vgainit(void)
{

	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
		fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
		exit(1);
	}

	SDL_Surface *tmp = NULL;

	tmp = SDL_CreateRGBSurfaceFrom(Icon, 64, 64, 8, 64, 0, 0, 0, 0);
	SDL_SetColorKey(tmp, SDL_TRUE, 247);
	SDL_SetPaletteColors(tmp->format->palette, IconPalette, 0, 256);

	sdlWindow = SDL_CreateWindow("D I G G E R",
                             SDL_WINDOWPOS_UNDEFINED,
                             SDL_WINDOWPOS_UNDEFINED,
                             0, 0,
                             SDL_WINDOW_OPENGL);
  if(sdlWindow == NULL)
	{
		fprintf(stderr, "Couldn't initialize SDL window: %s\n", SDL_GetError());
		exit(1);
	}
  SDL_SetWindowIcon(sdlWindow, tmp);

	sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, 0);
	if(sdlRenderer == NULL)
	{
		fprintf(stderr, "Couldn't initialize SDL renderer: %s\n", SDL_GetError());
		exit(1);
	}
	SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");  // make the scaled rendering look smoother.
	SDL_RenderSetLogicalSize(sdlRenderer, 640, 480);

	sdlTexture = SDL_CreateTexture(sdlRenderer,
                               SDL_PIXELFORMAT_ARGB8888,
                               SDL_TEXTUREACCESS_STREAMING,
                               640, 480);
	if(sdlTexture == NULL)
	{
		fprintf(stderr, "Couldn't initialize SDL texture: %s\n", SDL_GetError());
		exit(1);
	}
	screen = SDL_CreateRGBSurface(0, 640, 480, 8, 0, 0, 0, 0);
	helper = SDL_CreateRGBSurface(0, 640, 480, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);

	if(screen == NULL || helper == NULL)
	{
		fprintf(stderr, "Couldn't initialize SDL surface: %s\n", SDL_GetError());
		exit(1);
	}

	if(setmode() == false) {
		fprintf(stderr, "Couldn't set 640x480x8 video mode: %s\n", SDL_GetError());
		exit(1);
  }
	SDL_ShowCursor(0);
}
Beispiel #14
0
int
SDL_SetColors(SDL_Surface * surface, const SDL_Color * colors, int firstcolor,
              int ncolors)
{
    if (SDL_SetPaletteColors
        (surface->format->palette, colors, firstcolor, ncolors) == 0) {
        return 1;
    } else {
        return 0;
    }
}
Beispiel #15
0
SDL_Surface *ch2bmap(Uint3 *sprite, Sint4 w, Sint4 h)
{
	Sint4 realw, realh;
	SDL_Surface *tmp;

	realw = virt2scrw(w*4);
	realh = virt2scrh(h);
	tmp = SDL_CreateRGBSurfaceFrom(sprite, realw, realh, 8, realw, 0, 0, 0, 0);
	SDL_SetPaletteColors(tmp->format->palette, screen->format->palette->colors, 0, screen->format->palette->ncolors);
	return(tmp);
}
CFinaleStaticScene::CFinaleStaticScene(const std::string &game_path, const std::string &scene_file):
m_mustclose(false),
m_timer(0)
{
    mpSceneSurface.reset(SDL_CreateRGBSurface( 0, 320, 200, 8, 0, 0, 0, 0),
                         &SDL_FreeSurface);

#if SDL_VERSION_ATLEAST(2, 0, 0)
    SDL_SetPaletteColors(mpSceneSurface->format->palette, g_pGfxEngine->Palette.m_Palette, 0, 255);
    SDL_SetColorKey(mpSceneSurface.get(), SDL_TRUE, COLORKEY);
#else
    SDL_SetColors(mpSceneSurface.get(), g_pGfxEngine->Palette.m_Palette, 0, 255);
    SDL_SetColorKey(mpSceneSurface.get(), SDL_SRCCOLORKEY, COLORKEY);
#endif

    if( finale_draw( mpSceneSurface.get(), scene_file, game_path) )
	{
#if SDL_VERSION_ATLEAST(2, 0, 0)
        
#else
        mpSceneSurface.reset(g_pVideoDriver->convertThroughBlitSfc(mpSceneSurface.get()), &SDL_FreeSurface);
#endif

        SDL_Surface *blit = g_pVideoDriver->getBlitSurface();

        std::shared_ptr<SDL_Surface> scaledScene(
                    SDL_ConvertSurface(blit, blit->format, 0),
                    &SDL_FreeSurface);


        SDL_Rect srcRect, dstRect;

        srcRect.x = 0;  srcRect.y = 0;
        srcRect.w = mpSceneSurface->w;
        srcRect.h = mpSceneSurface->h;

        dstRect.x = 0;  dstRect.y = 0;
        dstRect.w = scaledScene->w;
        dstRect.h = scaledScene->h;

        SDL_FillRect(scaledScene.get(), nullptr, SDL_MapRGB(scaledScene->format, 0, 0, 0) );

        SDL_BlitScaledWrap(mpSceneSurface.get(),
                           &srcRect,
                           scaledScene.get(),
                           &dstRect);

        mpSceneSurface = scaledScene;
    }
	else
	{
		m_mustclose = true;
    }
}
Beispiel #17
0
//
// I_SDLSetPaletteDirect
//
// haleyjd 11/12/09: make sure surface palettes are set at startup.
//
static void I_SDLSetPaletteDirect(byte *palette)
{
   for(int i = 0; i < 256; i++)
   {
      colors[i].r = gammatable[usegamma][(basepal[i].r = *palette++)];
      colors[i].g = gammatable[usegamma][(basepal[i].g = *palette++)];
      colors[i].b = gammatable[usegamma][(basepal[i].b = *palette++)];
   }

   if(primary_surface)
      SDL_SetPaletteColors(primary_surface->format->palette, colors, 0, 256);
}
Beispiel #18
0
bool CSprite::createSurface(Uint32 flags, SDL_Color *Palette)
{        
	mpSurface.reset(SDL_CreateRGBSurface( flags, m_xsize, m_ysize, 8, 0, 0, 0, 0), &SDL_FreeSurface);
#if SDL_VERSION_ATLEAST(2, 0, 0)
    SDL_SetPaletteColors(mpSurface->format->palette, Palette, 0, 255);
    SDL_SetColorKey(mpSurface.get(), SDL_TRUE, COLORKEY);
#else
    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
#endif

	mpMasksurface.reset(SDL_CreateRGBSurface( flags, m_xsize, m_ysize, 8, 0, 0, 0, 0), &SDL_FreeSurface);
#if SDL_VERSION_ATLEAST(2, 0, 0)
    SDL_SetPaletteColors(mpMasksurface->format->palette, Palette, 0, 255);
    SDL_SetColorKey(mpMasksurface.get(), SDL_TRUE, COLORKEY);
#else
    SDL_SetColors( mpMasksurface.get(), Palette, 0, 255);
	SDL_SetColorKey( mpMasksurface.get(), SDL_SRCCOLORKEY, COLORKEY ); // color key.
#endif
	
	return ( !mpSurface && !mpMasksurface );
}
Beispiel #19
0
// if sfc is an 8bpp paletted surface, change color index 'oldcolor' to be newcolor.
// if sfc is a 16bpp surface, replace all instances of color 'oldcolor' with 'newcolor'
void NXFont::ReplaceColor(SDL_Surface *sfc, uint32_t oldcolor, uint32_t newcolor)
{
	#ifndef __SDLSHIM__
	if (sfc->format->BitsPerPixel == 8)
	{
		SDL_Color desired;
		
		desired.r = (newcolor >> 16) & 0xff;
		desired.g = (newcolor >> 8) & 0xff;
		desired.b = (newcolor & 0xff);
		
		SDL_SetPaletteColors(sfc->format->palette, &desired, oldcolor, 1);
	}
void vga_setpalette(unsigned char* palette)
{
	SDL_Color colors[256];
	int i;
	for(i=0; i<256; i++)
	{
		colors[i].r = palette[0];
		colors[i].g = palette[1];
		colors[i].b = palette[2];
		palette += 3;
	}
	if(!screenPalette) screenPalette = SDL_AllocPalette(256);
	SDL_SetPaletteColors(screenPalette, colors, 0, 256);
}
Beispiel #21
0
static int
SW_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
                     const SDL_Color * colors, int firstcolor, int ncolors)
{
    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
        SDL_SetError("YUV textures don't have a palette");
        return -1;
    } else {
        SDL_Surface *surface = (SDL_Surface *) texture->driverdata;

        return SDL_SetPaletteColors(surface->format->palette, colors,
                                    firstcolor, ncolors);
    }
}
Beispiel #22
0
static void VL_SDL2_RefreshPaletteAndBorderColor(void *screen)
{
	SDL_Surface *surf = (SDL_Surface *)screen;
	static SDL_Color sdl2_palette[16];

	for (int i = 0; i < 16; i++)
	{
		sdl2_palette[i].r = VL_EGARGBColorTable[vl_emuegavgaadapter.palette[i]][0];
		sdl2_palette[i].g = VL_EGARGBColorTable[vl_emuegavgaadapter.palette[i]][1];
		sdl2_palette[i].b = VL_EGARGBColorTable[vl_emuegavgaadapter.palette[i]][2];
	}
	SDL_SetPaletteColors(vl_sdl2_palette, sdl2_palette, 0, 16);
	SDL_SetSurfacePalette(surf, vl_sdl2_palette);
}
Beispiel #23
0
void SDLImageLoader::init(Point SpriteSize, Point Margins, Point FullSize, SDL_Color *pal)
{
	//Init image
	image->surf = SDL_CreateRGBSurface(SDL_SWSURFACE, SpriteSize.x, SpriteSize.y, 8, 0, 0, 0, 0);
	image->margins  = Margins;
	image->fullSize = FullSize;

	//Prepare surface
	SDL_Palette * p = SDL_AllocPalette(256);
	SDL_SetPaletteColors(p, pal, 0, 256);
	SDL_SetSurfacePalette(image->surf, p);
	SDL_FreePalette(p);

	SDL_LockSurface(image->surf);
	lineStart = position = (ui8*)image->surf->pixels;
}
Beispiel #24
0
/*****************************************************************************

		Function: osd_gfx_set_color

		Description: Change the component of the choosen color
		Parameters: uchar index : index of the color to change
					uchar r	: new red component of the color
								uchar g : new green component of the color
								uchar b : new blue component of the color
		Return:

*****************************************************************************/
void
osd_gfx_set_color(uchar index, uchar r, uchar g, uchar b)
{
	SDL_Color R;

	r <<= 2;
	g <<= 2;
	b <<= 2;

	R.r = r;
	R.g = g;
	R.b = b;

	SDL_SetPaletteColors(screen->format->palette,
		&R, 0, 1);
}
Beispiel #25
0
  TexturePrivate(Renderer &renderer, Sprite &sprite, Palette &palette) : src_rect_(0,0,8,8), dst_rect_(0,0,8,8){
    SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(sprite.data(), sprite.width(), sprite.height(), 8, sprite.width(), 0, 0, 0, 0);

    SDL_Color colours[4];
    for(int i = 0; i < 4; i++){
      colours[i].a = palette[i].a;
      colours[i].r = palette[i].r;
      colours[i].g = palette[i].g;
      colours[i].b = palette[i].b;
    }

    SDL_SetPaletteColors(surface->format->palette, colours, 0, 4);
    texture_ = SDL_CreateTextureFromSurface(renderer.rawRenderer(), surface);
    if(texture_ == nullptr){
      throw std::runtime_error("SDL_CreateTextureFromSurface failed: " + std::string(SDL_GetError()));
    }
    SDL_FreeSurface(surface);
  }
Beispiel #26
0
static void osinterface_update_palette(char* colours, int start_index, int num_colours)
{
	SDL_Color base[256];
	SDL_Surface *surface;
	int i;

	surface = SDL_GetWindowSurface(_window);

	for (i = 0; i < 256; i++) {
		base[i].r = colours[2];
		base[i].g = colours[1];
		base[i].b = colours[0];
		base[i].a = 0;
		colours += 4;
	}

	SDL_SetPaletteColors(_palette, base, 0, 256);
}
Beispiel #27
0
static SDL_Surface *
create_surface_from_data(void *data, int width, int height, int transparent) {
	int r;

	/* Create sprite surface */
	SDL_Surface *surf8 =
	SDL_CreateRGBSurfaceFrom(data, (int)width, (int)height, 8,
				 (int)(width*sizeof(uint8_t)), 0, 0, 0, 0);
	if (surf8 == NULL) {
		LOGE("sdl-video", "Unable to create sprite surface: %s.",
		     SDL_GetError());
		exit(EXIT_FAILURE);
	}

	/* Set sprite palette */
	r = SDL_SetPaletteColors(surf8->format->palette, pal_colors, 0, 256);
	if (r < 0) {
		LOGE("sdl-video", "Unable to set palette for sprite.");
		exit(EXIT_FAILURE);
	}

	/* Covert to screen format */
	SDL_Surface *surf = NULL;

	if (transparent) {
		/* Set color key */
		r = SDL_SetColorKey(surf8, SDL_TRUE, 0);
		if (r < 0) {
			LOGE("sdl-video", "Unable to set color key for sprite.");
			exit(EXIT_FAILURE);
		}
	}

	surf = SDL_ConvertSurface(surf8, screen.surf->format, 0);
	if (surf == NULL) {
		LOGE("sdl-video", "Unable to convert sprite surface: %s.",
		     SDL_GetError());
		exit(EXIT_FAILURE);
	}

	SDL_FreeSurface(surf8);

	return surf;
}
Beispiel #28
0
bool GsTilemap::CreateSurface(SDL_Color *Palette, Uint32 Flags,
				Uint16 numtiles, Uint16 pbasesize, Uint16 column)
{
	m_numtiles = numtiles;
	m_pbasesize = pbasesize;
	m_column = column;
    m_Tilesurface = SDL_CreateRGBSurface(Flags, m_column<<m_pbasesize,
                                        (m_numtiles/m_column)<<m_pbasesize, 8, 0, 0, 0, 0);

#if SDL_VERSION_ATLEAST(2, 0, 0)
    SDL_SetPaletteColors(m_Tilesurface->format->palette, Palette, 0, 255);
    SDL_SetColorKey(m_Tilesurface, SDL_TRUE, COLORKEY);
#else
    SDL_SetColors(m_Tilesurface, Palette, 0, 255);
	SDL_SetColorKey(m_Tilesurface, SDL_SRCCOLORKEY, COLORKEY);
#endif
	
	return ( m_Tilesurface != NULL );
}
Beispiel #29
0
void vgageti(Sint4 x, Sint4 y, Uint3 *p, Sint4 w, Sint4 h)
{
	SDL_Surface *tmp;
	SDL_Rect src;

	memcpy(&tmp, p, (sizeof (SDL_Surface *)));
	if (tmp != NULL)
		SDL_FreeSurface(tmp); /* Destroy previously allocated bitmap */

	src.x = virt2scrx(x);
	src.y = virt2scry(y);
	src.w = virt2scrw(w*4);
	src.h = virt2scrh(h);

	tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, src.w, src.h, 8, 0, 0, 0, 0);
	SDL_SetPaletteColors(tmp->format->palette, screen->format->palette->colors, 0, screen->format->palette->ncolors);
	SDL_BlitSurface(screen, &src, tmp, NULL);
	memcpy(p, &tmp, (sizeof (SDL_Surface *)));
}
///
// Creation Routines
///
bool GsBitmap::createSurface(Uint32 flags, SDL_Rect rect, SDL_Color *Palette)
{        
    mpBitmapSurface.reset( SDL_CreateRGBSurface(flags, rect.w, rect.h, 8, 0, 0, 0, 0 ), &SDL_FreeSurface );

    auto bmpSfc = mpBitmapSurface.get();

#if SDL_VERSION_ATLEAST(2, 0, 0)   
    SDL_SetPaletteColors(bmpSfc->format->palette, Palette, 0, 255);
    SDL_SetColorKey(bmpSfc, SDL_TRUE, COLORKEY);
#else
    SDL_SetColors(bmpSfc, Palette, 0, 255);
    SDL_SetColorKey(bmpSfc, SDL_SRCCOLORKEY, COLORKEY);
#endif


    if(mpBitmapSurface)
	  return true;
	else
	  return false;
}