PDA

View Full Version : drawing with uniform variable -> stack underflow



Dylan
10-29-2006, 11:37 AM
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!

k_szczech
10-29-2006, 01:43 PM
I have no idea why!Me too :)
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" errorPlease 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.

Dylan
10-29-2006, 10:12 PM
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?

Dylan
10-29-2006, 10:18 PM
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

k_szczech
10-29-2006, 11:19 PM
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.