Change vertex color in vertex shader

Is it possible to set the color of one vertex using the vertex shader program GLSL in the same way as gl_Position changes the position of the vertex?

+3
source share
1 answer

I think I thought too much about your experience with GLSL. My apologies.

For versions of GLSL prior to version 1.30, you want to write gl_FrontColor or gl_BackColor, which are available in the vertex shader. Check out the changes to the GLSL 1.10 specification ( http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.10.59.pdf ) to learn more about them or the GL_ARB_vertex_shader extension specification.

gl_FrontColor gl_BackColor - 4D RGBA-, .

, , . , . , glColorPointer glDrawArrays, glDrawElements, glDrawRangeElements glMultiDrawElements. , glColorPointer, gl_Color . gl_Color per-vertex.

, , gl_Color. gl_FragColor.

:

void main()
{
    gl_FrontColor = gl_Color;
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

:

void main()
{
    gl_FragColor = gl_Color;
}

, , OpenGL, ftransform().

void main()
{
    ftransform();
}
+8

Source: https://habr.com/ru/post/1739295/


All Articles