libgdx API

com.badlogic.gdx.graphics
Class Texture

java.lang.Object
  extended by com.badlogic.gdx.graphics.Texture
All Implemented Interfaces:
Disposable

public class Texture
extends java.lang.Object
implements Disposable

A Texture wraps a standard OpenGL ES texture.

A Texture can be managed. If the OpenGL context is lost all managed textures get invalidated. This happens when a user switches to another application or receives an incoming call. Managed textures get reloaded automatically.

A Texture has to be bound via the bind() method in order for it to be applied to geometry. The texture will be bound to the currently active texture unit specified via GLCommon.glActiveTexture(int).

You can draw Pixmaps to a texture at any time. The changes will be automatically uploaded to texture memory. This is of course not extremely fast so use it with care. It also only works with unmanaged textures.

A Texture must be disposed when it is no longer used

Author:
badlogicgames@gmail.com

Nested Class Summary
static class Texture.TextureFilter
           
static class Texture.TextureWrap
           
 
Constructor Summary
Texture(FileHandle file)
           
Texture(FileHandle file, boolean useMipMaps)
           
Texture(FileHandle file, Pixmap.Format format, boolean useMipMaps)
           
Texture(int width, int height, Pixmap.Format format)
           
Texture(Pixmap pixmap)
           
Texture(Pixmap pixmap, boolean useMipMaps)
           
Texture(Pixmap pixmap, Pixmap.Format format, boolean useMipMaps)
           
Texture(java.lang.String internalPath)
           
Texture(TextureData data)
           
 
Method Summary
 void bind()
          Binds this texture.
 void bind(int unit)
          Binds the texture to the given texture unit.
static void clearAllTextures(Application app)
          Clears all managed textures.
static int createGLHandle()
           
 void dispose()
          Disposes all resources associated with the texture
 void draw(Pixmap pixmap, int x, int y)
          Draws the given Pixmap to the texture at position x, y.
 int getHeight()
           
 Texture.TextureFilter getMagFilter()
           
static java.lang.String getManagedStatus()
           
 Texture.TextureFilter getMinFilter()
           
 TextureData getTextureData()
           
 int getTextureObjectHandle()
           
 Texture.TextureWrap getUWrap()
           
 Texture.TextureWrap getVWrap()
           
 int getWidth()
           
static void invalidateAllTextures(Application app)
          Invalidate all managed textures.
 boolean isManaged()
           
 void load(TextureData data)
           
static void setAssetManager(AssetManager manager)
          Sets the AssetManager.
static void setEnforcePotImages(boolean enforcePotImages)
           
 void setFilter(Texture.TextureFilter minFilter, Texture.TextureFilter magFilter)
           
 void setWrap(Texture.TextureWrap u, Texture.TextureWrap v)
          Sets the Texture.TextureWrap for this texture on the u and v axis.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Texture

public Texture(java.lang.String internalPath)

Texture

public Texture(FileHandle file)

Texture

public Texture(FileHandle file,
               boolean useMipMaps)

Texture

public Texture(FileHandle file,
               Pixmap.Format format,
               boolean useMipMaps)

Texture

public Texture(Pixmap pixmap)

Texture

public Texture(Pixmap pixmap,
               boolean useMipMaps)

Texture

public Texture(Pixmap pixmap,
               Pixmap.Format format,
               boolean useMipMaps)

Texture

public Texture(int width,
               int height,
               Pixmap.Format format)

Texture

public Texture(TextureData data)
Method Detail

createGLHandle

public static int createGLHandle()

load

public void load(TextureData data)

bind

public void bind()
Binds this texture. The texture will be bound to the currently active texture unit specified via GLCommon.glActiveTexture(int).


bind

public void bind(int unit)
Binds the texture to the given texture unit. Sets the currently active texture unit via GLCommon.glActiveTexture(int).

Parameters:
unit - the unit (0 to MAX_TEXTURE_UNITS).

draw

public void draw(Pixmap pixmap,
                 int x,
                 int y)
Draws the given Pixmap to the texture at position x, y. No clipping is performed so you have to make sure that you draw only inside the texture region. Note that this will only draw to mipmap level 0!

Parameters:
pixmap - The Pixmap
x - The x coordinate in pixels
y - The y coordinate in pixels

getWidth

public int getWidth()
Returns:
the width of the texture in pixels

getHeight

public int getHeight()
Returns:
the height of the texture in pixels

getMinFilter

public Texture.TextureFilter getMinFilter()

getMagFilter

public Texture.TextureFilter getMagFilter()

getUWrap

public Texture.TextureWrap getUWrap()

getVWrap

public Texture.TextureWrap getVWrap()

getTextureData

public TextureData getTextureData()

isManaged

public boolean isManaged()
Returns:
whether this texture is managed or not.

getTextureObjectHandle

public int getTextureObjectHandle()

setWrap

public void setWrap(Texture.TextureWrap u,
                    Texture.TextureWrap v)
Sets the Texture.TextureWrap for this texture on the u and v axis. This will bind this texture!

Parameters:
u - the u wrap
v - the v wrap

setFilter

public void setFilter(Texture.TextureFilter minFilter,
                      Texture.TextureFilter magFilter)

dispose

public void dispose()
Disposes all resources associated with the texture

Specified by:
dispose in interface Disposable

setEnforcePotImages

public static void setEnforcePotImages(boolean enforcePotImages)
Parameters:
enforcePotImages - whether to enforce power of two images in OpenGL ES 1.0 or not.

clearAllTextures

public static void clearAllTextures(Application app)
Clears all managed textures. This is an internal method. Do not use it!


invalidateAllTextures

public static void invalidateAllTextures(Application app)
Invalidate all managed textures. This is an internal method. Do not use it!


setAssetManager

public static void setAssetManager(AssetManager manager)
Sets the AssetManager. When the context is lost, textures managed by the asset manager are reloaded by the manager on a separate thread (provided that a suitable AssetLoader is registered with the manager). Textures not managed by the AssetManager are reloaded via the usual means on the rendering thread.

Parameters:
manager - the asset manager.

getManagedStatus

public static java.lang.String getManagedStatus()

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)