FifeGUI 0.2.0
A C++ GUI library designed for games.
fcn::opengl::Image Class Reference

#include <image.hpp>

Inheritance diagram for fcn::opengl::Image:
fcn::Image

Public Member Functions

void convertToDisplayFormat () override
void free () override
int getHeight () const override
Color getPixel (int x, int y) override
virtual GLuint getTextureHandle () const
virtual int getTextureHeight () const
virtual int getTextureWidth () const
int getWidth () const override
 Image (GLuint textureHandle, int width, int height, bool autoFree)
 Image (Image &&)=delete
 Image (Image const &)=delete
 Image (std::span< unsigned int const > pixels, int width, int height, bool convertToDisplayFormat=true)
Imageoperator= (Image &&)=delete
Imageoperator= (Image const &)=delete
void putPixel (int x, int y, Color const &color) override
Public Member Functions inherited from fcn::Image
 Image (Image &&)=delete
 Image (Image const &)=delete
Image & operator= (Image &&)=delete
Image & operator= (Image const &)=delete

Protected Attributes

bool mAutoFree
int mHeight
std::vector< unsigned int > mPixels
GLuint mTextureHandle
int mTextureHeight
int mTextureWidth
int mWidth

Additional Inherited Members

Static Public Member Functions inherited from fcn::Image
static ImageLoadergetImageLoader ()
static Image * load (std::string const &filename, bool convertToDisplayFormat=true)
static void setImageLoader (ImageLoader *imageLoader)
Static Protected Attributes inherited from fcn::Image
static ImageLoadermImageLoader = nullptr

Detailed Description

OpenGL-specific implementation of Image.

Definition at line 33 of file backends/opengl/image.hpp.

Constructor & Destructor Documentation

◆ Image() [1/2]

fcn::opengl::Image::Image ( std::span< unsigned int const > pixels,
int width,
int height,
bool convertToDisplayFormat = true )

Constructor.

Loads an image from an array of pixels. The pixel array is is copied in the constructor and should thus be freed after the constructor has been called.

NOTE: The functions getPixel and putPixel are only guaranteed to work before an image has been converted to display format.

Parameters
pixelspixel buffer to load from.
widththe width of the image.
heightthe height of the image.
convertToDisplayFormattrue if the image should be converted to display, false otherwise.

Definition at line 13 of file backends/opengl/image.cpp.

References convertToDisplayFormat(), mAutoFree, mHeight, mPixels, mTextureHandle, mTextureHeight, mTextureWidth, and mWidth.

◆ Image() [2/2]

fcn::opengl::Image::Image ( GLuint textureHandle,
int width,
int height,
bool autoFree )

Constructor.

Load an image from an OpenGL texture handle. The width and height specifies the size of the "interesting" part of the texture, the real width and height of the texture are assumed to be the closest higher power of two.

Parameters
textureHandlethe texture handle from which to load.
widththe width of the image.
heightthe height of the image.
autoFreetrue if the surface should automatically be deleted.

Definition at line 54 of file backends/opengl/image.cpp.

References mAutoFree, mHeight, mPixels, mTextureHandle, mTextureHeight, mTextureWidth, and mWidth.

◆ ~Image()

fcn::opengl::Image::~Image ( )
overridevirtual

Reimplemented from fcn::Image.

Definition at line 73 of file backends/opengl/image.cpp.

Member Function Documentation

◆ convertToDisplayFormat()

void fcn::opengl::Image::convertToDisplayFormat ( )
overridevirtual

Converts the image, if possible, to display format.

IMPORTANT: Only guaranteed to work before the image has been converted to display format.

Implements fcn::Image.

Definition at line 164 of file backends/opengl/image.cpp.

References mPixels, mTextureHandle, mTextureHeight, and mTextureWidth.

Referenced by Image().

◆ free()

void fcn::opengl::Image::free ( )
overridevirtual

Frees an image.

Implements fcn::Image.

Definition at line 99 of file backends/opengl/image.cpp.

References mPixels, and mTextureHandle.

◆ getHeight()

int fcn::opengl::Image::getHeight ( ) const
overridevirtual

Gets the height of the image.

Returns
The height of the image.

Implements fcn::Image.

Definition at line 113 of file backends/opengl/image.cpp.

References mHeight.

◆ getPixel()

Color fcn::opengl::Image::getPixel ( int x,
int y )
overridevirtual

Gets the color of a pixel at coordinate (x, y) in the image.

IMPORTANT: Only guaranteed to work before the image has been converted to display format.

Parameters
xThe x coordinate.
yThe y coordinate.
Returns
The color of the pixel.

Implements fcn::Image.

Definition at line 118 of file backends/opengl/image.cpp.

References mHeight, mPixels, mTextureWidth, and mWidth.

◆ getTextureHandle()

GLuint fcn::opengl::Image::getTextureHandle ( ) const
virtual

Gets the OpenGL texture handle for the image.

Returns
the OpenGL texture handle for the image.

Definition at line 84 of file backends/opengl/image.cpp.

References mTextureHandle.

◆ getTextureHeight()

int fcn::opengl::Image::getTextureHeight ( ) const
virtual

Gets the height of the texture.

Returns
the height of the texture.

Definition at line 94 of file backends/opengl/image.cpp.

References mTextureHeight.

◆ getTextureWidth()

int fcn::opengl::Image::getTextureWidth ( ) const
virtual

Gets the width of texture.

Returns
the width of the texture.

Definition at line 89 of file backends/opengl/image.cpp.

References mTextureWidth.

◆ getWidth()

int fcn::opengl::Image::getWidth ( ) const
overridevirtual

Gets the width of the image.

Returns
The width of the image.

Implements fcn::Image.

Definition at line 108 of file backends/opengl/image.cpp.

References mWidth.

◆ putPixel()

void fcn::opengl::Image::putPixel ( int x,
int y,
Color const & color )
overridevirtual

Puts a pixel with a certain color at coordinate (x, y).

Parameters
xThe x coordinate.
yThe y coordinate.
colorThe color of the pixel to put.

Implements fcn::Image.

Definition at line 145 of file backends/opengl/image.cpp.

References fcn::Color::a, fcn::Color::b, fcn::Color::g, mHeight, mPixels, mTextureWidth, mWidth, and fcn::Color::r.

Member Data Documentation

◆ mAutoFree

bool fcn::opengl::Image::mAutoFree
protected

Whether the texture handle should be freed on destruction.

Definition at line 116 of file backends/opengl/image.hpp.

Referenced by Image(), and Image().

◆ mHeight

int fcn::opengl::Image::mHeight
protected

Logical image height in pixels.

Definition at line 122 of file backends/opengl/image.hpp.

Referenced by getHeight(), getPixel(), Image(), Image(), and putPixel().

◆ mPixels

std::vector<unsigned int> fcn::opengl::Image::mPixels
protected

Pixel buffer copy for the image (RGBA packed).

Definition at line 113 of file backends/opengl/image.hpp.

Referenced by convertToDisplayFormat(), free(), getPixel(), Image(), Image(), and putPixel().

◆ mTextureHandle

GLuint fcn::opengl::Image::mTextureHandle
protected

OpenGL texture handle backing this image (if any).

Definition at line 110 of file backends/opengl/image.hpp.

Referenced by convertToDisplayFormat(), free(), getTextureHandle(), Image(), and Image().

◆ mTextureHeight

int fcn::opengl::Image::mTextureHeight
protected

Actual texture height (power-of-two) used by GL.

Definition at line 128 of file backends/opengl/image.hpp.

Referenced by convertToDisplayFormat(), getTextureHeight(), Image(), and Image().

◆ mTextureWidth

int fcn::opengl::Image::mTextureWidth
protected

Actual texture width (power-of-two) used by GL.

Definition at line 125 of file backends/opengl/image.hpp.

Referenced by convertToDisplayFormat(), getPixel(), getTextureWidth(), Image(), Image(), and putPixel().

◆ mWidth

int fcn::opengl::Image::mWidth
protected

Logical image width in pixels.

Definition at line 119 of file backends/opengl/image.hpp.

Referenced by getPixel(), getWidth(), Image(), Image(), and putPixel().


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