From 619f751371d2123604fdcb4b076e3bc4a3412ca6 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Tue, 7 Feb 2012 23:33:08 -0200 Subject: [PATCH] fixes in uicreature rendering --- modules/core_styles/styles/creatures.otui | 2 +- modules/game_outfit/outfit.otui | 3 +++ modules/game_shaders/outfit.frag | 26 +++++++++++++++++++++++ src/framework/graphics/texture.cpp | 4 ++-- src/otclient/luafunctions.cpp | 4 +++- src/otclient/ui/uicreature.cpp | 22 +++++++++++++++++-- src/otclient/ui/uicreature.h | 5 +++++ 7 files changed, 60 insertions(+), 6 deletions(-) diff --git a/modules/core_styles/styles/creatures.otui b/modules/core_styles/styles/creatures.otui index 6074d150..c2eeea97 100644 --- a/modules/core_styles/styles/creatures.otui +++ b/modules/core_styles/styles/creatures.otui @@ -1,5 +1,5 @@ Creature < UICreature - size: 66 66 + size: 80 80 padding: 1 image-source: /core_styles/images/panel_flat.png image-border: 1 diff --git a/modules/game_outfit/outfit.otui b/modules/game_outfit/outfit.otui index e318fc82..f34ba0b6 100644 --- a/modules/game_outfit/outfit.otui +++ b/modules/game_outfit/outfit.otui @@ -5,6 +5,7 @@ Color < ColorBox Window text: Select Outfit size: 550 280 + padding: 0 0 0 0 anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter @@ -26,6 +27,8 @@ Window anchors.top: name.bottom anchors.left: name.left margin-top: 5 + padding: 16 4 4 16 + fixed-creature-size: true ButtonBox id: head diff --git a/modules/game_shaders/outfit.frag b/modules/game_shaders/outfit.frag index edff06fb..86fa0622 100644 --- a/modules/game_shaders/outfit.frag +++ b/modules/game_shaders/outfit.frag @@ -11,6 +11,7 @@ uniform vec4 bodyColor; uniform vec4 legsColor; uniform vec4 feetColor; + vec4 calcOutfitPixel() { vec4 pixel = texture2D(texture, textureCoords); @@ -29,6 +30,31 @@ vec4 calcOutfitPixel() return pixel * outColor; } +/* +// optimized to handle antialising +vec4 calcOutfitPixel() +{ + vec4 pixel = texture2D(texture, textureCoords); + vec4 maskColor = texture2D(maskTexture, textureCoords); + const vec4 white = vec4(1,1,1,1); + + float headFactor = 0.0; + if(maskColor.r > 0.1 && maskColor.g > 0.1) { + headFactor = min(maskColor.r, maskColor.g); + + maskColor.r -= headFactor; + maskColor.g -= headFactor; + } + + float tot = headFactor + maskColor.r + maskColor.g + maskColor.b; + vec4 outColor = headFactor * headColor + bodyColor * maskColor.r + legsColor * maskColor.g + feetColor * maskColor.b; + if(tot < 1.0) + outColor += white * (1.0 - tot); + outColor.a = 1.0; + + return pixel * outColor; +} +*/ void main() { gl_FragColor = calcOutfitPixel() * color * opacity; diff --git a/src/framework/graphics/texture.cpp b/src/framework/graphics/texture.cpp index 0dcdc9b6..2d9394dd 100644 --- a/src/framework/graphics/texture.cpp +++ b/src/framework/graphics/texture.cpp @@ -86,8 +86,8 @@ uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_size.width(), m_size.height(), 0, format, GL_UNSIGNED_BYTE, pixels); // disable texture border - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); setupFilters(); diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index 9a778363..eed82cf1 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -248,8 +248,10 @@ void OTClient::registerLuaFunctions() g_lua.registerClass(); g_lua.bindClassStaticFunction("create", []{ return UICreaturePtr(new UICreature); } ); - g_lua.bindClassMemberFunction("getCreature", &UICreature::getCreature); g_lua.bindClassMemberFunction("setCreature", &UICreature::setCreature); + g_lua.bindClassMemberFunction("setFixedCreatureSize", &UICreature::setFixedCreatureSize); + g_lua.bindClassMemberFunction("getCreature", &UICreature::getCreature); + g_lua.bindClassMemberFunction("isFixedCreatureSize", &UICreature::isFixedCreatureSize); g_lua.registerClass(); g_lua.bindClassStaticFunction("create", []{ return UIMapPtr(new UIMap); } ); diff --git a/src/otclient/ui/uicreature.cpp b/src/otclient/ui/uicreature.cpp index 205f289f..8edad2d0 100644 --- a/src/otclient/ui/uicreature.cpp +++ b/src/otclient/ui/uicreature.cpp @@ -28,13 +28,31 @@ void UICreature::draw() { drawSelf(); + //TODO: cache with framebuffer if(m_creature) { g_painter.setColor(Fw::white); Rect drawRect = getChildrenRect(); - float scaleFactor = drawRect.width() / (float)m_creature->getExactSize(); - m_creature->draw(drawRect.bottomRight() - Point(32, 32) * scaleFactor , scaleFactor, false); + + float scaleFactor = drawRect.width(); + if(m_fixedCreatureSize) + scaleFactor /= Otc::TILE_PIXELS; + else + scaleFactor /= m_creature->getExactSize(); + + Point dest = drawRect.bottomRight() - (Point(1,1)*Otc::TILE_PIXELS - m_creature->getDisplacement()) * scaleFactor; + m_creature->draw(dest, scaleFactor, false); } drawChildren(); } + +void UICreature::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) +{ + UIWidget::onStyleApply(styleName, styleNode); + + for(const OTMLNodePtr& node : styleNode->children()) { + if(node->tag() == "fixed-creature-size") + setFixedCreatureSize(node->value()); + } +} diff --git a/src/otclient/ui/uicreature.h b/src/otclient/ui/uicreature.h index 365b66fa..10478de0 100644 --- a/src/otclient/ui/uicreature.h +++ b/src/otclient/ui/uicreature.h @@ -33,11 +33,16 @@ public: void draw(); void setCreature(const CreaturePtr& creature) { m_creature = creature; } + void setFixedCreatureSize(bool fixed) { m_fixedCreatureSize = fixed; } CreaturePtr getCreature() { return m_creature; } + bool isFixedCreatureSize() { return m_fixedCreatureSize; } protected: + void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode); + CreaturePtr m_creature; + Boolean m_fixedCreatureSize; }; #endif