0
votes

I need only a vertex shader functionality, but without fragment shader my object is just black. How do I write a fragment shader, if i need one, so the object won't lose it's color? The closest i get to it is the following set:

In vertex shader:

// some functionality regarding changing objects position
gl_FrontColor = gl_Color;
gl_FrontSecondaryColor = gl_SecondaryColor;
gl_BackColor = gl_Color;
gl_BackSecondaryColor = gl_SecondaryColor;

And not loading fragment shader at all. That way object is colored but without texture. How do I keep the object's coloring/texturing as it is?

1

1 Answers

0
votes

The simplest fragment shader you could write to just use the color you assign in the vertex shader is:

void main()
{
    gl_FragColor = gl_Color;
}

To get texturing you would need to change your vertex shader to pass along the texture coordinates by adding the following line:

gl_TexCoord[0] = gl_MultiTexCoord0;

Your fragment shader would then be:

uniform sampler2D tex_sampler;
void main()
{
    gl_FragColor = texture2D(tex_sampler,gl_TexCoord[0].st);
}

This will apply the texture to your object. I'm not sure what your original setup was like but if you want to do lighting then you will need to find out what type of lighting was originally used and implement that in the shaders as well.