GCGlib  0.04.228
GCG Graphics Engine
gcgTEXTURE2D Class Reference

Class to transparently deal with 3D textures. Allocates the texture directly from graphics system and provides functions for binding, unbinding and updating the texture. More...

#include <gcg.h>

Inheritance diagram for gcgTEXTURE2D:
gcgCLASS

Public Member Functions

 gcgTEXTURE2D ()
 Constructs a valid gcgTEXTURE instance but no actual texture is created. More...
 
virtual ~gcgTEXTURE2D ()
 Frees all texture resources by calling destroyTexture(). More...
 
bool destroyTexture ()
 Frees all texture resources. Invocations to the object methods become innocuous. A call to createTexture() or uploadImage() turns the texture usable again. More...
 
bool createTexture (unsigned int width, unsigned int height, unsigned char bpp, bool usealpha, bool mipmapped=false)
 Creates a new texture filled with black pixels (zeros). It releases all resources of the previous texture. The actual texture allocated in the graphics systems has power of 2. Thus, if width or height are not powers of 2, they are adjusted to the smallest power of 2 greater than them. The bits per pixel bpp may be 4, 8, 16, 24 or 32 bits, and the internal graphics system attributes are selected accordingly, also depending on the usealpha parameter. More...
 
bool uploadImage (gcgIMAGE *srcimage, int destposX=0, int destposY=0, unsigned int level=0, bool mipmapped=false)
 Loads the contents of an image into an existing texture. If the current texture is not compatible with srcimage, it returns false. If the texture was not allocated yet, it creates a new texture compatible with srcimage and with its contents. The actual texture allocated in the graphics systems has power of 2. Thus, it uses the smallest power of 2 greater than the width and height of srcimage. The srcimage's bits per pixel, or bpp, may be 4, 8, 16, 24 or 32 bits, and the internal graphics system attributes are selected accordingly, depending if srcimage has an alpha channel. If bpp is 4 or 8, then the texture indicates luminance (pixel brightness) given by srcimage's palette colors. If bpp is 16 (with no alpha channel), 5 bits are allocated for red and blue channels, and 6 bits for the green channel. If bpp is 32 (with no alpha channel), 8 bits are allocated for red, green and blue channels and the remaining 8 bits are ignored. If an alpha channel is present in srcimage, some of the bits of the texture are reserved for it. This works ONLY for 16 and 32 bits. If bpp = 16, there are 2 possible mappings (depending on srcimage) for red, green, blue and alpha respectively: (4, 4, 4, 4) or (5, 5, 5, 1). If bpp is 32, 8 bits are allocated for each of the four channels. If bpp is 24, no alpha channel is possible. More...
 
bool isCompatibleWith (gcgIMAGE *srcimage)
 Checks if the current texture is compatible with the srcimage. They are compatible if the internal parameters of the graphics system needed to store the image and the texture are the same. It depends on the image's bits per pixel and if it has an alpha channel. Checking the compatibility is useful for copying the image's content into the texture by using uploadImage(). More...
 
bool bind ()
 Binds a texture in the graphics system. Subsequent references to a texture will be addressed to the current texture. A later call to unbind() is mandatory to keep the system stable. More...
 
bool unbind ()
 Unbinds a texture from the graphics system. It is called after a call to bind(). If this is not the case, the result is unpredictable. More...
 
- Public Member Functions inherited from gcgCLASS
void * operator new (size_t size)
 Defines a new operator to be used by instatiations of GCGlib classes instead the global one. More...
 
void * operator new (size_t size, const std::nothrow_t &) throw ()
 Defines a new operator to be used by instantiations of GCGlib classes instead the global one. Returns a NULL pointer instead of throwing an exception if an error occurs. More...
 
void * operator new[] (size_t size)
 Defines a new operator to be used by GCGlib array allocations instead the global one. More...
 
void * operator new[] (size_t size, const std::nothrow_t &) throw ()
 Defines a new operator to be used by vector allocations instead the global one. More...
 
void operator delete (void *p)
 Defines a delete operator to free instances of GCGlib classes instead the global one. It is designed to match the new operator. More...
 
