fixes in uicreature rendering

master
Eduardo Bart 12 years ago
parent 09b3aa82df
commit 619f751371

@ -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

@ -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

@ -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;

@ -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();

@ -248,8 +248,10 @@ void OTClient::registerLuaFunctions()
g_lua.registerClass<UICreature, UIWidget>();
g_lua.bindClassStaticFunction<UICreature>("create", []{ return UICreaturePtr(new UICreature); } );
g_lua.bindClassMemberFunction<UICreature>("getCreature", &UICreature::getCreature);
g_lua.bindClassMemberFunction<UICreature>("setCreature", &UICreature::setCreature);
g_lua.bindClassMemberFunction<UICreature>("setFixedCreatureSize", &UICreature::setFixedCreatureSize);
g_lua.bindClassMemberFunction<UICreature>("getCreature", &UICreature::getCreature);
g_lua.bindClassMemberFunction<UICreature>("isFixedCreatureSize", &UICreature::isFixedCreatureSize);
g_lua.registerClass<UIMap, UIWidget>();
g_lua.bindClassStaticFunction<UIMap>("create", []{ return UIMapPtr(new UIMap); } );

@ -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<bool>());
}
}

@ -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<false> m_fixedCreatureSize;
};
#endif

Loading…
Cancel
Save