My first shader

Hi All,

I managed to put at work my first - very easy - fragment shader:

void main()
		gl_FragColor = vec4(0.9,0.4,0.8,1.0);

Suppose I draw 10 triangles, I want to use the shader only on the third and fourth. How can I do?

I use the following code:

myProgram = glCreateProgram();

  glAttachShader(myProgram, myShader);





You could bind program 0 (glUseProgram(0)) to draw triangles 1-2, 5-10, then bind program myProgram to draw triangles 3-4. :slight_smile:

this post should be in the shader section, but anyway, here you can find a great tutorial to learn the basics of glsl. :slight_smile:

Hi All,

I didn’t know there was a dedicated forum.

HexCat, thanks I didn’t know I could do that.

Now probably I see the problem.

I can’t have a fragment only shader, can I?

I noticed that all the examples I saw provide both vertex and fragment shader.



I can’t have a fragment only shader, can I?

No you can’t, a vertex shader, as its name says, processes on vertices, fragment shader works on fragments and always use interpolated data computed in the vertex shader (at least fragment position). So you can say, “so a vertex shader could work alone!” And no it is not possible, since fragment shader have to do all the work about “pixels color on screen” since using a shader disable the fixed pipeline that does for exemple “gouraud shading” “texturing”…

And please read carefully the tutorial i gave you in my last post, you will find inside answers of all the very basic questions you ask (without wanting to be offensive :slight_smile: ). Then don’t hesitate to come back ask more questions.

Yes, you can. OpenGL supports mixing fixed function vertex processing and fragment shaders, and vice versa.

Oh yes you are right Xmas! I apologize, I was convinced of the opposite until I found the paragraph in the glsl spec that talks about that.

But in my opinion, this seems useless and dangerous, source of many bugs since you have to take care of computing all the necessary data used by the fixed functionality in the vertex shader when you don’t use a fragment shader. On the other hand it looks like easier to not use a vertex shader but it limits almost always what you can do in the fragment shader

Using only one shader and the ffp for the rest is usually not very useful. The only case, where it is sometimes convenient, is when you only want to change the vertex-processing, such that you don’t need to write a dedicated fragment-shader.

Using no vertex-shader, but a fragment-shader is more a pain, than anything else.