CUGL
2.0
|
#include <cugl.h>
Public Member Functions | |
PixelMap () | |
PixelMap (const char *bmpFileName) | |
PixelMap (GLint x, GLint y, GLsizei w, GLsizei h) | |
~PixelMap () | |
void | read (const char *bmpFileName) |
void | read (GLint x, GLint y, GLsizei w, GLsizei h, GLenum mode=GL_FRONT) |
void | write (const char *bmpFileName) |
bool | badSize () |
void | rescale () |
void | draw () |
void | setTexture (GLuint name) |
void | setMipmaps (GLuint name) |
void | select (const PixelMap &src, int xp, int yp, int width, int height) |
unsigned long | getRows () const |
unsigned long | getColumns () const |
unsigned long | getSize () const |
char * | getName () const |
bool | ready () const |
Private Member Functions | |
PixelMap (const PixelMap &pm) | |
bool | allocate (unsigned long newSize) |
Private Attributes | |
unsigned long | numRows |
unsigned long | numCols |
unsigned long | size |
char * | fileName |
unsigned char * | pixels |
Friends | |
bool | compatible (const PixelMap &m1, const PixelMap &m2) |
void | mix (const PixelMap &m1, const PixelMap &m2, PixelMap &res, double prop) |
std::ostream & | operator<< (std::ostream &os, const PixelMap &pm) |
An instance is an RGB pixel array. An instance of PixelMap holds an array that OpenGL can use as a texture or to display directly.
This class is implemented so that it does not depend on Windows. In principle, it should even work with Linux and other operating systems, although this has not been tested thoroughly.
If you want to use a BMP image as a texture, the width and height must be powers of two. Thus a 256 x 512 BMP image is acceptable but a 640 x 400 image is not. This restriction does not apply to images that are displayed as bitmaps.
Since an instance of PixelMap
contains pointers, there are memory management issues. The destructor deletes pixel and other data associated with a pixel map. The copy constructor is declared privately and not implemented: this prevents instances being passed by value, although they may be passed by reference. Since there is a default constructor, you can construct arrays of PixelMap's or pointers to PixelMap.
cugl::PixelMap::PixelMap | ( | ) |
Construct an empty pixel map.
cugl::PixelMap::PixelMap | ( | const char * | bmpFileName | ) |
Read a pixel map from a file.
bmpFileName | is a path to a BMP file. |
cugl::PixelMap::PixelMap | ( | GLint | x, |
GLint | y, | ||
GLsizei | w, | ||
GLsizei | h | ||
) |
Construct a pixel map from a region of the pixel buffer.
x | is the X coordinate of the lower left corner of the region. |
y | is the Y coordinate of the lower left corner of the region. |
w | is the width of the region in pixels. |
h | is the height of the region in pixels. |
cugl::PixelMap::~PixelMap | ( | ) |
Delete a pixel map.
|
private |
The copy constructor is private and unimplemented. This prevents pixel maps from being copied by mistake.
|
private |
Allocate memory for a new pixel map if necessary.
bool cugl::PixelMap::badSize | ( | ) |
Check the dimensions of the bit map. If the dimensions are not powers of 2, return true
. If the dimensions of the bitmap are not powers of 2, OpenGL cannot use it as a texture. You should call PixelMap::rescale()
to resize the bit map.
void cugl::PixelMap::draw | ( | ) |
Draw the pixel map at the current raster position. Error NO_PIX_MAP
if there is no pixel map avaialble.
|
inline |
|
inline |
|
inline |
|
inline |
void cugl::PixelMap::read | ( | const char * | bmpFileName | ) |
Read a BMP file and convert it to a pixel map. Previous data associated with this object will be deleted. The BMP file must satisfy several criteria if it is to be converted successfully. Conversion failure is indicated by the following CUGL errors.
OPEN_FAILED:
the file could not be opened NOT_BMP_FILE:
the file is not a BMP file NOT_24_BITS:
the format is not 24 bits/pixel COMPRESSED_BMP_FILE:
the file is compressed NOT_ENOUGH_MEMORY:
there is not enough memory to store the dataOpenGL cannot use a bitmap as a texture if its dimensions are not powers of 2. To check whether the bitmap has acceptable dimensions, call PixelMap::badSize()
. To convert the bitmap dimensions to acceptable values, call PixelMap::rescale()
.
bmpFileName | is the name of the file to be read, with the extension '.bmp'. |
void cugl::PixelMap::read | ( | GLint | x, |
GLint | y, | ||
GLsizei | w, | ||
GLsizei | h, | ||
GLenum | mode = GL_FRONT |
||
) |
Read a pixel map from a region of the framebuffer. This function is similar to the constructor with the same parameters, but allocates new memory only if necessary.
x | is the X coordinate of the lower left corner of the region. |
y | is the Y coordinate of the lower left corner of the region. |
w | is the width of the region in pixels. |
h | is the height of the region in pixels. |
mode | is passed to glReadBuffer before reading the pixels. |
|
inline |
void cugl::PixelMap::rescale | ( | ) |
Rescale a bit map whose dimensions are not powers of 2. The new image will be distorted; the amount of distortion depends on how much the dimensions have to be altered. Use PixelMap::badSize()
to determine whether the dimensions are powers of 2.
void cugl::PixelMap::select | ( | const PixelMap & | src, |
int | xp, | ||
int | yp, | ||
int | width, | ||
int | height | ||
) |
Select a region from a pixel map.
src | is the pixel map from which the data is extracted. |
xp | defines the left side of the selected region. |
yp | defines the right side of the selected region. |
width | is the width of the selected region. |
height | is the height of the selected region. |
void cugl::PixelMap::setMipmaps | ( | GLuint | name | ) |
Set texture parameters for the pixel mipmaps. Construct a family of mipmaps for texturing.
name | is an OpenGL index for the texture parameters provided by the caller. |
GL_TEXTURE_MIN_FILTER
to GL_LINEAR_MIPMAP_NEAREST
. Call glTexParameter() to change this setting. glBindTexture
to select textures in the display function. void cugl::PixelMap::setTexture | ( | GLuint | name | ) |
Set texture parameters for the pixel map.
name | is an OpenGL index for the texture parameters provided by the caller. |
GL_TEXTURE_MAG_FILTER
and GL_TEXTURE_MIN_FILTER
to GL_NEAREST
. Call glTexParameter() to change these settings. void cugl::PixelMap::write | ( | const char * | bmpFileName | ) |
Write a pixel map to an output stream as a BMP file.
bmpFileName | is the name of the file to be written, with the extension '.bmp'. |
Check that two pixel maps are compatible for combining.
Combine two pixel maps.
m1 | is the first map to be combined. |
m2 | is the second map to be combined. |
res | is the resulting pixel map. The caller is responsible for constructing this map; it is not constructed by the function. |
prop | is the mixing proportion: 0 gives m1, 0.5 gives half of each, and 1 gives m2. |
|
friend |
Write a description of the pixel map to the output stream.
|
private |
|
private |
Number of columns in the pixel map.
Definition at line 2162 of file cugl.h.
Referenced by getColumns().
|
private |
|
private |
|
private |