I can't remember seeing a tutorial on Shaders, but the following seems to work in GLB.
I haven't used it in a while, mainly because it didn't work on my iPhone (3GS), and didn't want to investigate any further!
(I think I've since found out that GLB only uses OpenGL 1.1? Is that only on iOS? Or am i wrong?)
Here's my Shader code in GLB:
CONSTANT FP_SHADER$ = "Graphics/Shaders/"
CONSTANT SHADER_COLOUR% = 9
FUNCTION ShaderColour%: colour%
STATIC init%, ok%
LOCAL r#, g#, b#
IF init <> TRUE
init = TRUE
ok = ShaderLoad(SHADER_COLOUR, "Color")
ENDIF
IF NOT ok THEN RETURN
r = bAND(colour, 0xff) / 255.0
g = bAND(colour / 0x100, 0xff) / 255.0
b = bAND(colour / 0x10000, 0xff) / 255.0
X_SETSHADER SHADER_COLOUR
X_PUTSHADER "r", r
X_PUTSHADER "g", g
X_PUTSHADER "b", b
RETURN
ENDFUNCTION
FUNCTION ShaderLoad%: index%, fn$
LOCAL ok%
DEBUG ">GFX:{ShaderLoad } fn:[" + GETCURRENTDIR$() + FP_SHADER$ + fn$ + "]\n"
ok = X_LOADSHADER(index, FP_SHADER$ + fn$ + ".vert", FP_SHADER$ + fn$ + ".frag")
IF NOT ok THEN DEBUG ">{Gfx ShaderLoad } *** Error Loading:[" + FP_SHADER$ + fn$ + "]\n"
RETURN ok
ENDFUNCTION
And here are the Shader files:
'Color.vert'
float FogEyeRadial(vec4 Rh) {
vec4 Re = Rh / Rh.w;
return length(Re);
}
void main(void) {
gl_FogFragCoord = FogEyeRadial(gl_ModelViewMatrix * gl_Vertex);
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
}
'Color.frag'
uniform sampler2D TextureID1;
uniform float r;
uniform float g;
uniform float b;
void main (void) {
vec4 color = vec4(r, g, b, 0.5);
gl_FragColor = texture2D(TextureID1, gl_TexCoord[0].xy) + color;
gl_FragColor = mix(gl_Fog.color, gl_FragColor, clamp((gl_Fog.end - gl_FogFragCoord) * gl_Fog.scale / 5.0, 0.1, 1.0));
}
By looking at the shader files, I think this shader takes in three values, r, g, b, and shades the pixels by that colour.
And it appears to apply the fog settings to the affected pixels too.
This was my first shader, so there are maybe better or simpler ways to do this, but was just a proof of concept to see if I can get shaders to work. I took bits and pieces from other people's shaders to get this far!
To use it, just call the 'ShaderColour(RGB(255,0,0))' function passing it a colour you want applied.
It also loads the required shader files if they haven't already been loaded.
Finally it sets the shader and passes it the three required colour parts.