Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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) {                              

            Vector2 pos = (Vector2) e.getObject(D.COORDS.ordinal());                
            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);              
        } else if (ut == UnitTypes.Enemy_Infiltrator) {
            renderer.testShader.setUniformf("v_color", 1.0f,1,1,1.0f);
            Vector2 pos = (Vector2) e.getObject(D.COORDS.ordinal());
            mEntityMatrix.translate(pos.x, 0f, pos.y);
            mEntityMatrix.scale(0.2f, 0.2f, 0.2f);

        String vertexShader = "uniform mat4 u_mvpMatrix;                   \n" 
            + "attribute vec4 a_position;                  \n"
            + "attribute vec2 a_uv;                  \n"
            + "varying vec2 v_uv;                  \n"
            + "void main()                                 \n" + "{                                           \n"
            + " v_uv = vec2(a_uv.x,1.0-a_uv.y);\n"              
            + "   gl_Position = u_mvpMatrix * a_position;  \n" + "}                            \n";
        String fragmentShader = "#ifdef GL_ES\n" + "precision mediump float;\n" + "#endif\n"
            + " uniform vec4 v_color;" 
            + " uniform sampler2D tex;" 
            + " varying vec2 v_uv;     \n"
            + "void main()                                  \n" 
            + "{                                            \n"
            + "  gl_FragColor = v_color*texture2D(tex, v_uv);\n" 
            + "}";
      testShader = new ShaderProgram(vertexShader, fragmentShader);
share|improve this question
Nice job adding music to your sample debug video. Classy. Anyway, can you also show us your shader code for how you're applying the color? –  Byte56 Oct 10 '12 at 14:01
music just was caught by fraps, shader code pasted above. –  HaMMeReD Oct 10 '12 at 16:28
add comment

closed as too localized by Josh Petrie, Byte56, Trevor Powell, bummzack, Sean Middleditch Dec 28 '12 at 7:03

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

I simplified my renderer, and then looked at it.

The solution was the following. I tested with both options to ensure that I effectively fixed it.

The problem was


I set it before I set mEntityMatrix and made the incorrect assumption that it passed a reference and didn't make a copy. I assume this made it use the last "mEntityMatrix" from the last loop, hence transforming using "the last elements" position.

Once I moved the line to right before my drawElements everything started working.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.