Question: #include SceneManager.h #ifndef STB _ IMAGE _ IMPLEMENTATION #define STB _ IMAGE _ IMPLEMENTATION #include stb _ image.h #endif #include / /

#include "SceneManager.h"
#ifndef STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#endif
#include
// declaration of global variables
namespace
{
const char* g_ModelName = "model";
const char* g_ColorValueName = "objectColor";
const char* g_TextureValueName = "objectTexture";
const char* g_UseTextureName = "bUseTexture";
const char* g_UseLightingName = "bUseLighting";
}
/***********************************************************
* SceneManager()
*
* The constructor for the class
***********************************************************/
SceneManager::SceneManager(ShaderManager *pShaderManager)
{
m_pShaderManager = pShaderManager;
m_basicMeshes = new ShapeMeshes();
}
/***********************************************************
* ~SceneManager()
*
* The destructor for the class
***********************************************************/
SceneManager::~SceneManager()
{
m_pShaderManager = NULL;
delete m_basicMeshes;
m_basicMeshes = 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::CreateGLTexture(const char* filename, std::string tag)
{
int width =0;
int height =0;
int colorChannels =0;
GLuint textureID =0;
// indicate to always flip images vertically when loaded
stbi_set_flip_vertically_on_load(true);
// try to parse the image data from the specified image file
unsigned char* image = stbi_load(
filename,
&width,
&height,
&colorChannels,
0);
// 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(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
// set the texture wrapping parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// set texture filtering parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// if the loaded image is in RGB format
if (colorChannels ==3)
glTexImage2D(GL_TEXTURE_2D,0, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
// if the loaded image is in RGBA format - it supports transparency
else if (colorChannels ==4)
glTexImage2D(GL_TEXTURE_2D,0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 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
glGenerateMipmap(GL_TEXTURE_2D);
// free the image data from local memory
stbi_image_free(image);
glBindTexture(GL_TEXTURE_2D,0); // Unbind the texture
// register the loaded texture and associate it with the special tag string
m_textureIDs[m_loadedTextures].ID = textureID;
m_textureIDs[m_loadedTextures].tag = tag;
m_loadedTextures++;
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 16 slots.
***********************************************************/
void SceneManager::BindGLTextures()
{
for (int i =0; i m_loadedTextures; i++)
{
// bind textures on corresponding texture units
glActiveTexture(GL_TEXTURE0+ i);
glBindTexture(GL_TEXTURE_2D, m_textureIDs[i].ID);
}
}
/***********************************************************
* DestroyGLTextures()
*
* This method is used for freeing the memory in all the
* used texture memory slots.
***********************************************************/
void SceneManager::DestroyGLTextures()
{
for (int i =0; i m_lo
 #include "SceneManager.h" #ifndef STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" #endif #include //

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!