pass item id to item shader

This commit is contained in:
Eduardo Bart 2012-02-07 05:04:03 -02:00
parent ff8cc88ec8
commit 0b220e2e88
2 changed files with 5 additions and 1 deletions

View File

@ -14,7 +14,7 @@ end
function Effects.fadeOut(widget, time, elapsed) function Effects.fadeOut(widget, time, elapsed)
if not elapsed then elapsed = 0 end if not elapsed then elapsed = 0 end
if not time then time = 250 end if not time then time = 250 end
widget:setOpacity((time - elapsed)/time) widget:setOpacity(math.max((time - elapsed)/time, 0))
if elapsed < time then if elapsed < time then
scheduleEvent(function() scheduleEvent(function()
Effects.fadeOut(widget, time, elapsed + 30) Effects.fadeOut(widget, time, elapsed + 30)

View File

@ -49,6 +49,7 @@ ItemPtr Item::create(int id)
} }
PainterShaderProgramPtr itemProgram; PainterShaderProgramPtr itemProgram;
int ITEM_ID_UNIFORM = 10;
void Item::draw(const Point& dest, float scaleFactor, bool animate) void Item::draw(const Point& dest, float scaleFactor, bool animate)
{ {
@ -167,8 +168,11 @@ void Item::draw(const Point& dest, float scaleFactor, bool animate)
itemProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader); itemProgram->addShaderFromSourceCode(Shader::Vertex, glslMainWithTexCoordsVertexShader + glslPositionOnlyVertexShader);
itemProgram->addShaderFromSourceFile(Shader::Fragment, "/game_shaders/item.frag"); itemProgram->addShaderFromSourceFile(Shader::Fragment, "/game_shaders/item.frag");
assert(itemProgram->link()); assert(itemProgram->link());
itemProgram->bindUniformLocation(ITEM_ID_UNIFORM, "itemId");
} }
g_painter.setCustomProgram(itemProgram); g_painter.setCustomProgram(itemProgram);
itemProgram->bind();
itemProgram->setUniformValue(ITEM_ID_UNIFORM, (int)m_id);
// now we can draw the item // now we can draw the item
internalDraw(dest, scaleFactor, xPattern, yPattern, zPattern, animationPhase); internalDraw(dest, scaleFactor, xPattern, yPattern, zPattern, animationPhase);