R
R
ratatyq2017-03-21 10:40:12
OpenGL
ratatyq, 2017-03-21 10:40:12

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? 
}

Why do we even write this line gl_FragColor = u_Color? After all, we then `bind the data` in this way:
int uColor;
void bindDate() {
uColor = glGetUniformLocation(programId, "u_Color");
vertexDate.position(2); // Из за того что в массиве данных даем еще RGBA
glVertexAttribPointer(aColorLocation, 3, GL_FLOAT, false, 20, vertexData);
glEnableVertexAttribArray(aColorLocation);
}

And it's also not very clear why the uColor variable has an int data type, because then we pass everything to GL_FLOAT, tobish in a floating point data type ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
toly19, 2017-03-21
@toly19

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); //непонятно что :)

In short, you connect the vertexData buffer to aColorLocation, but this data does not affect the color of the pixel

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question