charcoal/OpenGLEngine/Application.cpp
elipzer a8c4b05d2f It Works! A triangle renders on the screen.
This commit gets creates the ObjectOriented scene and gets it
working.

The current test program swaps a triangle from small to large with
the 1 and 2 keys on the keyboard. (1 for small and 2 for large).

The small triangle is rendered by the simple scene and the large
one is rendered by the object oriented one.
2018-09-05 19:10:38 -04:00

92 lines
1.6 KiB
C++

#include "Application.h"
#include "Exception.h"
Application::Application()
{
base_init();
}
Application::~Application()
{
}
int Application::run()
{
try
{
init();
GLenum gl_err;
while (!glfwWindowShouldClose(m_p_window))
{
// Handle all messages
m_glfw_input_manager.mark();
glfwPollEvents();
float delta_time = m_fps.mark();
clock_t clock = m_fps.get_clock();
update(delta_time, clock);
render();
gl_err = glGetError();
if (gl_err != GL_NO_ERROR)
{
throw EXCEPTION("Caught OpenGL Error: " + std::to_string(gl_err));
}
glfwSwapBuffers(m_p_window);
}
return 0;
}
catch (Exception& e)
{
glfwTerminate();
throw e;
}
}
void Application::close()
{
}
void Application::base_init()
{
if (!glfwInit())
{
throw EXCEPTION("Unable to Initialize GLFW");
}
m_p_window = glfwCreateWindow(1280, 720, "OpenGLEngine", NULL, NULL);
if (!m_p_window)
{
glfwTerminate();
throw EXCEPTION("Unable to Create GLFW Window");
}
glfwMakeContextCurrent(m_p_window);
glewExperimental = GL_TRUE;
GLenum glew_err = glewInit();
if (glew_err != GLEW_OK)
{
glfwTerminate();
throw EXCEPTION("Unable to Initialize GLEW: " + std::string((char*)glewGetErrorString(glew_err)));
}
// Output Version Information
OutputDebugString("\nOpenGL Version Information:\nRenderer: ");
OutputDebugString((char*)glGetString(GL_RENDERER));
OutputDebugString("\nOpenGL Version: ");
OutputDebugString((char*)glGetString(GL_VERSION));
OutputDebugString("\n\n");
m_glfw_input_manager.init(m_p_window);
glfwSetKeyCallback(m_p_window, &GLFWInputManager::key_callback);
m_fps.prepare();
}
void Application::base_close()
{
close();
}