#include <dms/Texture2D.h> Texture2D(Image& image, GLint wrap=GL_REPEAT, GLint min=GL_LINEAR, GLint mag=GL_LINEAR); Texture2D(char *filename=NULL, GLint wrap=GL_REPEAT, GLint min=GL_LINEAR, GLint mag=GL_LINEAR); virtual ~Texture2D(void); virtual void apply(void); virtual void disable(void); void define(void); void subload(GLint xoffset=0,GLint yoffset=0); void setImage(Image&); Image& image(void) const;
Texture2D(Image& image, GLint wrap, GLint min, GLint mag); Texture2D(char *filename, GLint wrap, GLint min, GLint mag);
By default, the constructor assigns no image to the texture; one will
have to be assigned with setImage() before the texture can be
used.
If an Image object is passed to the constructor,
it will be used
for the texture image data; only a pointer to the Image object
is saved, so the object should not be deleted as long as the Texture
is being used.
If a filename is passed to the constructor, then a
FileImage object will be created to load the
image data.
The wrap, min, and mag options are passed
on to the Texture constructor.
Example:
Texture2D tex("brick.jpg", GL_REPEAT, GL_LINEAR_MIPMAP_LINEAR);
void apply(void)
Enables 2D texturing, and binds the texture object (via glBindTexture()).
If define() has not been called yet, the first apply() will
call it automatically.
Example:
tex.apply();
void disable(void)
Disables 2D texturing, and unbinds the texture object.
Example:
tex.apply(); glutSolidTeapot(1.0); tex.disable();
void define(void)
Creates an OpenGL texture using the Texture object's image data.
define()'s primary activity is to call glTexImage2D() and
glTexParameter() with the data and options for the Texture.
If the image data's width or height is not a power of two, the image will
be automatically rescaled down to the nearest power of two size using
gluScaleImage().
If the minification filter uses mipmapping, gluBuild2DMipmaps() will be
called in place of glTexImage2D().
The texture is created with the GL_RGBA internal format.
Example:
Texture2D tex("brick.jpg"); tex.define();
void subload(GLint xoffset,GLint yoffset)
Sub-loads new image data into the texture.
This can be called after changing the texture's image object (using
setImage()), or changing the contents of the current image's data.
It will use glTexSubImage2D() to sub-load the new data into
the texture; the new image's size should be no larger than that of the original
image that was used by define().
This function can only be called after define() has been called
to load the base image data.
The optional xoffset and yoffset values specify the
offset within the base texture image to subload at - i.e. they are the
lower-left corner of the region in the base image where the new data
will be subloaded. The default offsets are (0,0).
This function does not support subloading into mipmapped textures.
Example:
Texture2D tex("brick.jpg"); tex.define(); FileImage subimage("subbrick.jpg"); tex.setImage(subimage); tex.subload();
void setImage(Image&) Image& image(void)
Sets / returns the image object to be used by the texture.
setImage() must be called before define(), for
it to have an effect.
Example:
Texture2D tex; JPEGImage picture("sky.jpg"); tex.setImage(picture);