Hi there,
i need some help in applying a shader (my first try) to an existing colored object.
I copied a simple toon-shader-function from a tutorial:
#define _V_SHADER "
" \
" varying vec3 normalVec;
" \
" void main ()
" \
" {
" \
" normalVec = normalize (gl_NormalMatrix * gl_Normal);
" \
" gl_Position = ftransform ();
" \
" } "
#define _F_SHADER "
" \
" varying vec3 normalVec;
" \
" void main ()
" \
" {
" \
" float intensity;
" \
" vec4 color;
" \
" intensity = dot (vec3 (gl_LightSource [0].position), normalVec);
" \
" if (intensity > 0.90) { color = vec4 (1.00, 0.56, 0.0, 1.0); }
" \
" else if (intensity > 0.60) { color = vec4 (0.64, 0.35, 0.0, 1.0); }
" \
" else if (intensity > 0.30) { color = vec4 (0.37, 0.17, 0.0, 1.0); }
" \
" else { color = vec4 (0.12, 0.07, 0.0, 1.0); };
" \
" gl_FragColor = color;
" \
" } "
The implementation is preformed in two steps / functions (handles are already created in the constructor of the clsShaderBase-Object):
void clsShaderBase::Update() {
const char *vv = _V_SHADER; // vv & ff will be parameters later
const char *ff = _F_SHADER;
GLint success;
success = 0;
glShaderSource (vsHandle, 1, &vv, NULL);
glCompileShader (vsHandle);
glGetShaderiv (vsHandle, GL_COMPILE_STATUS, &success);
if (success == GL_FALSE) handleErr("GLSL Vertex-compile error", GL_COMPILE_STATUS);
success = 0;
glShaderSource (fsHandle, 1, &ff, NULL);
glCompileShader (fsHandle);
glGetShaderiv (fsHandle, GL_COMPILE_STATUS, &success);
if (success == GL_FALSE) handleErr("GLSL Fragment-compile error", GL_COMPILE_STATUS);
glAttachShader (ShaderProgramHandle, vsHandle);
glAttachShader (ShaderProgramHandle, fsHandle);
}
void clsShaderBase::Apply() {
glLinkProgram (ShaderProgramHandle);
GLint success = 0;
glGetProgramiv (ShaderProgramHandle, GL_LINK_STATUS, &success);
if(success == GL_FALSE) handleErr("GLSL Link error", GL_LINK_STATUS);
}
Apply() is called just before glBegin(GL_QUADS), but nothing changes in the rendered image and no error-handling is called.
Any idea what is wrong??
Regards,
Frank