having trouble drawing anything (using VBO/vertex buffer/etc)
AngryCarrot789 opened this issue · comments
hi, i've been trying to just draw a triangle but it doesn't work at all. i tested my shader, and passing the matrix to the shader and drawing a triangle using Gl.Vertex3, and it does work. the triangle moves around. however, it doesn't work if i draw the triangle using a VAO
float[] verts = new float[]
{
// Bottom Left
-0.5f, -0.5f, 1.0f,
// Top Middle
0.0f, 0.5f, 1.0f,
// Bottom Right
0.5f, -0.5f, 1.0f
};
// Generate vertex array buffer
// VAO being a uint, VBO being an array of uints
VAO = Gl.GenVertexArray();
Gl.BindVertexArray(VAO);
// Generate vertex buffer
VBO[0] = Gl.GenBuffer();
{
Gl.BindBuffer(BufferTarget.ArrayBuffer, VBO[0]);
Gl.BufferData(BufferTarget.ArrayBuffer, (uint)verts.Length * sizeof(float), verts, BufferUsage.StaticDraw)
Gl.EnableVertexAttribArray(0);
Gl.VertexAttribPointer(0, 3, VertexAttribType.Float, true, 0, 0);
}
and then to draw, i firstly "use" the shader (by calling Gl.UseProgram), then i give my matrix to the shader (with Gl.UniformMatrix4), which i pass an array of 16 floats, representing the matrix, going across the rows and down the colums.
and then finally i draw the mesh, by binding the VAO and drawing arrays like so:
public void Draw()
{
Gl.BindVertexArray(VAO);
Gl.DrawArrays(PrimitiveType.Triangles, 0, Vertices.Count);
}
but nothing draws onscreen.
when drawing the mesh, instead of doing it the DrawArrays way, i instead use the Gl.Vertex3 way, it works fine:
(the player/camera can move using the mouse and keyboard, so i moved to the top right corner and looked down to the left a bit, and then the shader obviously "moves" the vertices around using the UniformMatrix4 function)
Gl.Begin(PrimitiveType.Triangles);
Gl.Vertex3(-0.5f, -0.5f, 0.0f);
Gl.Vertex3( 0.0f, 0.5f, 0.0f);
Gl.Vertex3( 0.5f, -0.5f, 0.0f);
Gl.End();
does anyone know what's happening?
i could just about use RenderDoc and in Pipeline State>Vertex Input, it showed a buffer that was 36 bytes long, and i know floats are 4 bytes, 36/4 = 9, so it did pass my triangle. im not sure what it means by "stride 12" though. and in Vertex Attribute Formats, it mentioned in_pos. but i couldnt take any more captures because every time i try to analyse another capture, RenderDoc crashes.
The normalized parameter should be false: Gl.VertexAttribPointer(0, 3, VertexAttribType.Float, **false**, 0, 0);
If it doesn't solve the problem, probably in the MVP matrix:
representing the matrix, going across the rows and down the colums
Matrices should be column major. Double check that.
Stride is the distance between two contiguous elements (vec3 -> 3 * sizeof(float) = 12
); it could be greater than 12 in the case you configure interleaved attributes.
I'd suggest you to use more appropriate and popular Q&A site suck as stackoverflow, I'll get more help and guidance.