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::green (0x00, 0xFF, 0x00, 0xFF);
Color Color::blue (0x00, 0x00, 0xFF, 0xFF); Color Color::blue (0x00, 0x00, 0xFF, 0xFF);
Color Color::pink (0xFF, 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 <framework/graphics/framebuffer.h>
#include "game.h" #include "game.h"
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
Creature::Creature() : Thing(THING_CREATURE) Creature::Creature() : Thing(THING_CREATURE)
{ {
m_healthPercent = 0; m_healthPercent = 0;
@ -22,9 +18,6 @@ void Creature::draw(int x, int y)
// draw outfit // draw outfit
internalDraw(x, y, 0, m_direction, 0, 0, anim); 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 // TODO: move this shit hahaha
static const Color outfitColors[] = { static const Color outfitColors[] = {
Color(255,255,255), Color(255,255,255),

View File

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

View File

@ -15,8 +15,7 @@ public:
uint32 getSignature() { return m_signature; } uint32 getSignature() { return m_signature; }
int getSpritesCount() { return m_spritesCount; } int getSpritesCount() { return m_spritesCount; }
TexturePtr getSpriteTexture(int id); TexturePtr getSpriteTexture(int id, SpriteMask mask = SpriteMaskNone);
TexturePtr getSpriteMask(int id, SpriteMask mask);
private: private:
TexturePtr loadSprite(int id); 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) if(!spriteId)
continue; continue;
TexturePtr spriteTex; TexturePtr spriteTex = g_sprites.getSpriteTexture(spriteId, mask);
if(mask == SpriteMaskNone) {
spriteTex = g_sprites.getSpriteTexture(spriteId);
} else
spriteTex = g_sprites.getSpriteMask(spriteId, mask);
Rect drawRect((x - xi*32) - attributes.xOffset, Rect drawRect((x - xi*32) - attributes.xOffset,
(y - yi*32) - attributes.xOffset, (y - yi*32) - attributes.xOffset,