Drawing with uniform variable -> stack underflow

Hi,

I have a weird problem with GLSL.
I’m using a “uniform float alpha” in my vertex program to alter the alpha value.

the alpha value is linked to a key in my main program.
I update the alpha value by calling
“glUniform1f(getUniLoc(sp1.progobj, “alpha”), alpha);” in my draw function after I bind the sp1.progobj (shaderprogram 1), and I’m sure the alpha value stays between 0 and 1.

alpha is initialized as 1.0f

when I put the glUniform line into my draw function the GLSL returns an “stack underflow” error.

I have no idea why!

I have no idea why!
Me too :slight_smile:
But perhaps if I could see your code things would be different.
It shouldn’t have anything to do with the value you put into alpha.

GLSL returns an “stack underflow” error
Please be more precise - where do you get this message from? glGetError?
Also - you only need to call GetUniformLocation once (after you link your program) - these locations do not change unless you link your program again.
Another thing - if you have an uniform declared in your vertex shader but not actually used in shader’s code then you will not be able to get this uniform’s location because it’s not an active uniform.

Originally posted by k_szczech:
Also - you only need to call GetUniformLocation once (after you link your program) - these locations do not change unless you link your program again.

But how can I change this parameter then, during drawing?

Ok, i found out how to get rid of the error.

I used:
location = glGetUniformLocation(sp1.progobj, “alpha”);
glUniform1f(location, alpha);

in stead of:
glUniform1f(glGetUniformLocation(sp1.progobj,“alpha”), alpha);

Its exactly the same, but no error now…weird

But how can I change this parameter then, during drawing?
Well, you do this almost exactly the way you do it now:
Initialization:

location = glGetUniformLocation(sp1.progobj, "alpha");

Rendering:

glUniform1f(location, alpha);

You only need to ask for “alpha” location once - then you just use glUniform to change it’s value.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.