reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

A wrapper class for an OpenGL texture. More...

#include <ofTexture.h>

Inheritance diagram for ofTexture:
ofBaseDraws

Public Member Functions

 ofTexture ()
 Construct an ofTexture instance.
 
 ofTexture (const ofTexture &mom)
 Construct an ofTexture from an existing ofTexture.
 
 ofTexture (ofTexture &&mom)
 
virtual void allocate (const ofTextureData &textureData)
 Allocate the texture using the given settings.
 
virtual void allocate (const ofTextureData &textureData, int glFormat, int pixelType)
 Allocate the texture using the given settings and custom format.
 
virtual void allocate (int w, int h, int glInternalFormat)
 Allocate texture of a given size and format.
 
virtual void allocate (int w, int h, int glInternalFormat, int glFormat, int pixelType)
 Allocate texture of a given size and format.
 
virtual void allocate (int w, int h, int glInternalFormat, bool bUseARBExtension)
 Allocate texture of a given size and format. Specify texture type.
 
virtual void allocate (int w, int h, int glInternalFormat, bool bUseARBExtension, int glFormat, int pixelType)
 Allocate texture of a given size, format, & type.
 
virtual void allocate (const ofPixels &pix)
 Allocate texture using an ofPixels instance.
 
virtual void allocate (const ofPixels &pix, bool bUseARBExtension)
 Allocate texture using an ofPixels instance and type.
 
virtual void allocate (const ofShortPixels &pix)
 Allocate texture using an ofShortPixels instance.
 
virtual void allocate (const ofShortPixels &pix, bool bUseARBExtension)
 Allocate texture using an ofShortPixels instance and type.
 
virtual void allocate (const ofFloatPixels &pix)
 Allocate texture using an ofFloatPixels instance.
 
virtual void allocate (const ofFloatPixels &pix, bool bUseARBExtension)
 Allocate texture using an ofShortPixels instance and type.
 
void allocateAsBufferTexture (const ofBufferObject &buffer, int glInternalFormat)
 Allocate texture as a Buffer Texture.
 
bool isAllocated () const
 Determine whether the texture has been allocated.
 
 OF_DEPRECATED_MSG ("Use isAllocated instead", bool bAllocated() const)
 Has the texture been allocated?
 
virtual ~ofTexture ()
 Destroy an ofTexture instance.
 
ofTextureoperator= (const ofTexture &mom)
 Copy a given ofTexture into this texture.
 
ofTextureoperator= (ofTexture &&mom)
 
void clear ()
 Clears the texture.
 
void setUseExternalTextureID (GLuint externTexID)
 Set the texture ID.
 
void loadData (const uint8_t *const data, int w, int h, int glFormat)
 Load byte pixel data.
 
void loadData (const uint16_t *data, int w, int h, int glFormat)
 Load short (2 byte) pixel data.
 
void loadData (const uint32_t *data, int w, int h, int glFormat)
 
void loadData (const int8_t *data, int w, int h, int glFormat)
 
void loadData (const int16_t *data, int w, int h, int glFormat)
 
void loadData (const int32_t *data, int w, int h, int glFormat)
 
void loadData (const float *data, int w, int h, int glFormat)
 Load float pixel data.
 
void loadData (const ofPixels &pix)
 Load pixels from an ofPixels instance.
 
void loadData (const ofShortPixels &pix)
 Load pixels from an ofShortPixels instance.
 
void loadData (const ofFloatPixels &pix)
 Load pixels from an ofFloatPixels instance.
 
void loadData (const ofPixels &pix, int glFormat)
 Load pixels from an ofPixels instance and specify the format.
 
void loadData (const ofShortPixels &pix, int glFormat)
 Load pixels from an ofShortPixels instance & specify the format.
 
void loadData (const ofFloatPixels &pix, int glFormat)
 Load pixels from an ofFloatPixels instance and specify the format.
 
void loadData (const void *data, int w, int h, int glFormat, int glType)
 Load byte pixel data.
 
void loadData (const ofBufferObject &buffer, int glFormat, int glType)
 Load pixels from an ofBufferObject.
 
void loadScreenData (int x, int y, int w, int h)
 Copy an area of the screen into this texture.
 
void draw (float x, float y) const
 
void draw (float x, float y, float z) const
 
void draw (const glm::vec3 &pos) const
 
void draw (float x, float y, float w, float h) const
 Draw at a position with the specified size.
 
void draw (float x, float y, float z, float w, float h) const
 Draw the texture at a given size witdh and depth.
 
void draw (const glm::vec3 &pos, float w, float h) const
 
void draw (const glm::vec3 &p1, const glm::vec3 &p2, const glm::vec3 &p3, const glm::vec3 &p4) const
 Draws the texture at 4 points passed in as if you created 4 glVertices.
 
void drawSubsection (float x, float y, float w, float h, float sx, float sy) const
 Draw a subsection of the texture.
 
void drawSubsection (float x, float y, float z, float w, float h, float sx, float sy) const
 Draw a subsection of the texture with depth.
 
void drawSubsection (float x, float y, float w, float h, float sx, float sy, float sw, float sh) const
 Draw a subsection of the texture with an offset.
 
