The texture system manages all game textures, texture packs, and dynamic texture loading. It consists of several key classes working together.
Textures Class
The main Textures class handles texture loading, binding, and management.
Constructor
Textures(TexturePackRepository *skins, Options *options)
Creates a new texture manager.
Game options for anaglyph mode, etc.
Texture Loading
loadTexture (by name)
int loadTexture(TEXTURE_NAME texId, const wstring& resourceName)
Loads a texture from the texture pack.
Resource path (e.g., “terrain/sun”)
Returns the OpenGL texture ID.
loadTexture (by index)
Loads a pre-indexed texture.
getTexture
int getTexture(BufferedImage *img, C4JRender::eTextureFormat format = C4JRender::TEXTURE_FORMAT_RxGyBzAw, bool mipmap = true)
Creates an OpenGL texture from an image.
format
C4JRender::eTextureFormat
default:"TEXTURE_FORMAT_RxGyBzAw"
Texture format
Texture Binding
bindTexture (by name)
void bindTexture(const wstring &resourceName)
Binds a texture by resource name, loading it if necessary.
bindTexture (by ID)
void bindTexture(int resourceId)
Binds a pre-loaded texture by ID.
bind
Binds an OpenGL texture directly.
clearLastBoundId
Clears the last bound texture ID, forcing a rebind on next use.
Dynamic Textures
loadHttpTexture
int loadHttpTexture(const wstring& url, const wstring& backup)
int loadHttpTexture(const wstring& url, int backup)
Loads a texture from an HTTP URL with a fallback.
HTTP URL to load texture from
Fallback texture (resource name or ID)
addHttpTexture
HttpTexture *addHttpTexture(const wstring& url, HttpTextureProcessor *processor)
Adds an HTTP texture with a custom processor.
removeHttpTexture
void removeHttpTexture(const wstring& url)
Removes an HTTP texture from the cache.
hasHttpTexture
bool hasHttpTexture(const wstring &url)
Checks if an HTTP texture is loaded.
Memory Textures (Console-specific)
loadMemTexture
int loadMemTexture(const wstring& url, const wstring& backup)
int loadMemTexture(const wstring& url, int backup)
Loads a texture from memory (for console features like Game Trophy System).
addMemTexture
MemTexture *addMemTexture(const wstring& url, MemTextureProcessor *processor)
Adds a memory texture with processor.
removeMemTexture
void removeMemTexture(const wstring& url)
Removes a memory texture.
Texture Updates
replaceTexture
void replaceTexture(intArray rawPixels, int w, int h, int id)
Replaces a texture’s pixel data (with anaglyph processing).
replaceTextureDirect
void replaceTextureDirect(intArray rawPixels, int w, int h, int id)
void replaceTextureDirect(shortArray rawPixels, int w, int h, int id)
Replaces a texture’s pixel data directly without processing.
releaseTexture
void releaseTexture(int id)
Releases an OpenGL texture.
OpenGL texture ID to release
Texture Pack Management
reloadAll
Reloads all textures (called when changing texture packs).
stitch
Stitches terrain and item textures into texture atlases.
tick
void tick(bool updateTextures, bool tickDynamics = true)
Updates animated textures and dynamic textures.
Whether to update texture data
Whether to tick dynamic textures (water, lava)
Utility Methods
readImage
BufferedImage *readImage(TEXTURE_NAME texId, const wstring& name)
Reads an image from the texture pack.
getMissingIcon
Icon *getMissingIcon(int type)
Gets the missing texture icon.
Icon type (0 = block, 1 = item)
IsTUImage / IsOriginalImage
static bool IsTUImage(TEXTURE_NAME texId, const wstring& name)
static bool IsOriginalImage(TEXTURE_NAME texId, const wstring& name)
Checks if a texture is from a Title Update or original game.
Static Settings
static bool MIPMAP;
static C4JRender::eTextureFormat TEXTURE_FORMAT;
Global texture settings for mipmapping and format.
TexturePackRepository Class
Manages available texture packs and texture pack selection.
Constructor
TexturePackRepository(File workingDirectory, Minecraft *minecraft)
Creates the texture pack repository.
Directory containing texture packs
Texture Pack Selection
selectSkin
bool selectSkin(TexturePack *skin)
Selects a texture pack.
Returns true if successful.
selectTexturePackById
bool selectTexturePackById(DWORD id)
Selects a texture pack by ID.
getSelected
TexturePack *getSelected()
Returns the currently selected texture pack.
isUsingDefaultSkin
bool isUsingDefaultSkin()
Returns whether the default texture pack is selected.
Texture Pack Management
updateList
Scans for available texture packs and updates the list.
getAll
vector<TexturePack *> *getAll()
Returns all available texture packs.
getTexturePackById
TexturePack *getTexturePackById(DWORD id)
Gets a texture pack by its ID.
getTexturePackCount
unsigned int getTexturePackCount()
Returns the number of available texture packs.
getTexturePackByIndex
TexturePack *getTexturePackByIndex(unsigned int index)
Gets a texture pack by index.
addTexturePackFromDLC
TexturePack *addTexturePackFromDLC(DLCPack *dlcPack, DWORD id)
Adds a texture pack from DLC.
DLC pack containing texture pack
Constants
static const DWORD DEFAULT_TEXTURE_PACK_ID = 0;
static const DWORD FOLDER_TEST_TEXTURE_PACK_ID = 1;
static const DWORD DLC_TEST_TEXTURE_PACK_ID = 2;
AbstractTexturePack Class
Base class for texture pack implementations.
Constructor
protected:
AbstractTexturePack(DWORD id, File *file, const wstring &name, TexturePack *fallback)
Texture pack file or directory
Fallback texture pack for missing resources
Resource Access
getResource
virtual InputStream *getResource(const wstring &name, bool allowFallback)
Gets a resource from the texture pack.
Resource path (e.g., “terrain.png”)
Whether to use fallback pack if resource not found
hasFile
virtual bool hasFile(const wstring &name, bool allowFallback)
virtual bool hasFile(const wstring &name) = 0
Checks if the texture pack contains a file.
getImageResource
virtual BufferedImage *getImageResource(const wstring& file, bool filenameHasExtension = false,
bool bTitleUpdateTexture = false, const wstring &drive = L"")
Loads an image from the texture pack.
getId
Returns the texture pack ID.
getName
virtual wstring getName()
Returns the texture pack name.
getDesc1 / getDesc2
virtual wstring getDesc1()
virtual wstring getDesc2()
Returns texture pack description lines.
getWorldName
virtual wstring getWorldName()
Returns the associated world name (for world-specific packs).
Loading/Unloading
load
virtual void load(Textures *textures)
Loads the texture pack.
unload
virtual void unload(Textures *textures)
Unloads the texture pack.
loadUI / unloadUI
virtual void loadUI()
virtual void unloadUI()
Loads/unloads UI-specific resources.
loadColourTable
virtual void loadColourTable()
Loads the color table for UI theming.
getColourTable
virtual ColourTable *getColourTable()
Returns the loaded color table.
Pack Icon
getPackIcon
virtual PBYTE getPackIcon(DWORD &dwImageBytes)
Gets the texture pack icon image data.
Output: size of image data in bytes
Returns pointer to image data.
Texture Name Enum
Pre-defined texture IDs:
enum TEXTURE_NAME {
TN__BLUR__MISC_PUMPKINBLUR,
TN__CLAMP__MISC_SHADOW,
TN_ART_KZ,
TN_ENVIRONMENT_CLOUDS,
TN_ENVIRONMENT_RAIN,
TN_ENVIRONMENT_SNOW,
TN_GUI_GUI,
TN_GUI_ICONS,
TN_TERRAIN,
TN_GUI_ITEMS,
// ... many more mob, block, and item textures
TN_COUNT
};
Example Usage
Basic Texture Loading
// Create texture manager
Textures *textures = new Textures(texturePackRepository, options);
// Load a specific texture
int terrainTexId = textures->loadTexture(TN_TERRAIN, L"terrain.png");
// Bind for rendering
textures->bindTexture(terrainTexId);
Changing Texture Packs
TexturePackRepository *repo = new TexturePackRepository(workDir, minecraft);
// Update available packs
repo->updateList();
// Get all packs
vector<TexturePack*> *packs = repo->getAll();
// Select a pack
if (packs->size() > 1) {
repo->selectSkin((*packs)[1]);
// Reload textures
textures->reloadAll();
}
Loading Player Skins
// Load player skin from URL
wstring skinUrl = L"http://example.com/skin.png";
int skinTexId = textures->loadHttpTexture(skinUrl, TN_MOB_CHAR);
// Bind for player rendering
textures->bindTexture(skinTexId);
Animated Textures
// In your render loop
void renderLoop() {
// Update animated textures (water, lava, portals)
textures->tick(true, true);
// Render world
// ...
}
Custom Texture Replacement
// Create custom texture data
intArray pixels; // ARGB format
pixels.size = 256 * 256;
pixels.values = new int[pixels.size];
// Fill with custom data
for (int i = 0; i < pixels.size; i++) {
pixels.values[i] = 0xFF00FF00; // Green
}
// Replace existing texture
textures->replaceTextureDirect(pixels, 256, 256, textureId);
Texture Pack Information
TexturePack *selected = repo->getSelected();
wstring name = selected->getName();
wstring desc1 = selected->getDesc1();
wstring desc2 = selected->getDesc2();
DWORD id = selected->getId();
printf("Using: %s\n", name.c_str());
printf(" %s\n", desc1.c_str());
printf(" %s\n", desc2.c_str());
- Texture atlases (stitched terrain/items) reduce draw calls
- Mipmaps improve rendering quality but use more VRAM
- HTTP textures are cached to avoid repeated downloads
- Anaglyph processing is expensive; only enable when needed
Calling reloadAll() is expensive as it reloads all textures. Only call when changing texture packs or when absolutely necessary.