Tucano
0.1
A library for rapid prototyping with modern OpenGL and GLSL
|
An OpenGL texture in its simplest form, is an image. But it can also be though as an array (1D, 2D, or 3D). Each array element is another array of 1, 2, 3, or 4 elements.
The Texture Class is useful for easily:
Tucano has support for only very simple image formats, such as PPM and PAM. In this case, you can create the texture by using one of the importers, for example:
Tucano does not, however, read other image files (jpg, png, tiff, etc...), you need an external library for this, such as Qt or CImg. In this case the Texture receives an array with the image data. For example, with Qt:
To access a Texture from a Shader Program, the Texture must be bound to one of the Texture Units of the Graphics Card. This can be done manually by allocating and keeping track of which Texture is bound to which unit, and associating the same slot id
in the Shader, using the layout(binding=id)
qualifier, or be setting an Uniform.
Tucano makes everything transparent by using the TextureManager Class. It is a singleton class that is accessed by all Texture instances. Not that there is no need to include or use the Texture Manager directly. Every time you bind a Texture, the Texture Manager will look for the first empty unit, bind the Texture to that unit and return the unit id. To make things easier, a Texture can be bound and passed to a shader with a single call:
The Texture is readily available in the Shader code as:
Don't forget to unbind
the Texture after usage, otherwise you might quickly run out of Texture Slots.