GlistEngine
Loading...
Searching...
No Matches
gImage Class Reference

#include <gImage.h>

Inheritance diagram for gImage:
Collaboration diagram for gImage:

Public Member Functions

 gImage ()
 gImage (int w, int h, int format=GL_RGBA)
 gImage (const gImage &other)
 gImage (gImage &&other) noexcept
gImage & operator= (const gImage &other)
gImage & operator= (gImage &&other) noexcept
virtual ~gImage ()
unsigned int load (const std::string &fullPath)
unsigned int loadImage (const std::string &imagePath)
unsigned int loadImageFromURL (const std::string &imageUrl)
unsigned int loadImageFromURL (const std::string &imageUrl, bool cutUrlParameters)
void loadData (const std::string &fullPath)
void loadImageData (const std::string &imagePath)
unsigned int useData ()
void setImageData (unsigned char *imageData)
void setImageData (unsigned char *imageData, int width, int height, int componentNum, bool isMutable=false, bool isStbImage=false)
unsigned char * getImageData ()
void setImageDataHDR (float *imageData)
void setImageDataHDR (float *imageData, int width, int height, int componentNum, bool isMutable=false, bool isStbImage=false)
float * getImageDataHDR ()
void clearData ()
void save (std::string fullpath)
void saveImage (std::string fileName)
bool checkPixelPerfectCollision (gImage *otherImage, float imgposX, float imgposY, float otherimgposX, float otherimgposY)
std::string getImageUrl ()
unsigned int loadMaskImage (const std::string &maskImagePath)
Public Member Functions inherited from gTexture
 gTexture ()
 gTexture (int w, int h, int format=GL_RGBA, bool isFbo=false)
 gTexture (const gTexture &other)
 gTexture (gTexture &&other) noexcept
 gTexture (int w, int h, int miplevels, int format, bool isFbo)
gTexture & operator= (const gTexture &other)
gTexture & operator= (gTexture &&other) noexcept
virtual ~gTexture ()
unsigned int loadTexture (const std::string &texturePath)
unsigned int loadMask (const std::string &fullPath)
unsigned int loadMaskTexture (const std::string &maskTexturePath)
void setMaskMode (int maskMode)
void setMaskRotation (float angle)
void setImageRotation (float angle)
void setObjectRotation (float angle)
void setAlphaMasking (int maskMode)
void disableAlphaMasking ()
bool getAlphaMasking () const
void bind () const
void bind (int textureSlotNo) const
void unbind () const
unsigned int getId () const
bool isHDR () const
unsigned int getInternalFormat () const
unsigned int getFormat () const
void setType (TextureType textureType)
TextureType getType () const
void setWrapping (int wrapS, int wrapT)
void setFiltering (int minFilter, int magFilter)
int getWrapS () const
int getWrapT () const
int getFilterMin () const
int getFilterMag () const
const std::string & getTypeName () const
const std::string & getFilename () const
const std::string & getDir () const
const std::string & getFullPath () const
int getWidth () const
int getHeight () const
int getComponentNum () const
void draw (int x, int y)
void draw (int x, int y, int w, int h)
void draw (int x, int y, int w, int h, float rotate)
void draw (int x, int y, int w, int h, int pivotx, int pivoty, float rotate)
void draw (int x, int y, int w, int h, int pivotx, int pivoty, float rotate, bool flipHorizontal)
void draw (glm::vec2 position, glm::vec2 size, float rotate=0.0f)
void draw (glm::vec2 position, glm::vec2 size, glm::vec2 pivot, float rotate=0.0f)
void drawSub (int x, int y, int sx, int sy, int sw, int sh)
void drawSub (int x, int y, int w, int h, int sx, int sy, int sw, int sh)
void drawSub (int x, int y, int w, int h, int sx, int sy, int sw, int sh, float rotate)
void drawSub (int x, int y, int w, int h, int sx, int sy, int sw, int sh, int pivotx, int pivoty, float rotate)
void drawSub (int x, int y, int w, int h, int sx, int sy, int sw, int sh, int pivotx, int pivoty, float rotate, bool flipHorizontal)
void drawSub (glm::vec2 pos, glm::vec2 size, glm::vec2 subpos, glm::vec2 subsize, float rotate=0.0f)
void drawSub (glm::vec2 pos, glm::vec2 size, glm::vec2 subpos, glm::vec2 subsize, glm::vec2 pivot, float rotate=0.0f)
void drawSub (glm::vec2 pos, glm::vec2 size, glm::vec2 subpos, glm::vec2 subsize, glm::vec2 pivot, float rotate, bool flipHorizontal)
void drawSub (const gRect &src, const gRect &dst, float rotate=0.f)
void drawSub (const gRect &src, const gRect &dst, int pivotx, int pivoty, float rotate=0.f)
void drawSub (const gRect &src, const gRect &dst, glm::vec2 pivot, float rotate=0.f)
unsigned int setData (unsigned char *textureData, int width, int height, int componentNum, bool isMutable=false, bool isStbImage=false)
unsigned int setDataHDR (float *textureData, int width, int height, int componentNum, bool isMutable=false, bool isStbImage=false)
void setupRenderData ()
void cleanupData ()
void cleanupAll ()
void save (std::string fullpath)
void saveTexture (std::string fileName)
unsigned char * getData ()
Public Member Functions inherited from gRenderObject
 gRenderObject ()