void drawSubsection (const ofRectangle &drawBounds, const ofRectangle &subsectionBounds) const
 Draw a subsection of the texture with an offset.
 
void drawSubsection (float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const
 Draw a subsection of the texture with an offset and depth.
 
ofMesh getQuad (const glm::vec3 &p1, const glm::vec3 &p2, const glm::vec3 &p3, const glm::vec3 &p4) const
 
ofMesh getMeshForSubsection (float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh, bool vflipped, ofRectMode rectMode) const
 Get a mesh that has the texture coordinates set.
 
void bind (int textureLocation=0) const
 Bind the texture.
 
void unbind (int textureLocation=0) const
 Unbind the texture.
 
const ofTexturegetAlphaMask () const
 
float getHeight () const
 Display height of texture.
 
float getWidth () const
 Display width of texture.
 
void setAnchorPercent (float xPct, float yPct)
 Set the anchor point the texture is drawn around as a percentage.
 
void setAnchorPoint (float x, float y)
 Set the anchor point the texture is drawn around in pixels.
 
void resetAnchor ()
 Reset the anchor point to (0, 0).
 
glm::vec2 getCoordFromPoint (float xPos, float yPos) const
 Helper to convert display coordinate to texture coordinate.
 
glm::vec2 getCoordFromPercent (float xPts, float yPts) const
 Helper to convert display coordinate to texture coordinate.
 
void setAlphaMask (ofTexture &mask)
 Set another ofTexture to use as an alpha mask.
 
void disableAlphaMask ()
 Disable the alpha mask.
 
void setTextureWrap (GLint wrapModeHorizontal, GLint wrapModeVertical)
 Set texture wrapping.
 
void setTextureMinMagFilter (GLint minFilter, GLint magFilter)
 Set texture minification/magnification scaling filters.
 
void setTextureMatrix (const glm::mat4 &m)
 Sets a texture matrix to be uploaded whenever the texture is bound.
 
const glm::mat4 & getTextureMatrix () const
 
bool isUsingTextureMatrix () const
 
void disableTextureMatrix ()
 Disable the texture matrix.
 
void setCompression (ofTexCompression compression)
 Set the texture compression.
 
void setRGToRGBASwizzles (bool rToRGBSwizzles)
 Swizzle RGBA to grayscale with alpha in the red channel.
 
void setSwizzle (GLenum srcSwizzle, GLenum dstChannel)
 Swizzle a channel to another.
 
void readToPixels (ofPixels &pixels) const
 Read current texture data from the GPU into pixels.
 
void readToPixels (ofShortPixels &pixels) const
 Read current texture data from the GPU into pixels.
 
void readToPixels (ofFloatPixels &pixels) const
 Read current texture data from the GPU into pixels.
 
void copyTo (ofBufferObject &buffer) const
 Copy the texture to an ofBufferObject.
 
ofTextureDatagetTextureData ()
 Internal texture data access.
 
const ofTextureDatagetTextureData () const
 Const version of getTextureData().
 
void enableMipmap ()
 Sets flag allowing texture to auto-generate a mipmap.
 
void disableMipmap ()
 Sets flag disallowing texture to auto-generate mipmap.
 
void generateMipmap ()
 Generate mipmap for the current texture.
 
bool hasMipmap () const
 Find out if a mipmap has been generated for the current texture.
 
virtual void draw (float x, float y) const
 Draw at a position at the native size.
 
virtual void draw (float x, float y, float w, float h) const=0
 Draw at a position with the specified size.
 
virtual void draw (const glm::vec2 &point) const
 Draw at a position at the native size.
 
virtual void draw (const ofRectangle &rect) const
 Draw at a position and size specified by a rectangle.
 
virtual void draw (const glm::vec2 &point, float w, float h) const
 Draw at a position.
 
- Public Member Functions inherited from ofBaseDraws
virtual ~ofBaseDraws ()
 Destroy the abstract object.
 

Public Attributes

ofTextureData texData
 

Protected Member Functions

void enableTextureTarget (int textureLocation) const
 Enable a texture target.
 
void disableTextureTarget (int textureLocation) const
 Disable a texture target.
 

Protected Attributes

glm::vec3 anchor
 The texture's anchor point.
 
bool bAnchorIsPct
 

Detailed Description

A wrapper class for an OpenGL texture.

Constructor & Destructor Documentation

◆ ofTexture() [1/3]

ofTexture::ofTexture ( )

Construct an ofTexture instance.

and Allocation

◆ ofTexture() [2/3]

ofTexture::ofTexture ( const ofTexture mom)

Construct an ofTexture from an existing ofTexture.

Parameters
momThe ofTexture to copy. Reuses internal GL texture ID.

◆ ofTexture() [3/3]

ofTexture::ofTexture ( ofTexture &&  mom)

◆ ~ofTexture()

ofTexture::~ofTexture ( )
virtual

Destroy an ofTexture instance.

ofTexture keeps a reference count for the internal OpenGL texture ID. Thus, the texture ID is only released if there are no additional references to the internal texture ID.

Member Function Documentation

◆ allocate() [1/12]

void ofTexture::allocate ( const ofFloatPixels pix)
virtual

Allocate texture using an ofFloatPixels instance.

Same as void allocate(const ofPixels& pix), except using ofFloatPixels.

See also
allocate(const ofPixels& pix)
Parameters
pixReference to ofFloatPixels instance.

◆ allocate() [2/12]

void ofTexture::allocate ( const ofFloatPixels pix,
bool  bUseARBExtension 
)
virtual

Allocate texture using an ofShortPixels instance and type.

Same as void void allocate(const ofPixels& pix), except using ofShortPixels.

See also
allocate(const ofFloatPixels& pix)
Parameters
pixReference to ofFloatPixels instance.
bUseARBExtensionSet to true to use rectangular textures.

◆ allocate() [3/12]

void ofTexture::allocate ( const ofPixels pix)
virtual

Allocate texture using an ofPixels instance.

Todo:
Not sure how the two texture format parameters are different: glFormat & glInternalFormat.

Pixel type and OpenGL format are determined from pixel settings.

Parameters
pixReference to ofPixels instance.

◆ allocate() [4/12]

void ofTexture::allocate ( const ofPixels pix,
bool  bUseARBExtension 
)
virtual

Allocate texture using an ofPixels instance and type.

This lets you overide the default OF texture type in case you need a square GL_TEXTURE_2D texture.

Warning
ARB textures are not available in OpenGL ES.
See also
ofEnableArbTex()
allocate(const ofPixels& pix)
Parameters
pixReference to ofPixels instance.
bUseARBExtensionSet to true to use rectangular textures.

◆ allocate() [5/12]

void ofTexture::allocate ( const ofShortPixels pix)
virtual

Allocate texture using an ofShortPixels instance.

Same as void allocate(const ofPixels& pix), except using ofShortPixels.

See also
allocate(const ofPixels& pix)
Parameters
pixReference to ofShortPixels instance.

◆ allocate() [6/12]

void ofTexture::allocate ( const ofShortPixels pix,
bool  bUseARBExtension 
)
virtual

Allocate texture using an ofShortPixels instance and type.

Same as void void allocate(const ofPixels& pix), except using ofShortPixels.

See also
allocate(const ofShortPixels& pix)
Parameters
pixReference to ofShortPixels instance.
bUseARBExtensionSet to true to use rectangular textures.

◆ allocate() [7/12]

void ofTexture::allocate ( const ofTextureData textureData)
virtual

Allocate the texture using the given settings.

This is useful if you need manual control over loading a number of textures with the same settings. Make sure to set the texture data parameters first.

Parameters
textureDataThe settings to use when allocating the ofTexture.

◆ allocate() [8/12]

void ofTexture::allocate ( const ofTextureData textureData,
int  glFormat,
int  pixelType 
)
virtual

Allocate the texture using the given settings and custom format.

Parameters
textureDataThe settings to use when allocating the ofTexture.
glFormatGL texture format: GL_RGBA, GL_LUMINANCE, etc.
pixelTypeGL pixel type: GL_UNSIGNED_BYTE, GL_FLOAT, etc.

◆ allocate() [9/12]

void ofTexture::allocate ( int  w,
int  h,
int  glInternalFormat 
)
virtual

Allocate texture of a given size and format.

The width (w) and height (h) do not necessarily need to be powers of 2, but they do need to be large enough to contain the data you will upload to the texture.

The internal data type glFormat describes how OpenGL will store this texture internally. For example, if you want a grayscale texture, you can use GL_LUMINANCE. You can upload what ever type of data you want (using loadData()) but internally, opengl will store the information as grayscale. Other types include: GL_RGB, GL_RGBA.

This method applies the currently set OF texture type and defaults to ARB rectangular textures if they are supported. (They are not supported on OpenGL ES).

Parameters
wDesired width in pixels.
hDesired height in pixels.
glInternalFormatOpenGL internal data format: GL_RGBA, GL_LUMINANCE, etc.

◆ allocate() [10/12]

void ofTexture::allocate ( int  w,
int  h,
int  glInternalFormat,
bool  bUseARBExtension 
)
virtual

Allocate texture of a given size and format. Specify texture type.

This allows to enable the ARBE extension for this texture. This will overide the default OF texture type, in case you need a square texture (GL_TEXTURE_2D).

Warning
ARB textures are not available in OpenGL ES.
See also
ofEnableArbTex()
allocate(int w, int h, int glInternalFormat)
Parameters
wDesired width in pixels.
hDesired height in pixels.
glInternalFormatThe internal openGL format.
bUseARBExtensionSet to true to use rectangular textures.

◆ allocate() [11/12]

void ofTexture::allocate ( int  w,
int  h,
int  glInternalFormat,
bool  bUseARBExtension,
int  glFormat,
int  pixelType 
)
virtual

Allocate texture of a given size, format, & type.

See also
allocate(int w, int h, int glInternalFormat)
Parameters
wDesired width in pixels.
hDesired height in pixels.
glInternalFormatOpenGL data format: GL_RGBA, GL_LUMINANCE, etc.
bUseARBExtensionSet to true to use rectangular textures.
glFormatThe OpenGL format.
pixelTypeOpenGL pixel type: GL_UNSIGNED_BYTE, GL_FLOAT, etc.

◆ allocate() [12/12]

void ofTexture::allocate ( int  w,
int  h,
int  glInternalFormat,
int  glFormat,
int  pixelType 
)
virtual

Allocate texture of a given size and format.

See also
allocate(int w, int h, int glInternalFormat)
Parameters
wDesired width in pixels.
hDesired height in pixels.
glInternalFormatThe internal openGL format.
glFormatThe openGL format.
pixelTypeGL pixel type: GL_UNSIGNED_BYTE, GL_FLOAT, etc.

◆ allocateAsBufferTexture()

void ofTexture::allocateAsBufferTexture ( const ofBufferObject buffer,
int  glInternalFormat 
)

Allocate texture as a Buffer Texture.

Uses a GPU buffer as data for the texture instead of pixels in RAM Allows to use texture buffer objects (TBO) which make it easier to send big amounts of data to a shader as a uniform.

Buffer textures are 1D textures, and may only be sampled using texelFetch in GLSL.

See textureBufferInstanceExample and https://www.opengl.org/wiki/Buffer_Texture

See also
allocate(const ofBufferObject & buffer, int glInternalFormat)
Parameters
bufferReference to ofBufferObject instance.
glInternalFormatInternal pixel format of the data.

◆ bind()

void ofTexture::bind ( int  textureLocation = 0) const

Bind the texture.

For advanced users who need to manually manage texture drawing without calling ofTexture::draw.

See also
http://www.opengl.org/sdk/docs/man4/html/glBindTexture.xhtml

◆ clear()

void ofTexture::clear ( )

Clears the texture.

Clears / frees the texture memory, if something was already allocated. Useful if you need to control the memory on the graphics card.

The internal GL texture ID is only released if this is the last texture using it.

◆ copyTo()

void ofTexture::copyTo ( ofBufferObject buffer) const

Copy the texture to an ofBufferObject.

Parameters
bufferthe target buffer to copy to.

◆ disableAlphaMask()

void ofTexture::disableAlphaMask ( )

Disable the alpha mask.

◆ disableMipmap()

void ofTexture::disableMipmap ( )

Sets flag disallowing texture to auto-generate mipmap.

By default, this will set your minFilter to GL_LINEAR_MIPMAP_LINEAR. If you want to change your minFilter later use setTextureMinMagFilter()

If you want to generate a mipmap later, or at a specific point in your code, use ofTexture::generateMipmap() instead.

See also
generateMipmap()
enableMipmap()
setTextureMinMagFilter()

◆ disableTextureMatrix()

void ofTexture::disableTextureMatrix ( )

Disable the texture matrix.

Disable the texture matrix.

◆ disableTextureTarget()

void ofTexture::disableTextureTarget ( int  textureLocation) const
protected

Disable a texture target.

Parameters
textureLocationthe OpenGL texture ID to enable as a target.

◆ draw() [1/12]

void ofBaseDraws::draw ( const glm::vec2 &  point) const
virtual

Draw at a position at the native size.

Native size is determined by getWidth() and getHeight().

Parameters
pointDraw position.

Reimplemented from ofBaseDraws.

◆ draw() [2/12]

void ofBaseDraws::draw ( const glm::vec2 &  point,
float  w,
float  h 
) const
virtual

Draw at a position.

Parameters
pointDraw position.
wDraw width.
hDraw height.

Reimplemented from ofBaseDraws.

◆ draw() [3/12]

void ofTexture::draw ( const glm::vec3 &  p1,
const glm::vec3 &  p2,
const glm::vec3 &  p3,
const glm::vec3 &  p4 
) const

Draws the texture at 4 points passed in as if you created 4 glVertices.

Parameters
p1Upper left position on the x axis.
p2Upper left position on the y axis.
p3Lower right position on the x axis.
p4Lower right position on the y axis.

ps: maybe if bUsingArbTex is enabled we should use glActiveTextureARB?

◆ draw() [4/12]

void ofTexture::draw ( const glm::vec3 &  pos) const

◆ draw() [5/12]

void ofTexture::draw ( const glm::vec3 &  pos,
float  w,
float  h 
) const

◆ draw() [6/12]

void ofBaseDraws::draw ( const ofRectangle rect) const
virtual

Draw at a position and size specified by a rectangle.

Parameters
rectDraw position and size.

Reimplemented from ofBaseDraws.

◆ draw() [7/12]

virtual void ofBaseDraws::draw ( float  x,
float  y 
) const
inlinevirtual

Draw at a position at the native size.

Native size is determined by getWidth() and getHeight().

Parameters
xDraw position on the x axis.
yDraw position on the y axis.

Reimplemented from ofBaseDraws.

◆ draw() [8/12]

void ofTexture::draw ( float  x,
float  y 
) const
virtual

Drawing

Reimplemented from ofBaseDraws.

◆ draw() [9/12]

void ofTexture::draw ( float  x,
float  y,
float  w,
float  h 
) const
virtual

Draw at a position with the specified size.

Parameters
xDraw position on the x axis.
yDraw position on the y axis.
wDraw width.
hDraw height.

Implements ofBaseDraws.

◆ draw() [10/12]

virtual void ofBaseDraws::draw ( float  x,
float  y,
float  w,
float  h 
) const
virtual

Draw at a position with the specified size.

Parameters
xDraw position on the x axis.
yDraw position on the y axis.
wDraw width.
hDraw height.

Implements ofBaseDraws.

◆ draw() [11/12]

void ofTexture::draw ( float  x,
float  y,
float  z 
) const

◆ draw() [12/12]

void ofTexture::draw ( float  x,
float  y,
float  z,
float  w,
float  h 
) const

Draw the texture at a given size witdh and depth.

Parameters
xDraw position on the x axis.
yDraw position on the y axis.
zDraw position on the z axis.
wDraw width.
hDraw height.

◆ drawSubsection() [1/5]

void ofTexture::drawSubsection ( const ofRectangle drawBounds,
const ofRectangle subsectionBounds 
) const

Draw a subsection of the texture with an offset.

See also
drawSubsection(ofRectangle& drawBounds, ofRectangle& subsectionBounds)
Parameters
drawBoundsDraw position and dimensions.
subsectionBoundsSubsection position and dimensions within the texture.

◆ drawSubsection() [2/5]

void ofTexture::drawSubsection ( float  x,
float  y,
float  w,
float  h,
float  sx,
float  sy 
) const

Draw a subsection of the texture.

Like ofRect() depend on the current OF_RECT_MODE:

  • OF_RECT_MODE_CORNER: drawn with the upper left corner = (x,y)
  • OF_RECT_MODE_CENTER: drawn centered on (x,y)
See also
ofSetRectMode()
Parameters
xDraw position on the x axis.
yDraw position on the y axis.
wDraw width.
hDraw height.
sxSubsection x axis offset within the texture.
sySubsection y axis offset within the texture.

◆ drawSubsection() [3/5]

void ofTexture::drawSubsection ( float  x,
float  y,
float  w,
float  h,
float  sx,
float  sy,
float  sw,
float  sh 
) const

Draw a subsection of the texture with an offset.

See also
drawSubsection(float x, float y, float w, float h, float sx, float sy)
Parameters
xDraw position on the x axis.
yDraw position on the y axis.
wDraw width.
hDraw height.
sxSubsection x axis offset within the texture.
sySubsection y axis offset within the texture.
swSubsection width within the texture.
shSubsection height within the texture.

◆ drawSubsection() [4/5]

void ofTexture::drawSubsection ( float  x,
float  y,
float  z,
float  w,
float  h,
float  sx,
float  sy 
) const

Draw a subsection of the texture with depth.

See also
drawSubsection(float x, float y, float w, float h, float sx, float sy)
Parameters
xDraw position on the x axis.
yDraw position on the y axis.
zDraw position on the z axis.
wDraw width.
hDraw height.
sxSubsection x axis offset within the texture.
sySubsection y axis offset within the texture.

◆ drawSubsection() [5/5]

void ofTexture::drawSubsection ( float  x,
float  y,
float  z,
float  w,
float  h,
float  sx,
float  sy,
float  sw,
float  sh 
) const

Draw a subsection of the texture with an offset and depth.

See also
drawSubsection(float x, float y, float w, float h, float sx, float sy)
Parameters
xDraw position on the x axis.
yDraw position on the y axis.
zDraw position on the z axis.
wDraw width.
hDraw height.
sxSubsection x axis offset within the texture.
sySubsection y axis offset within the texture.
swSubsection width within the texture.
shSubsection height within the texture.

◆ enableMipmap()

void ofTexture::enableMipmap ( )

Sets flag allowing texture to auto-generate a mipmap.

Mipmapping

By default, this will set your minFilter to GL_LINEAR_MIPMAP_LINEAR. If you want to change your minFilter later use setTextureMinMagFilter()

If you want to generate a mipmap later, or at a specific point in your code, use generateMipmap() instead.

See also
generateMipmap()
disableMipmap()
setTextureMinMagFilter()

◆ enableTextureTarget()

void ofTexture::enableTextureTarget ( int  textureLocation) const
protected

Enable a texture target.

Parameters
textureLocationthe OpenGL texture ID to enable as a target.

◆ generateMipmap()

void ofTexture::generateMipmap ( )

Generate mipmap for the current texture.

Warning
Only GL_TEXTURE_RECTANGLE - which is the default openFrameworks texture target - does not support mipmaps, so make sure to call ofDisableArbTex() before loading texture data for a texture you want to generate mipmaps for.
See also
ofEnableArbTex()
ofDisableArbTex()

OpenGL ES only supports mipmap for the following two texture targets:

OpenGL supports mipmaps for additional texture targets:

◆ getAlphaMask()

const ofTexture * ofTexture::getAlphaMask ( ) const

◆ getCoordFromPercent()

glm::vec2 ofTexture::getCoordFromPercent ( float  xPts,
float  yPts 
) const

Helper to convert display coordinate to texture coordinate.

Parameters
xPtsHorizontal position in a normalized percentage (0 - 1).
yPtsVertical position in a normalized percentage (0 - 1).
Returns
Texture coordinate or zero if texture is not allocated.

◆ getCoordFromPoint()

glm::vec2 ofTexture::getCoordFromPoint ( float  xPos,
float  yPos 
) const

Helper to convert display coordinate to texture coordinate.

Parameters
xPosHorizontal position in pixels.
yPosVertical position in pixels.
Returns
Texture coordinate or zero if texture is not allocated.

◆ getHeight()

float ofTexture::getHeight ( ) const
virtual

Display height of texture.

and Coordinates

Return value is pixel size (default) or normalized (0 - 1) if ofEnableNormalizedTextures() is set to true.

See also
ofEnabledNormalizedTextures()
Returns
Display height of texture in pixels.

Implements ofBaseDraws.

◆ getMeshForSubsection()

ofMesh ofTexture::getMeshForSubsection ( float  x,
float  y,
float  z,
float  w,
float  h,
float  sx,
float  sy,
float  sw,
float  sh,
bool  vflipped,
ofRectMode  rectMode 
) const

Get a mesh that has the texture coordinates set.

See also
drawSubsection(float x, float y, float w, float h, float sx, float sy)
Parameters
xDraw position on the x axis.
yDraw position on the y axis.
zDraw position on the z axis.
wDraw width.
hDraw height.
sxSubsection x axis offset within the texture.
sySubsection y axis offset within the texture.
swSubsection width within the texture.
shSubsection height within the texture.
vflippedTakes into account the flipped state in OF.
rectModerectMode Taking x,y as the center or the top left corner.

◆ getQuad()

ofMesh ofTexture::getQuad ( const glm::vec3 &  p1,
const glm::vec3 &  p2,
const glm::vec3 &  p3,
const glm::vec3 &  p4 
) const

◆ getTextureData() [1/2]

ofTextureData & ofTexture::getTextureData ( )

Internal texture data access.

Settings

This returns the internal texture data for this texture, for instance, its textureID, type of texture, whether it's been allocated and other data about the state of the texture.

Returns
a reference to the internal texture data struct.

◆ getTextureData() [2/2]

const ofTextureData & ofTexture::getTextureData ( ) const

Const version of getTextureData().

See also
ofTextureData::getTextureData()

◆ getTextureMatrix()

const glm::mat4 & ofTexture::getTextureMatrix ( ) const

◆ getWidth()

float ofTexture::getWidth ( ) const
virtual

Display width of texture.

Return value is pixel size (default) or normalized (0 - 1) if ofEnableNormalizedTextures() is set to true.

See also
ofEnabledNormalizedTextures()
Returns
Display width of texture in pixels.

Implements ofBaseDraws.

◆ hasMipmap()

bool ofTexture::hasMipmap ( ) const

Find out if a mipmap has been generated for the current texture.

See also
generateMipmap()
enableMipmap()

◆ isAllocated()

bool ofTexture::isAllocated ( ) const

Determine whether the texture has been allocated.

This lets you check if a texture is safe to draw. The texture can both be allocated by using allocate() or loading it with data loadData().

Returns
true if the texture has been allocated.

◆ isUsingTextureMatrix()

bool ofTexture::isUsingTextureMatrix ( ) const

◆ loadData() [1/15]

void ofTexture::loadData ( const float *  data,
int  w,
int  h,
int  glFormat 
)

Load float pixel data.

See also
loadData(const unsigned char* const data, int w, int h, int glFormat)
Parameters
dataPointer to byte pixel data. Must not be nullptr.
wPixel data width.
hPixel data height.
glFormatGL pixel type: GL_RGBA, GL_LUMINANCE, etc.

◆ loadData() [2/15]

void ofTexture::loadData ( const int16_t *  data,
int  w,
int  h,
int  glFormat 
)

◆ loadData() [3/15]

void ofTexture::loadData ( const int32_t *  data,
int  w,
int  h,
int  glFormat 
)

◆ loadData() [4/15]

void ofTexture::loadData ( const int8_t *  data,
int  w,
int  h,
int  glFormat 
)

◆ loadData() [5/15]

void ofTexture::loadData ( const ofBufferObject buffer,
int  glFormat,
int  glType 
)

Load pixels from an ofBufferObject.

This is different to allocate(ofBufferObject,internal). That creates a texture which data lives in GL buffer while this copies the data from the buffer to the texture.

This is usually used to upload data to be shown asynchronously by using a buffer object binded as a PBO

Parameters
bufferThe buffer to load.
glFormatGL pixel type: GL_RGBA, GL_LUMINANCE, etc.
glTypethe GL type to load.

◆ loadData() [6/15]

void ofTexture::loadData ( const ofFloatPixels pix)

Load pixels from an ofFloatPixels instance.

Same as loadData(ofPixels &) but for ofFloatPixels.

See also
loadData(const ofPixels & pix)
Parameters
pixReference to ofFloatPixels instance.

◆ loadData() [7/15]

void ofTexture::loadData ( const ofFloatPixels pix,
int  glFormat 
)

Load pixels from an ofFloatPixels instance and specify the format.

See also
loadData(const ofPixels & pix, int glFormat)
Parameters
pixReference to ofFloatPixels instance.
glFormatGL pixel type: GL_RGBA, GL_LUMINANCE, etc.

◆ loadData() [8/15]

void ofTexture::loadData ( const ofPixels pix)

Load pixels from an ofPixels instance.

Parameters
pixReference to ofPixels instance.

◆ loadData() [9/15]

void ofTexture::loadData ( const ofPixels pix,
int  glFormat 
)

Load pixels from an ofPixels instance and specify the format.

glFormat can be different to the internal format of the texture on each load, ie. we can upload GL_BGRA pixels into a GL_RGBA texture, but the number of channels need to match according to the OpenGL standard.

Parameters
pixReference to ofPixels instance.
glFormatGL pixel type: GL_RGBA, GL_LUMINANCE, etc.

◆ loadData() [10/15]

void ofTexture::loadData ( const ofShortPixels pix)

Load pixels from an ofShortPixels instance.

Same as loadData(ofPixels &) but for ofShortPixels.

See also
loadData(const ofPixels & pix)
Parameters
pixReference to ofShortPixels instance.

◆ loadData() [11/15]

void ofTexture::loadData ( const ofShortPixels pix,
int  glFormat 
)

Load pixels from an ofShortPixels instance & specify the format.

See also
loadData(const ofPixels & pix, int glFormat)
Parameters
pixReference to ofShortPixels instance.
glFormatGL pixel type: GL_RGBA, GL_LUMINANCE, etc.

◆ loadData() [12/15]

void ofTexture::loadData ( const uint16_t *  data,
int  w,
int  h,
int  glFormat 
)

Load short (2 byte) pixel data.

See also
loadData(const unsigned char* const data, int w, int h, int glFormat)
Parameters
dataPointer to byte pixel data. Must not be nullptr.
wPixel data width.
hPixel data height.
glFormatGL pixel type: GL_RGBA, GL_LUMINANCE, etc.

◆ loadData() [13/15]

void ofTexture::loadData ( const uint32_t *  data,
int  w,
int  h,
int  glFormat 
)

◆ loadData() [14/15]

void ofTexture::loadData ( const uint8_t *const  data,
int  w,
int  h,
int  glFormat 
)

Load byte pixel data.

glFormat can be different to the internal format of the texture on each load, i.e. we can upload GL_BGRA pixels into a GL_RGBA texture but the number of channels need to match according to the OpenGL standard.

Parameters
dataPointer to byte pixel data. Must not be nullptr.
wPixel data width.
hPixel data height.
glFormatGL pixel type: GL_RGBA, GL_LUMINANCE, etc.

◆ loadData() [15/15]

void ofTexture::loadData ( const void *  data,
int  w,
int  h,
int  glFormat,
int  glType 
)

Load byte pixel data.

glFormat can be different to the internal format of the texture on each load, i.e. we can upload GL_BGRA pixels into a GL_RGBA texture but the number of channels need to match according to the OpenGL standard.

Parameters
dataPointer to byte pixel data. Must not be nullptr.
wPixel data width.
hPixel data height.
glFormatGL pixel type: GL_RGBA, GL_LUMINANCE, etc.
glTypethe OpenGL type of the data.

◆ loadScreenData()

void ofTexture::loadScreenData ( int  x,
int  y,
int  w,
int  h 
)

Copy an area of the screen into this texture.

Specifiy the position (x,y) you wish to grab from, with the width (w) and height (h) of the region.

Make sure that you have allocated your texture (using allocate()) to be large enough to hold the region of the screen you wish to load.

See also
http://www.opengl.org/sdk/docs/man4/html/glCopyTexSubImage2D.xhtml
Parameters
xUpper left corner horizontal screen position.
yUpper left corner vertical screen position.
wWidth of the area to copy in pixels.
hHeight of the area to copy in pixels.

◆ OF_DEPRECATED_MSG()

ofTexture::OF_DEPRECATED_MSG ( "Use isAllocated instead"  ,
bool bAllocated() const   
)

Has the texture been allocated?

Legacy function for backwards compatibility.

Returns
true if the texture has been allocated.

◆ operator=() [1/2]

ofTexture & ofTexture::operator= ( const ofTexture mom)

Copy a given ofTexture into this texture.

ofCubeMap

Parameters
momThe ofTexture to copy from. Reuses internal GL texture ID.

◆ operator=() [2/2]

ofTexture & ofTexture::operator= ( ofTexture &&  mom)

◆ readToPixels() [1/3]

void ofTexture::readToPixels ( ofFloatPixels pixels) const

Read current texture data from the GPU into pixels.

Warning
This is not supported in OpenGL ES and does nothing.
Parameters
pixelsTarget pixels reference.

◆ readToPixels() [2/3]

void ofTexture::readToPixels ( ofPixels pixels) const

Read current texture data from the GPU into pixels.

Pixel Data

Warning
This is not supported in OpenGL ES and does nothing.
Parameters
pixelsTarget ofPixels reference.

◆ readToPixels() [3/3]

void ofTexture::readToPixels ( ofShortPixels pixels) const

Read current texture data from the GPU into pixels.

Warning
This is not supported in OpenGL ES and does nothing.
Parameters
pixelsTarget pixels reference.

◆ resetAnchor()

void ofTexture::resetAnchor ( )
virtual

Reset the anchor point to (0, 0).

Reimplemented from ofBaseDraws.

◆ setAlphaMask()

void ofTexture::setAlphaMask ( ofTexture mask)

Set another ofTexture to use as an alpha mask.

Settings

Parameters
maskThe texture to use as alpha mask.

◆ setAnchorPercent()

void ofTexture::setAnchorPercent ( float  xPct,
float  yPct 
)
virtual

Set the anchor point the texture is drawn around as a percentage.

This can be useful if you want to rotate an image around a particular point.

Parameters
xPctHorizontal texture position as a percentage (0 - 1).
yPctVertical texture position as a percentage (0 - 1).

Reimplemented from ofBaseDraws.

◆ setAnchorPoint()

void ofTexture::setAnchorPoint ( float  x,
float  y 
)
virtual

Set the anchor point the texture is drawn around in pixels.

This can be useful if you want to rotate an image around a particular point.

Parameters
xHorizontal texture position in pixels.
yVertical texture position in pixels.

Reimplemented from ofBaseDraws.

◆ setCompression()

void ofTexture::setCompression ( ofTexCompression  compression)

Set the texture compression.

Warning
: not yet implemented.
See also
ofTexCompression

◆ setRGToRGBASwizzles()

void ofTexture::setRGToRGBASwizzles ( bool  rToRGBSwizzles)

Swizzle RGBA to grayscale with alpha in the red channel.

Todo:
Define Swizzle in the documentation.

Use 1 channel GL_R as luminance instead of red channel in OpenGL 3+.

Warning
This is not supported in OpenGL ES and does nothing.
See also
https://en.wikipedia.org/wiki/Swizzling_(computer_graphics)

◆ setSwizzle()

void ofTexture::setSwizzle ( GLenum  srcSwizzle,
GLenum  dstChannel 
)

Swizzle a channel to another.

Example:

tex.setSwizzle(GL_TEXTURE_SWIZZLE_R,GL_ALPHA);
A wrapper class for an OpenGL texture.
Definition ofTexture.h:253
void setSwizzle(GLenum srcSwizzle, GLenum dstChannel)
Swizzle a channel to another.
Definition ofTexture.cpp:536

will make channel 0 appear as alpha in the shader.

Warning
This is not supported in OpenGL ES and does nothing.
See also
https://en.wikipedia.org/wiki/Swizzling_(computer_graphics)

◆ setTextureMatrix()

void ofTexture::setTextureMatrix ( const glm::mat4 &  m)

Sets a texture matrix to be uploaded whenever the texture is bound.

Parameters
mThe 4x4 texture matrix.

Sets a texture matrix that will be uploaded whenever the texture is binded.

◆ setTextureMinMagFilter()

void ofTexture::setTextureMinMagFilter ( GLint  minFilter,
GLint  magFilter 
)

Set texture minification/magnification scaling filters.

Controls how OpenGL will scale this texture.

See also
http://www.opengl.org/sdk/docs/man4/html/glTexParameter.xhtml
ofTextureSetMinMagFilters()
Warning
May be overridden.
Parameters
minFilterminifying filter for scaling a pixel to a smaller area.
magFiltermagnifying filter for scaling a pixel to a larger area.

◆ setTextureWrap()

void ofTexture::setTextureWrap ( GLint  wrapModeHorizontal,
GLint  wrapModeVertical 
)

Set texture wrapping.

By default, textures are clamped to their edges with GL_CLAMP_TO_EDGE. Setting a repeat mode like GL_REPEAT allows you to create tiled backgrounds with small textures.

See also
ofTextureSetWrap()
http://www.opengl.org/sdk/docs/man4/html/glTexParameter.xhtml
Warning
May be overridden.
Parameters
wrapModeHorizontalwrap parameter for texture coordinate s.
wrapModeVerticalwrap parameter for texture coordinate t.

◆ setUseExternalTextureID()

void ofTexture::setUseExternalTextureID ( GLuint  externTexID)

Set the texture ID.

Allows you to point the texture id to an externally allocated id (perhaps from another texture). It's up to you to set the rest of the textData parameters manually.

Warning
When setting an external texture ID, the user must set the remaining ofTextureData parameters manually.
Parameters
externTexIDNew texture ID.

◆ unbind()

void ofTexture::unbind ( int  textureLocation = 0) const

Unbind the texture.

For advanced users who need to manually manage texture drawing without calling ofTexture::draw.

See also
http://www.opengl.org/sdk/docs/man4/html/glBindTexture.xhtml

Member Data Documentation

◆ anchor

glm::vec3 ofTexture::anchor
protected

The texture's anchor point.

◆ bAnchorIsPct

bool ofTexture::bAnchorIsPct
protected

Is the anchor point represented as a normalized (0 - 1) coordinate?

◆ texData

ofTextureData ofTexture::texData

Internal texture data access. For backwards compatibility.


The documentation for this class was generated from the following files:
  • /Users/icq4ever/Desktop/oF0120/libs/openFrameworks/gl/ofTexture.h
  • /Users/icq4ever/Desktop/oF0120/libs/openFrameworks/gl/ofTexture.cpp