Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The goal of the assignment is to add source code that maps two different textures to at least two of the shapes in the existing
The goal of the assignment is to add source code that maps two different textures to at least two of the shapes in the existing D scene. code wont run completely
CreateGLTexture
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
void SceneManager::BindGLTextures
for int i ; i mloadedTextures; i
bind textures on corresponding texture units
glActiveTextureGLTEXTURE i;
glBindTextureGLTEXTURED mtextureIDsiID;
DestroyGLTextures
void SceneManager::DestroyGLTextures
for int i ; i mloadedTextures; i
glGenTextures &mtextureIDsiID;
FindTextureID
int SceneManager::FindTextureIDstd::string tag
int textureID ;
int index ;
bool bFound false;
while index mloadedTextures && bFound false
if mtextureIDsindextag.comparetag
textureID mtextureIDsindexID;
bFound true;
else
index;
returntextureID;
FindTextureSlot
int SceneManager::FindTextureSlotstd::string tag
int textureSlot ;
int index ;
bool bFound false;
while index mloadedTextures && bFound false
if mtextureIDsindextag.comparetag
textureSlot index;
bFound true;
else
index;
returntextureSlot;
SetTransformations
void SceneManager::SetTransformations
glm::vec scaleXYZ,
float XrotationDegrees,
float YrotationDegrees,
float ZrotationDegrees,
glm::vec positionXYZ
variables for this method
glm::mat modelView;
glm::mat scale;
glm::mat rotationX;
glm::mat rotationY;
glm::mat rotationZ;
glm::mat translation;
set the scale value in the transform buffer
scale glm::scalescaleXYZ;
set the rotation values in the transform buffer
rotationX glm::rotateglm::radiansXrotationDegrees glm::vecfff;
rotationY glm::rotateglm::radiansYrotationDegrees glm::vecfff;
rotationZ glm::rotateglm::radiansZrotationDegrees glm::vecfff;
set the translation value in the transform buffer
translation glm::translatepositionXYZ;
modelView translation rotationZ rotationY rotationX scale;
if NULL mpShaderManager
mpShaderManagersetMatValuegModelName, modelView;
SetShaderColor
void SceneManager::SetShaderColor
float redColorValue,
float greenColorValue,
float blueColorValue,
float alphaValue
variables for this method
glm::vec currentColor;
currentColor.r redColorValue;
currentColor.g greenColorValue;
currentColor.b blueColorValue;
currentColor.a alphaValue;
if NULL mpShaderManager
mpShaderManagersetIntValuegUseTextureName, false;
mpShaderManagersetVecValuegColorValueName, currentColor;
SetShaderTexture
void SceneManager::SetShaderTexture
std::string textu
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started