New to opengl! I am having issues with passing colours from the program to vertex shader.
I am creating a grid where I want to control the color of each cell.Thus I am generating each cell and having two vbo's, one for the vertices, and another for the colour. I want my grid to look like this:
But I end up with:
I have confirmed if I generate the colour data in the vertex shader and then pass it to the fragment, I get the first case. It is only when I grab the colour data from the program that I get the second case.
Code for creating each vbo(written in go):
var vbo [2]uint32
gl.GenBuffers(2, &vbo[0])
gl.BindBuffer(gl.ARRAY_BUFFER, vbo[0])
gl.BufferData(gl.ARRAY_BUFFER, 4*len(points), gl.Ptr(points), gl.STATIC_DRAW)
gl.BindBuffer(gl.ARRAY_BUFFER, vbo[1])
gl.BufferData(gl.ARRAY_BUFFER, 4*3, gl.Ptr([]float32{0.5,0.5,0.0}), gl.STATIC_DRAW)
var vao uint32
gl.GenVertexArrays(1, &vao)
gl.BindVertexArray(vao)
gl.EnableVertexAttribArray(0)
gl.BindBuffer(gl.ARRAY_BUFFER, vbo[0])
gl.VertexAttribPointer(0, 3, gl.FLOAT, false, 0, nil)
gl.EnableVertexAttribArray(1)
gl.BindBuffer(gl.ARRAY_BUFFER, vbo[1])
gl.VertexAttribPointer(1, 3, gl.FLOAT, false, 0, nil)
Vertex Shader:
#version 410
/*layout (location=0) */in vec3 vp;
/*layout (location=1)*/ in vec3 colour;
/*layout (location=2)*/ out vec3 outcolour;
void main(){
gl_Position = vec4(vp,1.0);
//outcolour = vec3(0.5,0.5,0.0);
outcolour = vec3(colour);
}
Fragment Shader
#version 410
in vec3 outcolour;
out vec4 frag_colour;
void main(){
frag_colour = vec4(outcolour,1.0);
}
/*layout (location=1)*/
Why did you comment out important declarations like that? $\endgroup$