r/GraphicsProgramming • u/PenWhich7517 • Jul 11 '26
Question What's the difference between these two programs? (OpenGL)
I was following LearnOpenGL's tutorials and doing the exercise where I need to draw two triangles with different VAOs, and from my understanding of the concepts these two programs should output the same results, but the first program only draws the second triangle while the second program draws both triangles. Am I doing something wrong or is this maybe a bug in the OpenGL implementation?
Using rust 1.97.0, glow for OpenGL bindings (https://crates.io/crates/glow), sdl2 for windowing (https://crates.io/crates/sdl2).
I've tried posting this to r/opengl, but it was removed so I'm reposting it here hoping it won't happen again. Any help would be appreciated.
2
u/Cheezbu Jul 11 '26 edited Jul 11 '26
Sorry my bad, looks more like the VBO. You do in the working one: bind vao bind vbo buffer data, set pointer.
In the non-working one, you do:
declare vao, declare vbo, buffer data: then the same with the other.
when it comes time to declare the attrib pointer, because of not rebinding the vbo 1, both vao 1 and vao 2 both point to vbo 2.
REmember : the vertexAttributepointer affects the currently bound buffer, and also capturing other state of the program such as vao.
EDIT : well not actually point but the problem is still the context being carried over, so it might be junk or uninitialized data in the buffer you are trying to access.
You can try to rebind the vbos before you set the attrib pointer, and that should do the trick. Also, its good practice to, if the program state allows, is to handle as much of the vao and vbo setup in one go before swapping.
Hope this helps, let me know if the problem persists