From 817234a6606e8acba350e694ee7f1f0a273e337d Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Fri, 19 Aug 2011 09:49:29 -0300 Subject: [PATCH] head outfit color fix --- src/framework/util/color.cpp | 2 +- src/otclient/core/creature.cpp | 7 ----- src/otclient/core/spritemanager.cpp | 46 ++++++++++++++--------------- src/otclient/core/spritemanager.h | 3 +- src/otclient/core/thing.cpp | 6 +--- 5 files changed, 25 insertions(+), 39 deletions(-) diff --git a/src/framework/util/color.cpp b/src/framework/util/color.cpp index 5c1bcb76..5c4c7bef 100644 --- a/src/framework/util/color.cpp +++ b/src/framework/util/color.cpp @@ -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); diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index 9006a0c1..082346ba 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -4,10 +4,6 @@ #include #include "game.h" -#include -#include -#include - 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), diff --git a/src/otclient/core/spritemanager.cpp b/src/otclient/core/spritemanager.cpp index 061a866a..51b144fc 100644 --- a/src/otclient/core/spritemanager.cpp +++ b/src/otclient/core/spritemanager.cpp @@ -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(); + + 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; + } -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(); - - // 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; } diff --git a/src/otclient/core/spritemanager.h b/src/otclient/core/spritemanager.h index 8e533637..eb95f960 100644 --- a/src/otclient/core/spritemanager.h +++ b/src/otclient/core/spritemanager.h @@ -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); diff --git a/src/otclient/core/thing.cpp b/src/otclient/core/thing.cpp index 229a752e..8b1c0d3f 100644 --- a/src/otclient/core/thing.cpp +++ b/src/otclient/core/thing.cpp @@ -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,