int getScreenWidth ()
int getScreenHeight ()
void pushMatrix ()
void popMatrix ()
Public Member Functions inherited from gObject
 gObject ()
void logi (std::string message)
void logd (std::string message)
void logw (std::string message)
void loge (std::string message)
void logi (std::string tag, std::string message)
void logd (std::string tag, std::string message)
void logw (std::string tag, std::string message)
void loge (std::string tag, std::string message)

Static Public Member Functions

static std::string generateDownloadedImagePath (std::string imageType="png")
Static Public Member Functions inherited from gTexture
static const std::string & getTypeName (TextureType textureType)
Static Public Member Functions inherited from gRenderObject
static void setScreenSize (int screenWidth, int screenHeight)
static void setUnitScreenSize (int unitWidth, int unitHeight)
static void setScreenScaling (int screenScaling)
static void enableShadowMapping ()
static void disableShadowMapping ()
static bool isShadowMappingEnabled ()
static void enableExtraShaders (bool isEnabled=true)
static void disableExtraShaders ()
static bool isExtraShadersEnabled ()
static gRenderer * getRenderer ()
static void destroyRenderer ()
static void createRenderer (int renderEngine=G_RENDERER_GL)
Static Public Member Functions inherited from gObject
static std::string gGetAppDir ()
static std::string gGetAssetsDir ()
static void gSetAssetsDir (std::string assetsDir)
static std::string gGetFilesDir ()
static std::string gGetImagesDir ()
static std::string gGetFontsDir ()
static std::string gGetModelsDir ()
static std::string gGetTexturesDir ()
static std::string gGetShadersDir ()
static std::string gGetSoundsDir ()
static std::string gGetDatabasesDir ()
static std::string gGetVideosDir ()
static void setCurrentResolution (int scalingNo, int currentResolutionNo)

Protected Member Functions

void copyFrom (const gImage &other) noexcept
void swap (gImage &other) noexcept
Protected Member Functions inherited from gTexture
void setDataInternal (unsigned char *textureData, bool isMutable=false, bool isStbImage=false, bool clean=true)
void setDataInternalHDR (float *textureData, bool isMutable=false, bool isStbImage=false, bool clean=true)
bool isMutable ()
void swap (gTexture &other) noexcept
void copyFrom (const gTexture &other) noexcept
std::string getDirName (const std::string &fname)
std::string getFileName (const std::string &fname)

Additional Inherited Members

