A render system Texture is used to apply an image to a mesh during rendering. A texture engine object is used to store and manage a singular texture.
Nwge uses OpenGL for its rendering backend, consider giving the Texture article on the OpenGL wiki a read.
Many of nwge’s built-in rendering functions accept a reference to a texture that should be used during rendering. In case no texture is provided to such functions, a built-in blank texture is used instead.
When doing rendering via VertexArray and ShaderProgram, you must call the
Texture’s bind()
method to use it for subsequent rendering operations.
Additionally, you must handle texture coordinates in the shaders. The built-in
rendering functions simply accept a texture and texture coordinate parameter and
handle this for you.
Example:
void render() const override {
// bind the texture we want to use for drawing
mTexture.bind();
// ALWAYS call use() before drawing to ensure uniforms are updated
mShaderProgram.use();
// then issue the draw call.
mVAO.draw();
}
When a texture engine object is first created, it has no corresponding OpenGL
texture stored on the GPU. If you try to use such object during rendering, a
built-in “Missing Texture” texture will be used instead. Generally, you’ll be
loading textures from a bundle using its nqTexture
method.
Alternatively, you can load a texture from a file directly with the load()
method or upload an Image with the replace()
method.
Note that loading textures uses Image objects internally. Any image you can load into an Image object can also be uploaded to a Texture.
The nwge::render::Texture
class is defined in the <nwge/render/Texture.hpp>
header. Texture engine objects use object IDs with type 7
.
To view a list of textures, use r.textureList
:
> r.textureList
Currently loaded textures:
- Texture 07000000: future.bndl; testcardRGBA.png
Size: 256x256
Color channels: 4
- Texture 07000001: future.bndl; testcardRGBA.qoi
Size: 256x256
Color channels: 4
To disable or enable textures, use r.textures
:
> r.textures
Textures: Enabled
> r.textures d
Textures disabled
> r.textures
Textures: Disabled
> r.textures e
Textures enabled
To disable or enable texture filtering, use r.filterTextures
:
> r.filterTextures
Texture filtering is disabled
> r.filterTextures e
Enabled texture filtering
> r.filterTextures
Texture filtering is enabled
> r.filterTextures d
Disabled texture filtering