Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

With the below code I need help addig a complex 3 D object using at least two basic 3 D shapes. / / Main GLFW

With the below code I need help addig a complex 3D object using at least two basic 3D shapes.
// Main GLFW window
GLFWwindow* g_Window = nullptr;
// scene manager object for managing the 3D scene prepare and render
SceneManager* g_SceneManager = nullptr;
// shader manager object for dynamic interaction with the shader code
ShaderManager* g_ShaderManager = nullptr;
// view manager object for managing the 3D view setup and projection to 2D
ViewManager* g_ViewManager = nullptr;
}
// Function declarations - all functions that are called manually
// need to be pre-declared at the beginning of the source code.
bool InitializeGLFW();
bool InitializeGLEW();
/***********************************************************
* main(int, char*)
*
* This function gets called after the application has been
* launched.
***********************************************************/
int main(int argc, char* argv[])
{
// if GLFW fails initialization, then terminate the application
if (InitializeGLFW()== false)
{
return(EXIT_FAILURE);
}
// try to create a new shader manager object
g_ShaderManager = new ShaderManager();
// try to create a new view manager object
g_ViewManager = new ViewManager(
g_ShaderManager);
// try to create the main display window
g_Window = g_ViewManager->CreateDisplayWindow(WINDOW_TITLE);
// if GLEW fails initialization, then terminate the application
if (InitializeGLEW()== false)
{
return(EXIT_FAILURE);
}
// load the shader code from the external GLSL files
g_ShaderManager->LoadShaders(
"shaders/vertexShader.glsl",
"shaders/fragmentShader.glsl");
g_ShaderManager->use();
// try to create a new scene manager object and prepare the 3D scene
g_SceneManager = new SceneManager(g_ShaderManager);
g_SceneManager->PrepareScene();
// declare the variables for the transformations
glm::vec3 scaleXYZ;
float XrotationDegrees =0.0f;
float YrotationDegrees =0.0f;
float ZrotationDegrees =0.0f;
glm::vec3 positionXYZ;
// loop will keep running until the application is closed
// or until an error has occurred
while (!glfwWindowShouldClose(g_Window))
{
// Enable z-depth
glEnable(GL_DEPTH_TEST);
// Clear the frame and z buffers
glClearColor(0.0f,0.0f,0.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// convert from 3D object space to 2D view
g_ViewManager->PrepareSceneView();
// refresh the 3D scene
g_SceneManager->RenderScene();
// Flips the the back buffer with the front buffer every frame.
glfwSwapBuffers(g_Window);
// query the latest GLFW events
glfwPollEvents();
}
// clear the allocated manager objects from memory
if (NULL != g_SceneManager)
{
delete g_SceneManager;
g_SceneManager = NULL;
}
if (NULL != g_ViewManager)
{
delete g_ViewManager;
g_ViewManager = NULL;
}
if (NULL != g_ShaderManager)
{
delete g_ShaderManager;
g_ShaderManager = NULL;
}
// Terminates the program successfully
exit(EXIT_SUCCESS);
}
/***********************************************************
* InitializeGLFW()
*
* This function is used to initialize the GLFW library.
***********************************************************/
bool InitializeGLFW()
{
// GLFW: initialize and configure library
//--------------------------------------
glfwInit();
#ifdef __APPLE__
// set the version of OpenGL and profile to use
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#else
// set the version of OpenGL and profile to use
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#endif
// GLFW: end -------------------------------
return(true);
}
/***********************************************************
* InitializeGLEW()
*
* This function is used to initialize the GLEW library.
***********************************************************/
bool InitializeGLEW()
{
// GLEW: initialize
//-----------------------------------------
GLenum GLEWInitResult = GLEW_OK;
// try to initialize the GLEW library
GLEWInitResult = glewInit();
if (GLEW_OK != GLEWInitResult)
{
std::cerr << glewGetErrorString(GLEWInitResult)<< std::endl;
return false;
}
// GLEW: end -------------------------------
// Displays a successful OpenGL initialization message
std::cout << "INFO: OpenGL Successfully Initialized
";
std::cout << "INFO: OpenGL Version: "<< glGetString(GL_VERSION)<<"
"<< std::endl;
return(true);
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions

Question

Conduct a needs assessment. page 269

Answered: 1 week ago