Public Types inherited from gTexture
enum  TextureType : int {
  TEXTURETYPE_DIFFUSE = 0 , TEXTURETYPE_SPECULAR = 1 , TEXTURETYPE_NORMAL = 2 , TEXTURETYPE_HEIGHT = 3 ,
  TEXTURETYPE_PBR_ALBEDO = 4 , TEXTURETYPE_PBR_ROUGHNESS = 5 , TEXTURETYPE_PBR_METALNESS = 6 , TEXTURETYPE_PBR_NORMAL = 7 ,
  TEXTURETYPE_PBR_AO = 8 , TEXTURETYPE_COUNT
}
enum  TextureWrap : int { TEXTUREWRAP_REPEAT = 0 , TEXTUREWRAP_CLAMP = 1 , TEXTUREWRAP_CLAMPTOEDGE = 2 , TEXTUREWRAP_NEAREST = 3 }
enum  TextureMagFilter : int { TEXTUREMINMAGFILTER_LINEAR = 0 , TEXTUREMINMAGFILTER_MIPMAPLINEAR = 1 , TEXTUREMINMAGFILTER_NEAREST = 2 , TEXTUREMINMAGFILTER_CLAMP = 3 }
enum  MaskMode : int { MASKMODE_BOTH = 0 , MASKMODE_PICTURE = 1 , MASKMODE_MASK = 2 , MASKMODE_BOTH_FREE_ROTATE = 3 }
Static Public Attributes inherited from gObject
static const int LOGLEVEL_SILENT
static const int LOGLEVEL_DEBUG
static const int LOGLEVEL_INFO
static const int LOGLEVEL_WARNING
static const int LOGLEVEL_ERROR
Protected Attributes inherited from gTexture
std::string fullpath
std::string directory
unsigned int id
unsigned int internalformat
unsigned int format
TextureType type
std::string path
int width
int height
int componentnum
unsigned char * data
bool ismutable
bool isstbimage
int wraps
int wrapt
int filtermin
int filtermag
bool ishdr
float * datahdr
bool ismaskloaded
gTexture * masktexture
bool istextureallocated
int maskmode = MASKMODE_BOTH
float maskRotation = 0.0f
float imageRotation = 0.0f
float objectRotation = 0.0f
bool isalphamasking = false
Static Protected Attributes inherited from gRenderObject
static bool isshadowmappingenabled
static bool isextrashadersenabled
Static Protected Attributes inherited from gObject
static int renderpassnum
static int renderpassno
static int releasescaling
static int releaseresolution

Detailed Description

gImage holds several functions primarily to locate and load images.

Overview of the functions: load and loadImage functions to load images effectively. loadData and loadImageData functions to load image's Data in a separate thread. useData function to create the texture in VRAM by using the loaded data. setImageData function to alter an image's data in integer format. setImageDataHDR function to alter an image's data in float format. getImageData function to access an image's original or edited data in integer format. getImageDataHDR function to access an image's original or edited data in float format. clearData function to clear a given Data.

Constructor & Destructor Documentation

◆ gImage() [1/4]

gImage::gImage ( )

◆ gImage() [2/4]

gImage::gImage ( int w,
int h,
int format = GL_RGBA )

◆ gImage() [3/4]

gImage::gImage ( const gImage & other)

◆ gImage() [4/4]

gImage::gImage ( gImage && other)
noexcept

◆ ~gImage()

virtual gImage::~gImage ( )
virtual

Member Function Documentation

◆ checkPixelPerfectCollision()

bool gImage::checkPixelPerfectCollision ( gImage * otherImage,
float imgposX,
float imgposY,
float otherimgposX,
float otherimgposY )

Used to check pixel perfect collision between 2 images.

Parameters
OtherImagefor the target image object which will be checked collisions with the caller object. positions of this images and position of the target image rotations of this images and rotation of the target image

◆ clearData()

void gImage::clearData ( )

Clears the data of a given structure.

◆ copyFrom()

void gImage::copyFrom ( const gImage & other)
protectednoexcept

◆ generateDownloadedImagePath()

std::string gImage::generateDownloadedImagePath ( std::string imageType = "png")
static

◆ getImageData()

unsigned char * gImage::getImageData ( )

Accesses an image's original or edited data in integer format. The data should be loaded in order to be accessed by this function.

◆ getImageDataHDR()

float * gImage::getImageDataHDR ( )

Accesses an image's original or edited data in float format. The data should be loaded in order to be accessed by this function.

◆ getImageUrl()

std::string gImage::getImageUrl ( )

◆ load()

unsigned int gImage::load ( const std::string & fullPath)
virtual

Loads an image from the given fullpath.

Supported image formats can be found in the class description.

The image might be stored anywhere on the hard disk or other storage devices out of the project folder.

This function was created primarily for development purposes. Due to the difficulties and errors of storing images in a messy fashion, developers are encouraged to use the loadImage function instead.

