[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.8.1 Textures

A texture is an image that can be applied onto the surface of a three dimensional model. In Ogre, textures are represented by the Texture resource class.

Creating a texture

Textures are created through the TextureManager. In most cases they are created from image files directly by the Ogre resource system. If you are reading this, you most probably want to create a texture manually so that you can provide it with image data yourself. This is done through TextureManager::createManual:

ptex = TextureManager::getSingleton().createManual(
    "MyManualTexture", // Name of texture
    "General", // Name of resource group in which the texture should be created
    TEX_TYPE_2D, // Texture type
    256, // Width
    256, // Height
    1, // Depth (Must be 1 for two dimensional textures)
    0, // Number of mipmaps
    PF_A8R8G8B8, // Pixel format

This example creates a texture named MyManualTexture in resource group General. It is a square two dimensional texture, with width 256 and height 256. It has no mipmaps, internal format PF_A8R8G8B8 and usage TU_DYNAMIC_WRITE_ONLY.

The different texture types will be discussed in Texture Types. Pixel formats are summarised in Pixel Formats.

Texture usages

In addition to the hardware buffer usages as described in See section Buffer Usage there are some usage flags specific to textures:


Mipmaps for this texture will be automatically generated by the graphics hardware. The exact algorithm used is not defined, but you can assume it to be a 2x2 box filter.


This texture will be a render target, i.e. used as a target for render to texture. Setting this flag will ignore all other texture usages except TU_AUTOMIPMAP.


This is actually a combination of usage flags, and is equivalent to TU_AUTOMIPMAP | TU_STATIC_WRITE_ONLY. The resource system uses these flags for textures that are loaded from images.

Getting a PixelBuffer

A Texture can consist of multiple PixelBuffers, one for each combo if mipmap level and face number. To get a PixelBuffer from a Texture object the method Texture::getBuffer(face, mipmap) is used:

face should be zero for non-cubemap textures. For cubemap textures it identifies the face to use, which is one of the cube faces described in See section Texture Types.

mipmap is zero for the zeroth mipmap level, one for the first mipmap level, and so on. On textures that have automatic mipmap generation (TU_AUTOMIPMAP) only level 0 should be accessed, the rest will be taken care of by the rendering API.

A simple example of using getBuffer is

// Get the PixelBuffer for face 0, mipmap 0.
HardwarePixelBufferSharedPtr ptr = tex->getBuffer(0,0);

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on August 20, 2012 using texi2html 5.0.