Texture
This is a WIP project - Expect breaking changes to occur.
Overview
Texture is responsible for representing a 2D texture map, loaded from Disk and uploaded to the GPU.
Images are loaded using STBImage and supports the following formats:
- PNG
- JPG
- BMP
- TGA
- Most other modern image formats
The image is always forced to 4 channels (RGBA) regardless of the original format.
texture()
public Texture(String resourcePath) {}Loads an image from the classpath and uploads it to the GPU as a 2D texture.
The image is flipped vertically on load to ensure the UV coordinate 0,0 maps to the bottom-left corner,
which matches OpenGL convention.
bind()
public void bind(int unit) {}Binds the texture to the specified unit.
Most shaders sample from Unit 0, GL_TEXTURE0.
We use higher units for binding multiple textures in the same shader simultaneously, such as diffuse and specular maps.
unbind()
public void unbind() {}Unbinds the texture from GL_TEXTURE_2D on the currently active unit.
destroy()
public void destroy() {}Deletes the GPU texture object. Call when the texture is no longer needed, to free GPU resources.
Getters and Setters
getTextureID()
public int getTextureID() { return textureID; }Returns the OpenGL texture object handle.
getWidth()
public int getWidth() { return width; }Returns the width of the texture in pixels.
getHeight()
public int getHeight() { return height; }Returns the height of the texture in pixels.