Question

So, there is my vertex and fragment shaders:

#version 120

attribute vec4 a_position;
varying vec4 pos;
uniform float time;

void main() { 
    float t = time;
    gl_Position = a_position;
    pos = gl_Position;
}

&

#version 120

#ifdef GL_ES 
    precision mediump float;
#endif
varying vec4 pos;
uniform float time;

void main() {
    gl_FragColor = vec4(pos.y / 2.0 + 1, time / 10.0, 1.0, 1.0);
};

If I try to change uniform 'time' just after compilation, it works:

shaderDown.setUniformf("time", World.ticks);

But if I try to call the same function in 'Update()' method, it gives an 'java.lang.NullPointerException'

So how can I change this variable every time?

Was it helpful?

Solution

You must call glUniform() to update "time" before each call to glDrawArrays(). IF that causes a null pointer exception, you probably need to call glUseProgram() first.

If "time" is to be calculated by the Vertex shader, you should change it to be a varying instead of a uniform.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top