Jump to content


Fragment shader basics


3 replies to this topic

#1 Alienizer

    Member

  • Members
  • PipPipPipPip
  • 435 posts

Posted 20 July 2012 - 11:39 PM

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);
glCompileShaderARB(shader_fp);
shader_id = glCreateProgram();
glAttachShader(shader_id, shader_fp);
glLinkProgramARB(shader_id);


and in the draw function I have...

glUseProgram(shader_id);

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!

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5305 posts
  • LocationBellevue, WA

Posted 21 July 2012 - 12:25 AM

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.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 Alienizer

    Member

  • Members
  • PipPipPipPip
  • 435 posts

Posted 21 July 2012 - 12:54 AM

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?

#4 Alienizer

    Member

  • Members
  • PipPipPipPip
  • 435 posts

Posted 21 July 2012 - 01:40 AM

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 :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users