CSCI441 OpenGL Library 5.9.0
CS@Mines CSCI441 Computer Graphics Course Library
Loading...
Searching...
No Matches
Namespaces | Functions
TextureUtils.hpp File Reference

Helper functions to work with OpenGL Textures. More...

#include <glad/gl.h>
#include <stb_image.h>
#include <cstdio>
#include <cstring>
#include <string>

Go to the source code of this file.

Namespaces

namespace  CSCI441
 CSCI441 Helper Functions for OpenGL.
 
namespace  TextureUtils
 OpenGL Texture Utility functions.
 

Functions

bool CSCI441::TextureUtils::loadPPM (const char *filename, int &imageWidth, int &imageHeight, unsigned char *&imageData)
 loads a PPM into memory
 
GLuint CSCI441::TextureUtils::loadAndRegisterTexture (const char *filename, GLint minFilter=GL_LINEAR, GLint magFilter=GL_LINEAR, GLint wrapS=GL_REPEAT, GLint wrapT=GL_REPEAT, GLboolean flipOnY=GL_TRUE, GLboolean printAllMessages=GL_TRUE, GLboolean enableMipmaps=GL_TRUE, GLboolean enableAniso=GL_TRUE)
 loads and registers a texture into memory returning a texture handle
 
GLuint CSCI441::TextureUtils::loadAndRegister2DTexture (const char *filename, GLint minFilter=GL_LINEAR, GLint magFilter=GL_LINEAR, GLint wrapS=GL_REPEAT, GLint wrapT=GL_REPEAT, GLboolean flipOnY=GL_TRUE, GLboolean printAllMessages=GL_TRUE, GLboolean enableMipmaps=GL_TRUE, GLboolean enableAniso=GL_TRUE)
 loads and registers a texture into memory returning a texture handle
 
void CSCI441::TextureUtils::loadCubeMapFaceTexture (GLint cubeMapFace, const char *filename)
 loads a texture into memory of a cube face
 

Detailed Description

Helper functions to work with OpenGL Textures.

Author
Dr. Jeffrey Paone

These functions, classes, and constants help minimize common code that needs to be written.

Warning
This header file depends upon GLAD (or alternatively GLEW)
This header file depends upon stb_image

Function Documentation

◆ loadAndRegister2DTexture()

GLuint CSCI441::TextureUtils::loadAndRegister2DTexture ( const char *  filename,
GLint  minFilter = GL_LINEAR,
GLint  magFilter = GL_LINEAR,
GLint  wrapS = GL_REPEAT,
GLint  wrapT = GL_REPEAT,
GLboolean  flipOnY = GL_TRUE,
GLboolean  printAllMessages = GL_TRUE,
GLboolean  enableMipmaps = GL_TRUE,
GLboolean  enableAniso = GL_TRUE 
)
inline

loads and registers a texture into memory returning a texture handle

This function loads a texture into memory and registers the texture with OpenGL. The provided minification and magnification filters are set for the texture. The texture coordinate wrapping parameters are also set.

Parameters
filenamename of texture to load
minFilterminification filter to apply (default: GL_LINEAR)
magFiltermagnification filter to apply (default: GL_LINEAR)
wrapSwrapping to apply to S coordinate (default: GL_REPEAT)
wrapTwrapping to apply to T coordinate (default: GL_REPEAT)
flipOnYflip the image along the vertical on load (default: GL_TRUE)
printAllMessagesprints debug/error messages to terminal (default: GL_TRUE)
enableMipmapscreate mipmaps for texture (default: GL_TRUE)
enableAnisoenable anisotropic filtering for mipmaps (default: GL_TRUE)
Returns
texture handle corresponding to the texture

◆ loadAndRegisterTexture()

GLuint CSCI441::TextureUtils::loadAndRegisterTexture ( const char *  filename,
GLint  minFilter = GL_LINEAR,
GLint  magFilter = GL_LINEAR,
GLint  wrapS = GL_REPEAT,
GLint  wrapT = GL_REPEAT,
GLboolean  flipOnY = GL_TRUE,
GLboolean  printAllMessages = GL_TRUE,
GLboolean  enableMipmaps = GL_TRUE,
GLboolean  enableAniso = GL_TRUE 
)
inline

loads and registers a texture into memory returning a texture handle

Note
Calls through to loadAndRegister2DTexture()
Parameters
filenamename of texture to load
minFilterminification filter to apply (default: GL_LINEAR)
magFiltermagnification filter to apply (default: GL_LINEAR)
wrapSwrapping to apply to S coordinate (default: GL_REPEAT)
wrapTwrapping to apply to T coordinate (default: GL_REPEAT)
flipOnYflip the image along the vertical on load (default: GL_TRUE)
printAllMessagesprints debug/error messages to terminal (default: GL_TRUE)
enableMipmapscreate mipmaps for texture (default: GL_TRUE)
enableAnisoenable anisotropic filtering for mipmaps (default: GL_TRUE)
Returns
texture handle corresponding to the texture

◆ loadCubeMapFaceTexture()

void CSCI441::TextureUtils::loadCubeMapFaceTexture ( GLint  cubeMapFace,
const char *  filename 
)
inline

loads a texture into memory of a cube face

Parameters
cubeMapFaceface of the Cube Map to load the texture to
filenamename of image to load texture from
Warning
Cube Map must be bound as active texture before calling

◆ loadPPM()

bool CSCI441::TextureUtils::loadPPM ( const char *  filename,
int &  imageWidth,
int &  imageHeight,
unsigned char *&  imageData 
)
inline

loads a PPM into memory

This function reads an ASCII PPM, returning true if the function succeeds and false if it fails. If it succeeds, the variables imageWidth and imageHeight will hold the width and height of the read image, respectively.

Returns the image as an unsigned character array containing imageWidth*imageHeight*3 entries (for that many bytes of storage).

Warning
This function expects imageData to be UNALLOCATED, and will allocate memory itself. If the function fails (returns false), imageData will be set to NULL and any allocated memory will be automatically deallocated.
Parameters
[in]filenamename of the image to load
[out]imageWidthwill contain the image width upon successful completion
[out]imageHeightwill contain the image height upon successful completion
[out]imageDatawill contain the RGB data upon successful completion
Precondition
imageData is unallocated
Returns
true if loading succeeded, false otherwise
Note
it's not terribly robust