void operator delete (void *p, const std::nothrow_t &) throw ()
 Defines a delete operator to free instances of GCGlib classes instead the global one. It is designed to match the new operator. More...
 
void operator delete[] (void *p)
 Defines a delete operator to free instances of arrays for GCGlib classes instead the global one. It is designed to match the new[] operator. More...
 
void operator delete[] (void *p, const std::nothrow_t &) throw ()
 Defines a delete operator to free instances of arrays for GCGlib classes instead the global one. It is designed to match the new[] operator. More...
 

Public Attributes

unsigned int width
 Width effectively used by the texture. It must be <= actualwidth.
 
unsigned int height
 Height effectively used by the texture. It must be <= actualheight.
 
unsigned int actualwidth
 Real width of the texture inside the graphics system: must be a power of 2.
 
unsigned int actualheight
 Real Height of the texture inside the graphics system: must be a power of 2.
 
unsigned int idOpengl
 OpenGL texture internal identification.
 
int internalformat
 OpenGL internal format: GL_LUMINANCE4, GL_LUMINANCE8, GL_RGB5, GL_RGB5_A1, GL_RGBA8, GL_RGB8 or GL_RGB4, depending on the texture creation parameters.
 
int format
 OpenGL format: GL_LUMINANCE, GL_BGRA, GL_RGB or GL_RGBA, depending on the texture creation parameters.
 
int type
 OpenGL format: GL_UNSIGNED_BYTE, GL_BITMAP, GL_UNSIGNED_BYTE_4, GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_UNSIGNED_SHORT_5_6_5, or GL_UNSIGNED_SHORT_4_4_4_4_REV, depending on the texture creation parameters.
 

Detailed Description

Class to transparently deal with 3D textures. Allocates the texture directly from graphics system and provides functions for binding, unbinding and updating the texture.

Since
0.01.6

Constructor & Destructor Documentation

◆ gcgTEXTURE2D()

gcgTEXTURE2D::gcgTEXTURE2D ( )

Constructs a valid gcgTEXTURE instance but no actual texture is created.

See also
~gcgTEXTURE2D()
Since
0.01.6

◆ ~gcgTEXTURE2D()

virtual gcgTEXTURE2D::~gcgTEXTURE2D ( )
virtual

Frees all texture resources by calling destroyTexture().

See also
gcgTEXTURE2D()
Since
0.01.6

Member Function Documentation

◆ bind()

bool gcgTEXTURE2D::bind ( )

Binds a texture in the graphics system. Subsequent references to a texture will be addressed to the current texture. A later call to unbind() is mandatory to keep the system stable.

Returns
true if the image was bound and available for texture mappings.
Remarks
Modifies several graphics library features: texture enabling and current matrix mode.
See also
unbind()
createTexture()
uploadImage()
Since
0.01.6

◆ createTexture()

bool gcgTEXTURE2D::createTexture ( unsigned int  width,
unsigned int  height,
unsigned char  bpp,
bool  usealpha,
bool  mipmapped = false 
)

Creates a new texture filled with black pixels (zeros). It releases all resources of the previous texture. The actual texture allocated in the graphics systems has power of 2. Thus, if width or height are not powers of 2, they are adjusted to the smallest power of 2 greater than them. The bits per pixel bpp may be 4, 8, 16, 24 or 32 bits, and the internal graphics system attributes are selected accordingly, also depending on the usealpha parameter.

