Hello everyone, I am a new registered user.
I have just started learning OpenGL 2 weeks ago and I come from a WIN32 API background. To cut straight to the chase, I have a Hexagon drawn like this:
GLfloat vertices[] = { -0.25f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // Red
0.25f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // Green
0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f , // Blue
0.25f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, // Purple
-0.25f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, // White
-0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f // Yellow
};
Here are my shaders:
Vertex Shader
#version 430 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec3 color;
layout (location = 2) in vec3 newColor; //Er... what to do?!
uniform mat4 _resultantMatrix;
out vec3 outputColor;
void main()
{
vec4 currentPos = vec4(position, 1.0f);
gl_Position = _resultantMatrix * currentPos;
outputColor = color;
};
Fragment Shader
#version 430 core
in vec3 outputColor;
out vec4 Color;
uniform float Timer;
void main()
{
vec3 tempColor = outputColor * abs(sin(Timer));
tempColor.x = (sin(Timer) / 2) + 0.5f;
// tempColor.y = (cos(Timer) / 2) + 0.5f; Not doing what I expect it to do.
Color = vec4(tempColor, 1.0f);
};
glGenBuffers(1, &vao);
glBindVertexArray(vao);
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
// glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(21 * sizeof(GLfloat))); Stores the data in layout 2 but don't know what to do after!
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
// glEnableVertexAttribArray(2);
So like in my fragment shader, when I go tempColor.x = blahblahblah; it's changing more than one vertex color. If anyone could help me out I'd greatly appreciate it as I have been stuck for 2 hours trying to figure this thing out. I want all my vertices to have different colors while the program is being executed, and so far only 3 vertices change while the other 3 stays the same.
Thank you very much!