So in my render loop I am trying to draw a GL_POINT with a color. I have a shader that it runs through for matrix transformations. For some reason I can set the color, set the position, but not both. When I set the color the positions gl_Position gets messed up for some reason. I am sure this boils down to me not knowing much about GLSL. If somebody could help that would be great.
C code
internal void
Render(game_memory *Memory)
{
game_state *GameState = (game_state *)Memory->PermanentStorage;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glm::mat4 Model = glm::mat4(1.0f);
glm::mat4 Projection = glm::ortho(0.0f, 1280.0f, 720.0f, 0.0f, 0.0f, 1.0f);
GLint ModelUniform = glGetUniformLocation(GameState->ShaderProgram, "Model");
Assert(ModelUniform != -1);
glUniformMatrix4fv(ModelUniform, 1, GL_FALSE, glm::value_ptr(Model));
GLint ProjectionUniform = glGetUniformLocation(GameState->ShaderProgram, "Projection");
Assert(ProjectionUniform != -1);
glUniformMatrix4fv(ProjectionUniform, 1, GL_FALSE, glm::value_ptr(Projection));
r32 SinOfTime = sinf(GameState->ElapsedTime);
r32 CosOfTime = cosf(GameState->ElapsedTime);
v2 Location;
Location.x = 500.0f + 100.0f * SinOfTime;
Location.y = 500.0f + 100.0f * CosOfTime;
glDisable(GL_TEXTURE_2D);
glPointSize(10.0f);
glBegin(GL_POINTS);
glColor3f(fabs(SinOfTime), 0.0f, 0.0f);
glVertex3f(Location.x, Location.y, 0.0f);
glEnd();
glEnable(GL_TEXTURE_2D);
SDL_GL_SwapWindow(GameState->SdlWindow);
}
Additional code that sets the position attribute so I can use it.
GLint PosAttrib = glGetAttribLocation(GameState->ShaderProgram, "position");
glEnableVertexAttribArray(PosAttrib);
glVertexAttribPointer(PosAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
Fragment Shader
#version 130
in vec4 Color;
void main(void)
{
gl_FragColor = Color;
}
Vertex Shader
#version 130
in vec3 position;
out vec4 Color;
uniform mat4 Model;
uniform mat4 Projection;
void main(void)
{
Color = gl_Color; // If I comment this line out and not set the color the
// position sets fine. If its like this, color changes
// but the position sticks in the top left corner of
// the screen.
gl_Position = Projection * Model * vec4(position, 1.0);
}