BGE glsl setUniform problem In Blender 2.69 and 2.70 I tried to make a simple GLSL shader that has one uniform value. However, it seems like the uniform value isn't applied correctly. The scene is showing a black cube. How can I fix it?

import bge

cont = bge.logic.getCurrentController()

vs = '''
    void main() {
        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    }
'''

fs = '''
    uniform float c;
    void main() {
        gl_FragColor = vec4(c, c, c, 1.0);
    }
'''

mesh = cont.owner.meshes[0]
for mat in mesh.materials:
    shader = mat.getShader()
    shader.setSource(vs, fs, 0)
    shader.setUniform1f('c', 0.5)


i partly figured it out myself.

if i play the scene in the stand alone player.
the uniform value is applied correctly.

i don't know why the viewport mode bge player doesn't work correctly.
The problem is the last argument of setSource, which isn´t documented. Looking at the blender source code this argument is named "apply" and expects a boolean.

So:

shader.setSource(vs, fs, True)


should fix the problem. Note, that you should also switch to textured view mode.