I have been working on some functions to try and get to understand OpenGL (I have started to learn it a short time ago). I am was trying to make the typical “spinning cube” application. I wanted to use vertex colors for the sides of the cube (I know that they aren’t normally used, but I don’t know any alternative yet). I am using the following shaders:
Vertex Shader
#version 400
layout(location = 1) in vec3 vcolor;
in vec3 vp;
out vec3 fragmentColor;
void main () {
gl_Position = vec4 (vp, 1.0);
fragmentColor = vcolor;
}
Fragment Shader
#version 400
in vec3 fragmentColor;
out vec3 color;
void main () {
color = fragmentColor;
}
The shader compiles correctly, and all, but I keep getting a black screen. If I change the line color = fragmentColor; to color = vec4( 1.0, 0.0, 0.0, 1.0); it works, which has led me to believe the issue may have been with the glVertexAttribPointer function:
void SimpleMesh::BindVBO ( int index, int attribInd )
{
glBindBuffer ( GL_ARRAY_BUFFER, vboVec_[ index ]);
glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, attribInd, NULL );
}
But I see nothing wrong with it. I know the location is 1, I know the color vector is not null, and in a vec3 format, I checked any possible cause I could think of, but I really pinpoint the cause of the issue. If anyone could help I’d be grateful.
Related to this, I would like to ask: since vertex colors are rarely used, how would one color the faces of a square?