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.
|
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
|
|
Helper functions to work with OpenGL Textures.
- Author
- Dr. Jeffrey Paone
- Copyright
- MIT License Copyright (c) 2017 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
◆ 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
-
filename | name of texture to load |
minFilter | minification filter to apply (default: GL_LINEAR) |
magFilter | magnification filter to apply (default: GL_LINEAR) |
wrapS | wrapping to apply to S coordinate (default: GL_REPEAT) |
wrapT | wrapping to apply to T coordinate (default: GL_REPEAT) |
flipOnY | flip the image along the vertical on load (default: GL_TRUE) |
printAllMessages | prints debug/error messages to terminal (default: GL_TRUE) |
enableMipmaps | create mipmaps for texture (default: GL_TRUE) |
enableAniso | enable 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
-
filename | name of texture to load |
minFilter | minification filter to apply (default: GL_LINEAR) |
magFilter | magnification filter to apply (default: GL_LINEAR) |
wrapS | wrapping to apply to S coordinate (default: GL_REPEAT) |
wrapT | wrapping to apply to T coordinate (default: GL_REPEAT) |
flipOnY | flip the image along the vertical on load (default: GL_TRUE) |
printAllMessages | prints debug/error messages to terminal (default: GL_TRUE) |
enableMipmaps | create mipmaps for texture (default: GL_TRUE) |
enableAniso | enable 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
-
cubeMapFace | face of the Cube Map to load the texture to |
filename | name 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] | filename | name of the image to load |
[out] | imageWidth | will contain the image width upon successful completion |
[out] | imageHeight | will contain the image height upon successful completion |
[out] | imageData | will contain the RGB data upon successful completion |
- Precondition
- imageData is unallocated
- Returns
- true if loading succeeded, false otherwise
- Note
- it's not terribly robust