Parameters
[in]widthThe expected width of the texture. If it is not a power of 2, the actual texture's width allocated in the graphics system is the smallest power of two greater than width.
[in]heightThe expected height of the texture. If it is not a power of 2, the actual texture's height allocated in the graphics system is the smallest power of two greater than height.
[in]bppThe bits per pixel of the texture. The internal parameters are chosen accordingly, in conjunction with usealpha. If bpp is 4 or 8, then the texture indicates luminance or pixel brightness. If bpp is 16 (and usealpha is false), 5 bits are allocated for red and blue channels, and 6 bits for the green channel. If bpp is 32 (and usealpha is false), 8 bits are allocated for red, green and blue channels and the remaining 8 bits are ignored. See usealpha to see the bitmap for 16 and 32 bits when alpha channel is needed.
[in]usealphaIf true, some of the bits per pixel are reserved for an alpha channel. This works ONLY for 16 and 32 bits. If bpp = 16 and usealpha is true, 4 four bits are allocated for red, green, blue and alpha. If bpp is 32, 8 bits are allocated for each of the four channels. See bpp to see the bitmap when usealpha is false. If bpp is 24, usealpha is ignored.
[in]mipmappedIf true, a pyramid of textures are generated for each level of a mipmap.
Returns
true if the texture is successfully created.
See also
uploadImage()
isCompatibleWith()
gcgIMAGE::createImage()
Since
0.01.6

◆ destroyTexture()

bool gcgTEXTURE2D::destroyTexture ( )

Frees all texture resources. Invocations to the object methods become innocuous. A call to createTexture() or uploadImage() turns the texture usable again.

Returns
true if the texture is completely released, including from graphics system.

◆ isCompatibleWith()

bool gcgTEXTURE2D::isCompatibleWith ( gcgIMAGE srcimage)

Checks if the current texture is compatible with the srcimage. They are compatible if the internal parameters of the graphics system needed to store the image and the texture are the same. It depends on the image's bits per pixel and if it has an alpha channel. Checking the compatibility is useful for copying the image's content into the texture by using uploadImage().

Parameters
[in]srcimageA valid gcgIMAGE object.
Returns
true if the image is compatible with the current texture.
See also
createTexture()
uploadImage()
Since
0.01.6

◆ unbind()

bool gcgTEXTURE2D::unbind ( )

Unbinds a texture from the graphics system. It is called after a call to bind(). If this is not the case, the result is unpredictable.

Returns
true if the image was correctly unbound.
Remarks
Modifies several graphics library features: texture enabling and current matrix mode
See also
bind()
Since
0.01.6

◆ uploadImage()

bool gcgTEXTURE2D::uploadImage ( gcgIMAGE srcimage,
int  destposX = 0,
int  destposY = 0,
unsigned int  level = 0,
bool  mipmapped = false 
)

Loads the contents of an image into an existing texture. If the current texture is not compatible with srcimage, it returns false. If the texture was not allocated yet, it creates a new texture compatible with srcimage and with its contents. The actual texture allocated in the graphics systems has power of 2. Thus, it uses the smallest power of 2 greater than the width and height of srcimage. The srcimage's bits per pixel, or bpp, may be 4, 8, 16, 24 or 32 bits, and the internal graphics system attributes are selected accordingly, depending if srcimage has an alpha channel. If bpp is 4 or 8, then the texture indicates luminance (pixel brightness) given by srcimage's palette colors. If bpp is 16 (with no alpha channel), 5 bits are allocated for red and blue channels, and 6 bits for the green channel. If bpp is 32 (with no alpha channel), 8 bits are allocated for red, green and blue channels and the remaining 8 bits are ignored. If an alpha channel is present in srcimage, some of the bits of the texture are reserved for it. This works ONLY for 16 and 32 bits. If bpp = 16, there are 2 possible mappings (depending on srcimage) for red, green, blue and alpha respectively: (4, 4, 4, 4) or (5, 5, 5, 1). If bpp is 32, 8 bits are allocated for each of the four channels. If bpp is 24, no alpha channel is possible.

Parameters
[in]srcimageA valid gcgIMAGE object whose pixel contents are to be copied into the texture.
[in]destposXColumn coordinate of the texture to where srcimage's column 0 has to be copied.
[in]destposYRow coordinate of the texture to where srcimage's row 0 has to be copied.
[in]levelIndicates the mipmap level of the current texture to where srcimage must be copied, if the current texture is mipmapped.
[in]mipmappedIf true, a pyramid of images are generated from srcimage and stored in each level of a mipmap.
Returns
true if the image's content is copied into the graphics system's texture, or a new texture was created.
See also
createTexture()
isCompatibleWith()
Since
0.01.6

The documentation for this class was generated from the following file: