EDIT: I’m sorry Stack Overflow, but I’m retarded. frac(tex_offset) -> fract(tex_offset), and it works fine on ATI cards, and also nVidia cards when #version is specified now. This must be why most of the programmers I know don’t have much hair left.
–
I’m working on a game for a school project. It’s a vertical scroller, so one of the required features was a scrolling background. I tried a few approaches, but I eventually wrote a simple fragment shader (this is the first time I touch shader programming, so don’t really know what I’m doing):
uniform sampler2D tex;
uniform float tex_offset;
void main()
{
vec2 coords = vec2(gl_TexCoord[0].s, gl_TexCoord[0].t - frac(tex_offset));
gl_FragColor = texture2D(tex, coords);
}
I use SFML so I don’t touch much of the stuff behind the scenes, but the texture I’m using is passed to the tex variable, and the tex_offset is generated in my game loop by taking the total elapsed seconds multiplied by a factor to control the scrolling speed.
This appears to do what it’s supposed to; it indefinitely scrolls a seamless repeating texture in one direction. It works on my laptop, and it works on my home computer, which both have nVidia cards. However, when we tried to run it on a group member’s computer with an ATI card, it simply did nothing. I did some googling and it seems like the nVidia cards accept “non-standard” GLSL code as well, which might explain the issues with compatibility. I find it difficult to find good tutorials/explanation on GLSL as most of the stuff I dig up is from version 1.2-1.4 and I’m apparently using syntax that was deprecated in version 3 (gl_FragColor, gl_TexCoord). However, when I tried to set #version to 120 or 140 or whatever, the shader also stopped working on my nVidia computers.
So, to try to phrase this into question form: what is wrong about this shader code? Is there any way to debug the syntax, and how do I turn on “standards” mode for my nVidia cards if this is possible?
Changed
frac(tex_offset)tofract(tex_offset), and it works fine on ATI cards, and also nVidia cards when #version is specified now.