I’m coding a graphic engine using OpenGL + GLSL shaders. Currently, I manage several lights in my scene (per-pixel lighting mode). So, I have a loop to access to the properties of all lights in the scene for each pixel. If I put the light count value directly in the loop condition there’s not problem but if I want to do this job in a dynamic way by sending an integer uniform variable from my C++ code it does not work. But I checked in the fragment shader the value of the variable and this one is correct.
You haven’t really provided enough information here:
Are you checking for shader compile and link errors, as well as GL errors?
What #version of GLSL are your shaders targeting?
What GPU and GPU driver are you running this on?
What is “light_par[]”? Let’s see the shader declaration for it.
Does light_par[] involve uniform blocks and/or samplers?
Are you doing anything else in your loop with “y” or “no_of_lights” besides indexing light_par[]?
There’s no such thing. The GLSL version numbers jumped from 1.50 (for OpenGL 3.2) to 3.30 (for OpenGL 3.3). Ensure that you have a valid #version directive; conforming implementations will use GLSL 1.1 for shaders lacking a #version directive.
Failing that, post a short stand-alone GLUT test program that illustrates the problem so folks can take a closer look at this, try it on their drivers/GPUs, and give you feedback.
I had added the above into a loop. That’s why it sends wrong constant value to the shader for each time the loop execute. Now i have added it before that loop it’s working fine.