View Full Version : problem in dynamic loop

10-16-2005, 11:48 PM

I'm learning about GLSL.
Appearing below is a GLSL fragment source code I wrote for experiment.

uniform int N_LOOP;
void main(void)
int i;
float tmp=0.0f;
for(i=0; i<N_LOOP; i++){
tmp += 0.1f;
gl_FragColor = vec4(tmp, 0.0, 0.0, 0.0);
}And, I set N_LOOP by written the below code.

glUniform1iARB(glGetUniformLocationARB(_programObj ect, "N_LOOP"), nLoop);I think that the result of this program is depend on nLoop but the result I got was similar to vec4(0.1, 0.0, 0.0, 0.0).
It seems that for-loop doesn't works dynamically.

Does GLSL support dynamic loop like I used above ?
(Is this written in specification or FAQ ?
I didn't find such description.)

Would you please give me some advice ?

My execution environment is GeForce6800GT(AGP).
When I wrote same program in HLSL and executed, the result is similar to (0.1*N_LOOP, 0.0, 0.0, 0.0).

10-17-2005, 04:14 AM
Should work. What driver are you running?

You have errors.

0.1f should be 0.1
Get rid of the "f"s and turn on strict GLSL support with NVEmulate.

10-17-2005, 10:44 PM
Thanks V-man.

I changed code from 1.0f to 1.0, and executed program.
As a result, I got a correct result.
Then, I changed code from 1.0 to 1.0f for confirmation.
As a result, I got a correnct result, too.

I don't understand why my code works correctly, but it is truth that result is correctly.
I hated to bother you about this.

10-20-2005, 04:40 AM
What is the value of N_LOOP?

The GLSL spec says
The consequences of very long or non-terminating loops are platform dependent. On your hardware, the max count loop is 255. If you exceed this limit, no error is generated but the results are undefined.