fixes in uicreature rendering

This commit is contained in:
Eduardo Bart 2012-02-07 23:33:08 -02:00
parent 09b3aa82df
commit 619f751371
7 changed files with 60 additions and 6 deletions

View File

@ -1,5 +1,5 @@
Creature < UICreature Creature < UICreature
size: 66 66 size: 80 80
padding: 1 padding: 1
image-source: /core_styles/images/panel_flat.png image-source: /core_styles/images/panel_flat.png
image-border: 1 image-border: 1

View File

@ -5,6 +5,7 @@ Color < ColorBox
Window Window
text: Select Outfit text: Select Outfit
size: 550 280 size: 550 280
padding: 0 0 0 0
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@ -26,6 +27,8 @@ Window
anchors.top: name.bottom anchors.top: name.bottom
anchors.left: name.left anchors.left: name.left
margin-top: 5 margin-top: 5
padding: 16 4 4 16
fixed-creature-size: true
ButtonBox ButtonBox
id: head id: head

View File

@ -11,6 +11,7 @@ uniform vec4 bodyColor;
uniform vec4 legsColor; uniform vec4 legsColor;
uniform vec4 feetColor; uniform vec4 feetColor;
vec4 calcOutfitPixel() vec4 calcOutfitPixel()
{ {
vec4 pixel = texture2D(texture, textureCoords); vec4 pixel = texture2D(texture, textureCoords);
@ -29,6 +30,31 @@ vec4 calcOutfitPixel()
return pixel * outColor; 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() void main()
{ {
gl_FragColor = calcOutfitPixel() * color * opacity; gl_FragColor = calcOutfitPixel() * color * opacity;

View File

@ -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); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_size.width(), m_size.height(), 0, format, GL_UNSIGNED_BYTE, pixels);
// disable texture border // disable texture border
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
setupFilters(); setupFilters();

View File

@ -248,8 +248,10 @@ void OTClient::registerLuaFunctions()
g_lua.registerClass<UICreature, UIWidget>(); g_lua.registerClass<UICreature, UIWidget>();
g_lua.bindClassStaticFunction<UICreature>("create", []{ return UICreaturePtr(new UICreature); } ); 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>("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.registerClass<UIMap, UIWidget>();
g_lua.bindClassStaticFunction<UIMap>("create", []{ return UIMapPtr(new UIMap); } ); g_lua.bindClassStaticFunction<UIMap>("create", []{ return UIMapPtr(new UIMap); } );

View File

@ -28,13 +28,31 @@ void UICreature::draw()
{ {
drawSelf(); drawSelf();
//TODO: cache with framebuffer
if(m_creature) { if(m_creature) {
g_painter.setColor(Fw::white); g_painter.setColor(Fw::white);
Rect drawRect = getChildrenRect(); 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(); 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>());
}
}

View File

@ -33,11 +33,16 @@ public:
void draw(); void draw();
void setCreature(const CreaturePtr& creature) { m_creature = creature; } void setCreature(const CreaturePtr& creature) { m_creature = creature; }
void setFixedCreatureSize(bool fixed) { m_fixedCreatureSize = fixed; }
CreaturePtr getCreature() { return m_creature; } CreaturePtr getCreature() { return m_creature; }
bool isFixedCreatureSize() { return m_fixedCreatureSize; }
protected: protected:
void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
CreaturePtr m_creature; CreaturePtr m_creature;
Boolean<false> m_fixedCreatureSize;
}; };
#endif #endif