Parameters
fullPathThe full path to the image file. It should contain the full path of the folder where the image is located, the name of the image and its extension. It is case sensitive.
Returns
Image id number generated by OpenGL.

Reimplemented from gTexture.

◆ loadData()

void gImage::loadData ( const std::string & fullPath)

Loads an image's data from the given full path to the RAM.

Supported image formats can be found in the class description.

The image can be located in anywhere(hard disk or other storage devices) as long as it has the full path.Supported image formats can be found in the class description.

Loading assets in separate threads improves overall efficiency. In order to load an image's data separately, this function can be used. It doesn't create a texture of the loaded data's image in VRAM, instead it loads the Data of a given image and saves it into the RAM.

Parameters
fullPathThe full path to the image file. It should contain the full path of the folder where the image is located.

◆ loadImage()

unsigned int gImage::loadImage ( const std::string & imagePath)

Loads an image from the project's images folder.

Supported image formats can be found in the class description.

There is no need to enter the folder address, as the function loads from the project's own images folders. It is only necessary to specify the name and extension of the image. For example, giving an address such as "image.jpg" is sufficient. Make sure that the named image is placed in the project's images folder.

Project's default images folder is ProjectLocation/assets/images directory.

The project's image folder may vary depending on the project's scaling settings. In case of SCALING_NONE and SCALING_AUTO, this function loads images from ProjectLocation/assets/images folder. In case of SCALING_MIPMAP, ProjectLocation/assets/mipmaps/DeviceResolution folder becomes images folder.

Developers are encouraged to use this function for image loading so that an efficient and shareable work can be carried out.

Parameters
imagePathThe fullname of the image stored under project's images folder. Fullname should contain image name and its extension. It is case sensitive.
Returns
Image id number generated by OpenGL.

◆ loadImageData()

void gImage::loadImageData ( const std::string & imagePath)

Loads an image's data from the project's images folder to the RAM.

Supported image formats can be found in the class description.

It doesn't require a full path of an image because the function loads an image from the project's own images folders. In fact, providing this function with a path that looks like 'image.jpg' is sufficient.

Project's default images folder is ProjectLocation/assets/images directory.

Loading assets in separate threads improves overall efficiency. In order to load an image's data separately, this function can be used. It doesn't create a texture of the loaded data's image in VRAM, instead it loads the Data of a given image and saves it into the RAM.

Developers are encouraged to use this function for Data loading so that an efficient work can be carried out.

Parameters
ImagePathThe full name of the image stored under project's images folder which should contain the image name and its extension. It is case sensitive.

◆ loadImageFromURL() [1/2]

unsigned int gImage::loadImageFromURL ( const std::string & imageUrl)

◆ loadImageFromURL() [2/2]

unsigned int gImage::loadImageFromURL ( const std::string & imageUrl,
bool cutUrlParameters )

◆ loadMaskImage()

unsigned int gImage::loadMaskImage ( const std::string & maskImagePath)

◆ operator=() [1/2]

gImage & gImage::operator= ( const gImage & other)

◆ operator=() [2/2]

gImage & gImage::operator= ( gImage && other)
noexcept

◆ save()

void gImage::save ( std::string fullpath)

Used for the image's extension and changing image's name.

Parameters
fileNameis a string value for the function . This file will be exist in the GlistApp's assets clasor after saving process.

◆ saveImage()

void gImage::saveImage ( std::string fileName)

◆ setImageData() [1/2]

void gImage::setImageData ( unsigned char * imageData)

Alters an image's data in integer format.

Data of a given image can be altered by the usage of this function. It's in integer format.

◆ setImageData() [2/2]

void gImage::setImageData ( unsigned char * imageData,
int width,
int height,
int componentNum,
bool isMutable = false,
bool isStbImage = false )

◆ setImageDataHDR() [1/2]

void gImage::setImageDataHDR ( float * imageData)

Alters an image's data in float format.

Data of a given image can be altered by the usage of this function. It's in float format.

◆ setImageDataHDR() [2/2]

void gImage::setImageDataHDR ( float * imageData,
int width,
int height,
int componentNum,
bool isMutable = false,
bool isStbImage = false )

◆ swap()

void gImage::swap ( gImage & other)
protectednoexcept

◆ useData()

unsigned int gImage::useData ( )

Creates a texture in VRAM by the usage of loaded data.


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