Im pretty new to opengl, and I just cant figure out how to rotate this vbo/vao in 2d space. This is how I bind my coordinates:
float points[] =
{
0.0f, 0.10f, 0.0f,
-0.10f, -0.10f, 0.0f,
0.10f, -0.10f, 0.0f
};
glGenBuffers(1, &points_vbo);
glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(float), points, GL_STATIC_DRAW);
I place the vbo at vao[0]
glBindBuffer(GL_ARRAY_BUFFER, points_vbo);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
And I enable the array
glEnableVertexAttribArray(0);
and call to draw in the cpu, with
glDrawArrays(GL_TRIANGLES, 0, 3);
In my shader, I load the array by:
//glsl shader
layout ( location = 0 ) in vec3 vertex_position ;
void main()
{
gl_Position = vec4(vertex_position, 1.0);
}
Ive edited out the coloring/fragment to save space, but this is my problem: I can make a uniform to move my triangle around, but idk how to apply a transformation matrix to a vec4.
It seems the shader reads my vertex_position VAO one vec/element at a time, and trying to apply any matrix just gives an error.
How do you make or apply a rotation matrix on vao, am I inputting it wrong? All the uniforms I apply seem to only stretch, zoom, or move the overall triangle.
Sorry if the question is bad, or partially confused, shading is new to me overall, so thanks in advance.'
my shader:
#version 410 core
layout ( location = 0 ) in vec3 vertex_position ;
layout ( location = 1 ) in vec3 vertex_colour ;
out vec3 colour;
uniform vec3 fade=vec3(0.0,0.0,0.0); //fade
uniform float zoom=1.0;
uniform mat4 transform = mat4(vec4(1.0,0.0,0.0,0.0),
vec4(0.0,1.0,0.0,0.0), vec4(0.0,0.0,1.0,0.0), vec4(0.0,0.0,0.0,1.0));
void main()
{
colour=vertex_colour+fade;
gl_Position=transform*vec4(vertex_position,1.0);
}
this example https://open.gl/transformations and the answer made it doable.
uniform mat4 transform = mat4(vec4(1.0,0.0,0.0,0.0), vec4(0.0,1.0,0.0,0.0), vec4(0.0,0.0,1.0,0.0), vec4(1.0,1.0,1.0,1.0));
\$\endgroup\$