mirror of
https://github.com/spiffcode/hostile-takeover.git
synced 2026-06-10 23:04:59 -06:00
SdlAnimSprite update for 32bpp
This commit is contained in:
parent
bda2e4a4ab
commit
5e927f2ccd
@ -11,7 +11,6 @@ SdlAnimSprite::SdlAnimSprite(SpriteManager *psprm) {
|
||||
cy_ = 0;
|
||||
xOrigin_ = 0;
|
||||
yOrigin_ = 0;
|
||||
texture_ = NULL;
|
||||
surface_ = NULL;
|
||||
nScale_ = 1.0f;
|
||||
x_ = 0;
|
||||
@ -24,9 +23,6 @@ SdlAnimSprite::~SdlAnimSprite() {
|
||||
psprm_->Remove(this);
|
||||
|
||||
crit_.Enter();
|
||||
SDL_DestroyTexture(texture_);
|
||||
texture_ = NULL;
|
||||
SDL_FreeSurface(surface_);
|
||||
surface_ = NULL;
|
||||
crit_.Leave();
|
||||
}
|
||||
@ -77,60 +73,11 @@ bool SdlAnimSprite::CreateSurface(UnitGob *pgob) {
|
||||
xOrigin_ = rcAni.left;
|
||||
yOrigin_ = rcAni.top;
|
||||
|
||||
// Alloc the 8bpp buffer.
|
||||
int cp = cx_ * cy_;
|
||||
byte *pb8 = new byte[cp];
|
||||
if (pb8 == NULL) {
|
||||
// Create the surface
|
||||
surface_ = CreateDibBitmap(NULL, cx_, cy_, true);
|
||||
if (surface_ == NULL)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Draw the animation into an 8 bit DibBitmap
|
||||
// The 8->32 conversion palette has been tweaked so that 255
|
||||
// will map to RGBA transparent on output.
|
||||
|
||||
DibBitmap bm;
|
||||
bm.Init(pb8, cx_, cy_);
|
||||
memset(pb8, 255, cp);
|
||||
|
||||
// Subvert the TBitmap shdowing to our purpose.
|
||||
// The background is 255. Force TBitmap shadowing to turn this into 254.
|
||||
// 254 has been to RGBA color with appropriate alpha, when the 8->32bpp
|
||||
// conversion occurs.
|
||||
|
||||
byte bSav = gmpiclriclrShadow[255];
|
||||
gmpiclriclrShadow[255] = 254;
|
||||
pgob->DrawAnimation(&bm, -xOrigin_, -yOrigin_);
|
||||
gmpiclriclrShadow[255] = bSav;
|
||||
|
||||
// Alloc the 32bpp buffer.
|
||||
dword *pdw32 = new dword[cp];
|
||||
if (pdw32 == NULL) {
|
||||
delete[] pb8;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Convert to 32bpp. Sdl will rotate at draw time.
|
||||
byte *pbT = pb8;
|
||||
dword *pdwT = pdw32;
|
||||
int cpT = cp;
|
||||
while (cpT-- != 0) {
|
||||
*pdwT++ = mp8bpp32bpp_[*pbT++];
|
||||
}
|
||||
delete[] pb8;
|
||||
|
||||
// Create the appropriate masks
|
||||
|
||||
dword rmask = 0xff000000;
|
||||
dword gmask = 0x00ff0000;
|
||||
dword bmask = 0x0000ff00;
|
||||
dword amask = 0x000000ff;
|
||||
|
||||
surface_ = SDL_CreateRGBSurfaceFrom(pdw32, cx_, cy_, 32, (cx_ * sizeof(dword)), bmask, gmask, rmask, amask);
|
||||
|
||||
if (surface_ == NULL) {
|
||||
delete[] pdw32;
|
||||
return false;
|
||||
}
|
||||
pgob->DrawAnimation(surface_, -xOrigin_, -yOrigin_);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -159,10 +106,13 @@ void SdlAnimSprite::Draw(void *pv, Size *psiz) {
|
||||
|
||||
if (surface_ != NULL) {
|
||||
// Create a texture from the surface
|
||||
texture_ = SDL_CreateTextureFromSurface((SDL_Renderer *)pv, surface_);
|
||||
SDL_Texture *texture = SDL_CreateTextureFromSurface((SDL_Renderer *)pv, surface_->GetSurface());
|
||||
|
||||
// Render the texture
|
||||
SDL_RenderCopy((SDL_Renderer *)pv, texture_, NULL, &rc);
|
||||
SDL_RenderCopy((SDL_Renderer *)pv, texture, NULL, &rc);
|
||||
|
||||
// Destroy
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
|
||||
crit_.Leave();
|
||||
|
||||
@ -44,10 +44,8 @@ private:
|
||||
dword hash_;
|
||||
int cx_, cy_;
|
||||
int xOrigin_, yOrigin_;
|
||||
SDL_Texture *texture_;
|
||||
SDL_Surface *surface_;
|
||||
DibBitmap *surface_;
|
||||
SpriteManager *psprm_;
|
||||
dword mp8bpp32bpp_[256];
|
||||
float nScaleStart_, nScaleEnd_;
|
||||
long msAnimateStart_;
|
||||
dword cmsAnimate_;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user