I know how to draw models, but I don't know how to draw a fullscreen background image.
I think I should draw it at the zfar of the camera. But I have no idea how to calculate its size...
In sketchfab, it seems the background image can implement the css propertybackground-size: cover
. And I notice sketchfab do not implement it by css.
I really want to know how to implement this!
Create a simple shader which draws a texture, without any transformations:
Vertex shader:
Fragment shader:
Create a an array buffer, with the 4 corner points of the XY-plane, of the Normalized device space, from (-1, -1) to (1, 1).
Draw the rectangle to the entire canvas, by using the shader. Since you draw on every fragment, you do not need to clear the color plane. But you have to disable the depth test.
Enable the depth test and clear the depth buffer, before you draw the geometry of the scene:
Note, when you load the texture, then you have to ensure that the width and the height of the texture is a power of 2.
See the code snippet: