Question: #include SceneManager.h #ifndef STB _ IMAGE _ IMPLEMENTATION #define STB _ IMAGE _ IMPLEMENTATION #include stb _ image.h #endif #include / /
#include "SceneManager.h
#ifndef STBIMAGEIMPLEMENTATION
#define STBIMAGEIMPLEMENTATION
#include stbimage.h
#endif
#include
declaration of global variables
namespace
const char gModelName "model";
const char gColorValueName "objectColor";
const char gTextureValueName "objectTexture";
const char gUseTextureName "bUseTexture";
const char gUseLightingName "bUseLighting";
SceneManager
The constructor for the class
SceneManager::SceneManagerShaderManager pShaderManager
mpShaderManager pShaderManager;
mbasicMeshes new ShapeMeshes;
~SceneManager
The destructor for the class
SceneManager::~SceneManager
mpShaderManager NULL;
delete mbasicMeshes;
mbasicMeshes NULL;
CreateGLTexture
This method is used for loading textures from image files,
configuring the texture mapping parameters in OpenGL,
generating the mipmaps, and loading the read texture into
the next available texture slot in memory.
bool SceneManager::CreateGLTextureconst char filename, std::string tag
int width ;
int height ;
int colorChannels ;
GLuint textureID ;
indicate to always flip images vertically when loaded
stbisetflipverticallyonloadtrue;
try to parse the image data from the specified image file
unsigned char image stbiload
filename,
&width,
&height,
&colorChannels,
;
if the image was successfully read from the image file
if image
std::cout "Successfully loaded image:" filename width:" width height:" height channels:" colorChannels std::endl;
glGenTextures &textureID;
glBindTextureGLTEXTURED textureID;
set the texture wrapping parameters
glTexParameteriGLTEXTURED GLTEXTUREWRAPS GLREPEAT;
glTexParameteriGLTEXTURED GLTEXTUREWRAPT GLREPEAT;
set texture filtering parameters
glTexParameteriGLTEXTURED GLTEXTUREMINFILTER, GLLINEAR;
glTexParameteriGLTEXTURED GLTEXTUREMAGFILTER, GLLINEAR;
if the loaded image is in RGB format
if colorChannels
glTexImageDGLTEXTURED GLRGB width, height, GLRGB GLUNSIGNEDBYTE, image;
if the loaded image is in RGBA format it supports transparency
else if colorChannels
glTexImageDGLTEXTURED GLRGBA width, height, GLRGBA, GLUNSIGNEDBYTE, image;
else
std::cout "Not implemented to handle image with colorChannels channels" std::endl;
return false;
generate the texture mipmaps for mapping textures to lower resolutions
glGenerateMipmapGLTEXTURED;
free the image data from local memory
stbiimagefreeimage;
glBindTextureGLTEXTURED; Unbind the texture
register the loaded texture and associate it with the special tag string
mtextureIDsmloadedTexturesID textureID;
mtextureIDsmloadedTexturestag tag;
mloadedTextures;
return true;
std::cout "Could not load image:" filename std::endl;
Error loading the image
return false;
BindGLTextures
This method is used for binding the loaded textures to
OpenGL texture memory slots. There are up to slots.
void SceneManager::BindGLTextures
for int i ; i mloadedTextures; i
bind textures on corresponding texture units
glActiveTextureGLTEXTURE i;
glBindTextureGLTEXTURED mtextureIDsiID;
DestroyGLTextures
This method is used for freeing the memory in all the
used texture memory slots.
void SceneManager::DestroyGLTextures
for int i ; i mlo
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
