GLSL - Adding vertex shader breaks my fragment shader?

Started by
1 comment, last by Chronix 16 years, 10 months ago
Hi guys, Just started looking at GLSL tonight, and eventually got it up and running. So I started making a very basic test shader. The fragment shader sets the colour to green. This works fine. However, as soon as I ADD a vertex shader the colour is no longer green and goes back to white. I've tried using an empty vertex shader function and its the same (no more green), I've tried adding other stuff to the vertex shader and it doesnt do anything at all. It just doesnt seem to work? I check compile results, and BOTH SHADES RETURN SUCCESS. Here's the code: (im typing the shader code in so as I can make changes easily while im trying to get simple things working.) GLuint brickFS = glCreateShader(GL_FRAGMENT_SHADER); GLchar *fsource = "void main(void) { gl_FragColor = vec4 (0.0,1.0,0.0,1.0); }"; glShaderSource(brickFS,1,(const GLchar **)&fsource,NULL); glCompileShader(brickFS); GLint vertCompiled; glGetShaderiv(brickFS,GL_COMPILE_STATUS,&vertCompiled); GLuint brickVS = glCreateShader(GL_VERTEX_SHADER); GLchar *ssource = "void main(void) { }"; glShaderSource(brickVS,1,(const GLchar **)&ssource,NULL); glCompileShader(brickVS); glGetShaderiv(brickVS,GL_COMPILE_STATUS,&vertCompiled); GLuint brickProg = glCreateProgram(); glAttachShader(brickProg, brickVS); glAttachShader(brickProg, brickFS); glLinkProgram(brickProg); glUseProgram(brickProg); Any help would be much appreciated, as I'm brand new to this, I'm not sure if it's something im doing wrong in the code, or if its a different problem. Thanks! Adam
Advertisement
When you write shaders in OpenGL you are responsible for passing along the information you want to be passed along. one of the important things is passing along the vertex information. Is that color green hardcoded into the fragment shader or drawn from the vertex??

Also, I recommend looking up glsl on Lighthouse 3d... google search it. amazing tutorials :).
Thanks for the reply.

The green is forced in the fragment shader.

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

I've been looking at those tutorials, the GLSL book arrived today too so I've been going through that. Which is what I don't get. it seems it should work!


This topic is closed to new replies.

Advertisement