Can't get your first hello world program(that is, render a triangle) for OpenGL/DirectX working?
Below is a handy checklist of things that you should check,
and that can be possible causes.
Conversation
Replying to
*your view and projection matrices might be wrong.
by hand, multiply every vertex by your mvp matrix, and perspective divide(or use renderdoc)
if resulting vertex is not in the ndc box(x in range [-1,+1], y in [-1,+1], z in [-1,+1] for OpenGL)
then of course it wont be rendered!
2
5
* Make sure to clear the depth and color of the default framebuffer, at beginning of every frame!
you get messed up result when moving the camera otherwise.
1
1
2
* Also, make sure to understand and then set the depth comparison function. If your geometry doesnt pass
the depth test, then it won't be rendered at all!
1
2
* make sure your constant buffers/uniforms are correctly uploaded to the shader!
otherwise, your MVP matrix will be filled with zeroes, and you dont want that!
this is easy to check in renderodc.
1
3
* also make sure ALL your vertex data is correctly uploaded.
it easily happens that you upload too little of your vertex data, due to some
miscalculation. again, this is easy to verify in renderdoc.
1
2
* backface culling means that backfacing triangles(often, counter-clockwise triangles) are not rendered,
and this is another reason your triangle might not be rendered.
for debugging purposes, try turning off backface culling.
1
3
* and in 90% of the cases, it's probably your view and projection matrices that are messed up. so make sure you understand those, and that they are correct!
2
4
Replying to
Step N: use an explicit API (D3D12 or Vk), because you'll almost certainly understand what you're doing by the time you get that first triangle
Replying to
Thanks! It'd be nice to have a simple library of utils to validate inputs. Nothing complex, basically the list you just provided but would support left and right handed coordinate systems. Seems relatively straightforward and could collectively save countless engineering hours.
1


