Rendering static images over game
When you want to show something like a health bar, a map, score or number of lives etc, I thought you might have to setup a specific view projection matrix, etc, but I just 'accidentally' did it by creating the graphic bounds using interpolated view projected vertices, e.g., the whole screen would be x and y -1,-1 to 1,1 respectively. In the vertex shader I just don't use a matrix to transform it and it works.
Is this how it's normally done anyway? Seems it would be quicker than doing it with matrices
It’s not “normal” (as in not a lot of people are doing this) but it is the best way to go in terms of efficiency for some things.
If it is for the HUD and, as you say, static objects, yes, this is best.
For moving objects, you would have to convert from pixel coordinates to normalized screen coordinates manually on the CPU, which will likely be slower to do than on the GPU, especially for batch rendering.
For your case of static objects, omitting the matrix transform (which just transforms things into -1 to 1 anyway) is the best way to go. Not only does it save on cycles but also on bandwidth, as there is less to send to the shaders.
L. Spiro
The reason I'm asking is because for my level editor (which will just use the c++ game engine from a c# front end) I'm going to need to overlay sprite-type icons on objects/zones, etc. this way seems pretty convenient to me
Although I guess this kind of changes the title to non-static graphics!
Thanks
Updating vertex buffers and calculating the normalized coordinates of vertices is slow. You have to decide based on your usage.
If it doesn’t move or moves rarely, use this method. If it moves a lot, use matrices.
HUD elements are just sprites, so there is no single answer. Use this to decide when you should use matrices and when you should not.
L. Spiro