colagl
September 27, 2022, 5:17am
#1
```
GLfloat vVertices[] = {
0.0f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f
};
```

Here, first three vectors are for three vertices for triangle. Last three vectors are used for colors. I get a RGB triangle like this:

My question is: how is color assigned to each vertex inside triangle? I did not set color for all the vertices of this triangle. I think, the last three vectors are colors for three vertices of corner of the triangle.

However your GL code sets up the vertex attributes (you didn’t include any of this in your post).

Crowbar
September 28, 2022, 7:30pm
#3
I think you’re confusing pixels (fragments) and vertices. A triangle only has three vertices, whose all colors you did set. As for fragments, yes, in OpenGL you can choose from a few ways of interpolating the values. Refer to:
https://www.khronos.org/opengl/wiki/Type_Qualifier_(GLSL)#Interpolation_qualifiers
Also:

In mathematics, linear interpolation is a method of curve fitting using linear polynomials to construct new data points within the range of a discrete set of known data points.
If the two known points are given by the coordinates
(
x
0
,
y
0
)
{\displaystyle (x_{0},y_{0})}
and
(
...