I’d expect to see a yellow slice on the left side on the top half of the window and and the rest of the top window should be green. The lower half should be completely black.
But what i get is a yellow slice on the right / top (i=3), the rest is black. For i=0,1,2 it is never entering.
What do I do wrong?
Note that the built-in output variable is called gl_FragColor (with ‘_’ after gl).
If you suspect the GLSL compiler to muck up something, you could try to assign the shader output (either built-in gl_FragColor or your own ‘out’ variable) only after the loop and use a temporary variable inside the loop - the theory being that assignment to output variables is something the compiler likely tracks specially and may get confused about if there is complex control flow involved.
Besides that, im not that experienced with opengl. Thats probably why i dont get your answer.
You suggest i should do the glFragColor outside the loop. But that doesnt change the fact that it is not in the right if cases and just the last incremented i (i=4) is recognized correctly. Does it?
That could be a coincidence. Have you checked the compile and link info log (glGetShaderInfoLog, glGetProgramInfoLog) for helpful messages?
I meant writing it like this:
vec4 color = vec4(0.0, 0.0, 0.0, 1.0);
int counterA = 0;
for(int i=0;i<4;i++)
{
if(texCoord.s<=((i+0.0)/4)+epsilon && texCoord.s>=((i+0.0)/4)-epsilon && texCoord.t >0.5)
{
if(counterA==0)
{
color = vec4(1,1,0,1);
}
else
{
color = vec4(0,1,0,1);
}
counterA++;
}
else
{
color = vec4(0,0,0,1);
}
}
gl_FragColor = color;
In theory this should do the same thing, except that there is only one location where an assignment to gl_FragColor happens. In the (perhaps unlikely) case that your original code runs into a GLSL compiler bug, this form or something like it could be a workaround.
[QUOTE=carsten neumann;1262594]
In theory this should do the same thing, except that there is only one location where an assignment to gl_FragColor happens. In the (perhaps unlikely) case that your original code runs into a GLSL compiler bug, this form or something like it could be a workaround.[/QUOTE]
It does the same thing, but sadly still the wrong one. Just one yellow slice on the left side
Do you have an other idea?
I assumed that it would be a common problem to increment through the area u want to be painted?