Drawing images with OpenGL
In order to draw an image on the OpenGL viewport, we should introduce another concept of OpenGL—the texture. A texture in OpenGL is usually a 2D image, and it is generally used to add visual detail to an object, which is mainly a triangle.
Since any kind of digital image is usually a rectangle, we should draw two triangles to compose a rectangle for the image, and then load the image as a texture and map it to the rectangles.
The texture uses a coordinate system that differs from the NDC that is used when we draw the triangles. Both of the x and y (axes) of the texture coordinate system are between 0 and 1, that is, the bottom-left corner is (0, 0), while the top-right corner is (1, 1). So, our vertices and coordinate ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access