I am following LearnOpenGL - Hello Triangle. The triangle example works perfectly. When I, however, attempt to render the square by utilizing the element buffer object too, everything compiles but nothing appears on the screen. No errors reported. I feel like I have checked every line of code twice now.
The official code: Code Viewer. Source code: src/1.getting_started/2.2.hello_triangle_indexed/hello_triangle_indexed.cpp
My code: attached to the file The shader code is literally copy pasted and the exact same in both the square and triangle example. It is 100% correct.
Your indices are of type usize
(normally 64 bit unsigned integer):
const indices = [_]usize{
0, 1, 3,
1, 2, 3,
};
But you are telling OpenGL that your indices are (32 bit) unsigned integers:
c.glDrawElements(c.GL_TRIANGLES, 6, c.GL_UNSIGNED_INT, @ptrFromInt(0));
You should change your index buffer to type u32
:
const indices = [_]u32{
0, 1, 3,
1, 2, 3,
};
1 Like
Oh my goodness I wouldnt have found that in a thousand years thank you so much lol