MinGfx Toolkit
1.0
A minimal library for writing cross-platform (Windows, OSX, linux) graphics programs.
|
A wrapper around a 2D texture that supports loading images from files or setting texture color data directly.
Example:
Definition at line 42 of file texture2d.h.
#include <texture2d.h>
Public Member Functions | |
Texture2D (GLenum wrapMode=GL_REPEAT, GLenum filterMode=GL_LINEAR) | |
Creates an empty texture. Optional parameters can be provided to set the texture wrap mode and filter mode. More... | |
virtual | ~Texture2D () |
bool | InitFromFile (const std::string &filename) |
Call this from within the InitOpenGL() function since it will initialize not just the Texture2D's internal data but also an OpenGL texture to be stored on the graphics card. Internally, this uses the stbi library to load images. It supports png, jpg, bmp, and other file formats. More... | |
bool | InitFromBytes (int width, int height, const unsigned char *data) |
Call this from within the InitOpenGL() function since it will initialize not just the Texture2D's internal data but also an OpenGL texture to be stored on the graphics card. With this version of Init, you may pass in your own pointer to color data. The data argument must point to an array of 4-channel color data stored as unsigned chars in RGBA format. You are responsible for managing the memory for this array. If you will never call Pixel(), then it is safe to free data as soon as this function returns. Otherwise, you need to make sure data does not change in memory until you destroy the Texture2D object. More... | |
bool | InitFromFloats (int width, int height, const float *data) |
Call this from within the InitOpenGL() function since it will initialize not just the Texture2D's internal data but also an OpenGL texture to be stored on the graphics card. With this version of Init, you may pass in your own pointer to color data. The data argument must point to an array of 4-channel color data stored as floats in RGBA format. You are responsible for managing the memory for this array. If you will never call Pixel(), then it is safe to free data as soon as this function returns. Otherwise, you need to make sure data does not change in memory until you destroy the Texture2D object. More... | |
bool | UpdateFromBytes (const unsigned char *data) |
This function may be called to re-read the texture data from an array formated the same as in InitFromBytes. The width and height of the texture must remain the same. More... | |
bool | UpdateFromFloats (const float *data) |
This function may be called to re-read the texture data from an array formated the same as in InitFromFloats. The width and height of the texture must remain the same. More... | |
bool | initialized () const |
Returns true if the texture data has been successfully transferred to OpenGL. More... | |
int | width () const |
Returns the width in pixels of the texture. More... | |
int | height () const |
Returns the height in pixels of the texture. More... | |
GLuint | opengl_id () const |
Returns the unsigned int used as the texture handle by OpenGL. More... | |
GLenum | wrap_mode () const |
Returns an enumerated constant for the OpenGL wrap mode used by the texture. More... | |
GLenum | filter_mode () const |
Returns an enumerated constant for the OpenGL filter mode used by the texture. More... | |
void | set_wrap_mode (GLenum wrapMode) |
Uses the OpenGL texture wrap mode arguments. More... | |
void | set_filter_mode (GLenum filterMode) |
Uses the OpenGL texture filter mode arguments. More... | |
Color | Pixel (int x, int y) const |
Returns the color at the specified pixel. The top left corner of the image is (0,0) and the bottom right is (width()-1, height()-1). More... | |
mingfx::Texture2D::Texture2D | ( | GLenum | wrapMode = GL_REPEAT , |
GLenum | filterMode = GL_LINEAR |
||
) |
Creates an empty texture. Optional parameters can be provided to set the texture wrap mode and filter mode.
|
virtual |
GLenum mingfx::Texture2D::filter_mode | ( | ) | const |
Returns an enumerated constant for the OpenGL filter mode used by the texture.
int mingfx::Texture2D::height | ( | ) | const |
Returns the height in pixels of the texture.
bool mingfx::Texture2D::InitFromBytes | ( | int | width, |
int | height, | ||
const unsigned char * | data | ||
) |
Call this from within the InitOpenGL() function since it will initialize not just the Texture2D's internal data but also an OpenGL texture to be stored on the graphics card. With this version of Init, you may pass in your own pointer to color data. The data argument must point to an array of 4-channel color data stored as unsigned chars in RGBA format. You are responsible for managing the memory for this array. If you will never call Pixel(), then it is safe to free data as soon as this function returns. Otherwise, you need to make sure data does not change in memory until you destroy the Texture2D object.
bool mingfx::Texture2D::InitFromFile | ( | const std::string & | filename | ) |
Call this from within the InitOpenGL() function since it will initialize not just the Texture2D's internal data but also an OpenGL texture to be stored on the graphics card. Internally, this uses the stbi library to load images. It supports png, jpg, bmp, and other file formats.
bool mingfx::Texture2D::InitFromFloats | ( | int | width, |
int | height, | ||
const float * | data | ||
) |
Call this from within the InitOpenGL() function since it will initialize not just the Texture2D's internal data but also an OpenGL texture to be stored on the graphics card. With this version of Init, you may pass in your own pointer to color data. The data argument must point to an array of 4-channel color data stored as floats in RGBA format. You are responsible for managing the memory for this array. If you will never call Pixel(), then it is safe to free data as soon as this function returns. Otherwise, you need to make sure data does not change in memory until you destroy the Texture2D object.
bool mingfx::Texture2D::initialized | ( | ) | const |
Returns true if the texture data has been successfully transferred to OpenGL.
GLuint mingfx::Texture2D::opengl_id | ( | ) | const |
Returns the unsigned int used as the texture handle by OpenGL.
Color mingfx::Texture2D::Pixel | ( | int | x, |
int | y | ||
) | const |
void mingfx::Texture2D::set_filter_mode | ( | GLenum | filterMode | ) |
Uses the OpenGL texture filter mode arguments.
void mingfx::Texture2D::set_wrap_mode | ( | GLenum | wrapMode | ) |
Uses the OpenGL texture wrap mode arguments.
bool mingfx::Texture2D::UpdateFromBytes | ( | const unsigned char * | data | ) |
This function may be called to re-read the texture data from an array formated the same as in InitFromBytes. The width and height of the texture must remain the same.
bool mingfx::Texture2D::UpdateFromFloats | ( | const float * | data | ) |
This function may be called to re-read the texture data from an array formated the same as in InitFromFloats. The width and height of the texture must remain the same.
int mingfx::Texture2D::width | ( | ) | const |
Returns the width in pixels of the texture.
GLenum mingfx::Texture2D::wrap_mode | ( | ) | const |
Returns an enumerated constant for the OpenGL wrap mode used by the texture.