Fragment shader basics

Alienizer 109 Jul 20, 2012 at 23:39

I’m not sure what I’m doing wrong, but here is what I have in my init function…

shader_fp = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSourceARB(shader_fp, 1, &program_string, 0);
shader_id = glCreateProgram();
glAttachShader(shader_id, shader_fp);

and in the draw function I have…


and in the fs program_string I have as a simple test…

void main(void) {
  gl_FragColor = vec4(0.5, 0.0, 0.0, 1.0);

but everything is drawn as if the fs program is not called. Everything should be red instead. If I use glEnable(GL_FRAGMENT_PROGRAM_ARB); then the output is the backgound blue color as set with glClearColor.

Can anyine spot what my problem is? Thanks!

3 Replies

Please log in or register to post a reply.

Reedbeta 167 Jul 21, 2012 at 00:25

You should insert error-checking calls after each of the shader-related GL calls, to see if anything is going wrong that GL can tell you about. This tutorial shows how. Also try using glCheckErrors() to catch any GL errors that aren’t specifically about shader compilation.

Alienizer 109 Jul 21, 2012 at 00:54

That’s what I did, I check every calls. I just didn’t show the code for it for simplicity. So it looks ok to you? Nothing missing? Or am I doing it the wrong way?

Alienizer 109 Jul 21, 2012 at 01:40

It didn’t seem to like…

main() {

so I changed it to…

void main(void) {

and now it works!!!

Thanks Reedbeta for the link. I like this site, very good tutorials :)