Uniform not being applied to proper mesh
Posted
by
HaMMeReD
on Game Development
See other posts from Game Development
or by HaMMeReD
Published on 2012-10-10T08:01:21Z
Indexed on
2012/10/10
15:55 UTC
Read the original article
Hit count: 238
Ok, I got some code, and you select blocks on a grid.
The selection works. I can modify the blocks to be raised when selected and the correct one shows.
I set a color which I use in the shader. However, I am trying to change the color before rendering the geometry, and the last rendered geometry (in the sequence) is rendered light.
However, to debug logic I decided to move the block up and make it white, in which case one block moves up and another block becomes white.
I checked all my logic and it knows the correct one is selected and it is showing in, in the correct place and rendering it correctly. When there is only 1 it works properly.
Video Of the bug in action, note how the highlighted and elevated blocks are not the same block, however the code for color and
My Renderer is here (For the items being drawn)
public void render(Renderer renderer) {
mGrid.render(renderer, mGameState);
for (Entity e:mGameEntities) {
UnitTypes ut = UnitTypes.valueOf((String)e.getObject(D.UNIT_TYPE.ordinal()));
if (ut == UnitTypes.Soldier) {
renderer.testShader.begin();
renderer.testShader.setUniformMatrix("u_mvpMatrix",mEntityMatrix);
renderer.texture_soldier.bind(0);
Vector2 pos = (Vector2) e.getObject(D.COORDS.ordinal());
mEntityMatrix.set(renderer.mCamera.combined);
if (mSelectedEntities.contains(e)) {
mEntityMatrix.translate(pos.x, 1f, pos.y);
renderer.testShader.setUniformf("v_color", 0.5f,0.5f,0.5f,1f);
} else {
mEntityMatrix.translate(pos.x, 0f, pos.y);
renderer.testShader.setUniformf("v_color", 1f,1f,1f,1f);
}
mEntityMatrix.scale(0.2f, 0.2f, 0.2f);
renderer.model_soldier.render(renderer.testShader,GL20.GL_TRIANGLES);
renderer.testShader.end();
} else if (ut == UnitTypes.Enemy_Infiltrator) {
renderer.testShader.begin();
renderer.testShader.setUniformMatrix("u_mvpMatrix",mEntityMatrix);
renderer.testShader.setUniformf("v_color", 1.0f,1,1,1.0f);
renderer.texture_enemy_infiltrator.bind(0);
Vector2 pos = (Vector2) e.getObject(D.COORDS.ordinal());
mEntityMatrix.set(renderer.mCamera.combined);
mEntityMatrix.translate(pos.x, 0f, pos.y);
mEntityMatrix.scale(0.2f, 0.2f, 0.2f);
renderer.model_enemy_infiltrator.render(renderer.testShader,GL20.GL_TRIANGLES);
renderer.testShader.end();
}
}
}
© Game Development or respective owner