浏览代码

More correct usage of SDL_Palette

AlexVinS 10 年之前
父节点
当前提交
28087099b8
共有 2 个文件被更改,包括 10 次插入7 次删除
  1. 5 6
      client/CDefHandler.cpp
  2. 5 1
      client/gui/CAnimation.cpp

+ 5 - 6
client/CDefHandler.cpp

@@ -174,13 +174,12 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const SDL_Co
 
 	BaseOffset += sizeof(SSpriteDef);
 	int BaseOffsetor = BaseOffset;
-
-	if(SDL_SetPaletteColors(ret->format->palette,palette,0,256) != 0)
-	{
-		logGlobal->errorStream() << __FUNCTION__ <<": Unable to set palette";
-		logGlobal->errorStream() << SDL_GetError();		
-	}
 	
+	SDL_Palette * p = SDL_AllocPalette(256);	
+	SDL_SetPaletteColors(p, palette, 0, 256);
+	SDL_SetSurfacePalette(ret, p);
+	SDL_FreePalette(p);	
+
 	int ftcp=0;
 
 	// If there's a margin anywhere, just blank out the whole surface.

+ 5 - 1
client/gui/CAnimation.cpp

@@ -355,7 +355,11 @@ void SDLImageLoader::init(Point SpriteSize, Point Margins, Point FullSize, SDL_C
 	image->fullSize = FullSize;
 
 	//Prepare surface
-	SDL_SetColors(image->surf, pal, 0, 256);
+	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;
 }