Answer the question
In order to leave comments, you need to log in
Why do we write line data in shaders (glsl)?
Hello, I’m just starting to delve into how to draw primitives in OpenGl, of course, a lot of things are not clear and a lot of stupid questions were asked and the same stupid answers were given, and maybe this question will also be very stupid, but I don’t understand why we write like this:
uniform vec4 u_Color;
void main()
{
gl_FragColor = u_Color; // Зачем мы тут присваиваем gl_FragColor?
}
int uColor;
void bindDate() {
uColor = glGetUniformLocation(programId, "u_Color");
vertexDate.position(2); // Из за того что в массиве данных даем еще RGBA
glVertexAttribPointer(aColorLocation, 3, GL_FLOAT, false, 20, vertexData);
glEnableVertexAttribArray(aColorLocation);
}
Answer the question
In order to leave comments, you need to log in
The first code is the fragment shader code. Its essence is to return the color of the pixel (gl_FragColor).
This color you take from the u_Color uniform, that is, everything that OpenGL renders will be the color of u_Color.
glVertexAttribPointer(aColorLocation, 3, GL_FLOAT, false, 20, vertexData);//тут подключаешь данные из буфера к атрибуту шейдера- указываешь, где брать данные
glEnableVertexAttribArray(aColorLocation); // включаешь атрибут
vertexDate.position(2); //непонятно что :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question