head outfit color fix

This commit is contained in:
Eduardo Bart 2011-08-19 09:49:29 -03:00
parent 66e58c5914
commit 817234a660
5 changed files with 23 additions and 37 deletions

View File

@ -7,4 +7,4 @@ Color Color::red (0xFF, 0x00, 0x00, 0xFF);
Color Color::green (0x00, 0xFF, 0x00, 0xFF);
Color Color::blue (0x00, 0x00, 0xFF, 0xFF);
Color Color::pink (0xFF, 0x00, 0xFF, 0xFF);
Color Color::yellow(0x00, 0xFF, 0xFF, 0xFF);
Color Color::yellow(0xFF, 0xFF, 0x00, 0xFF);

View File

@ -4,10 +4,6 @@
#include <framework/graphics/framebuffer.h>
#include "game.h"
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
Creature::Creature() : Thing(THING_CREATURE)
{
m_healthPercent = 0;
@ -22,9 +18,6 @@ void Creature::draw(int x, int y)
// draw outfit
internalDraw(x, y, 0, m_direction, 0, 0, anim);
// draw outfit colors
glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
// TODO: move this shit hahaha
static const Color outfitColors[] = {
Color(255,255,255),

View File

@ -88,7 +88,7 @@ TexturePtr SpriteManager::loadSprite(int id)
return TexturePtr(new Texture(32, 32, 4, pixels));
}
TexturePtr SpriteManager::getSpriteTexture(int id)
TexturePtr SpriteManager::getSpriteTexture(int id, SpriteMask mask)
{
if(id == 0)
return g_graphics.getEmptyTexture();
@ -105,30 +105,28 @@ TexturePtr SpriteManager::getSpriteTexture(int id)
//TODO: release unused sprites textures after X seconds
// to avoid massive texture allocations
return texture;
}
if(mask != SpriteMaskNone) {
auto pixels = texture->getPixels();
TexturePtr SpriteManager::getSpriteMask(int id, SpriteMask mask)
{
TexturePtr tex = getSpriteTexture(id);
auto pixels = tex->getPixels();
static RGBA maskColors[4] = { Color::red.rgba(), Color::green.rgba(), Color::blue.rgba(), Color::yellow.rgba() };
RGBA maskColor = maskColors[mask];
RGBA whiteColor = Color::white.rgba();
RGBA alphaColor = Color::alpha.rgba();
static RGBA maskColors[4] = { Color::red.rgba(), Color::green.rgba(), Color::blue.rgba(), Color::yellow.rgba() };
RGBA maskColor = maskColors[mask];
RGBA whiteColor = Color::white.rgba();
RGBA alphaColor = Color::alpha.rgba();
// convert pixels
// masked color -> white color
// any other color -> alpha color
for(int i=0;i<4096;i+=4) {
RGBA& currentColor = *(RGBA*)&pixels[i];
if(currentColor == maskColor)
currentColor = whiteColor;
else
currentColor = alphaColor;
}
// convert pixels
// masked color -> white color
// any other color -> alpha color
for(int i=0;i<4096;i+=4) {
RGBA& currentColor = *(RGBA*)&pixels[i];
if(currentColor == maskColor)
currentColor = whiteColor;
else
currentColor = alphaColor;
//TODO: cache sprites mask into a texture
return TexturePtr(new Texture(32, 32, 4, &pixels[0]));
}
//TODO: cache sprites mask into a texture
return TexturePtr(new Texture(32, 32, 4, &pixels[0]));
return texture;
}

View File

@ -15,8 +15,7 @@ public:
uint32 getSignature() { return m_signature; }
int getSpritesCount() { return m_spritesCount; }
TexturePtr getSpriteTexture(int id);
TexturePtr getSpriteMask(int id, SpriteMask mask);
TexturePtr getSpriteTexture(int id, SpriteMask mask = SpriteMaskNone);
private:
TexturePtr loadSprite(int id);

View File

@ -24,11 +24,7 @@ void Thing::internalDraw(int x, int y, int blendframes, int xdiv, int ydiv, int
if(!spriteId)
continue;
TexturePtr spriteTex;
if(mask == SpriteMaskNone) {
spriteTex = g_sprites.getSpriteTexture(spriteId);
} else
spriteTex = g_sprites.getSpriteMask(spriteId, mask);
TexturePtr spriteTex = g_sprites.getSpriteTexture(spriteId, mask);
Rect drawRect((x - xi*32) - attributes.xOffset,
(y - yi*32) - attributes.xOffset,