2018-09-04 19:25:54 +00:00
|
|
|
#include "Application.h"
|
|
|
|
|
2018-09-05 15:47:09 +00:00
|
|
|
#include "Exception.h"
|
2018-09-04 19:25:54 +00:00
|
|
|
|
|
|
|
Application::Application(const char* class_name, HINSTANCE h_instance)
|
2018-09-05 20:26:50 +00:00
|
|
|
: m_client_size(1280, 720)
|
2018-09-04 19:25:54 +00:00
|
|
|
{
|
2018-09-05 15:47:09 +00:00
|
|
|
base_init();
|
2018-09-04 19:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Application::~Application()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int Application::run()
|
|
|
|
{
|
2018-09-05 20:26:50 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
GLenum gl_err;
|
|
|
|
while (!glfwWindowShouldClose(m_p_window))
|
|
|
|
{
|
|
|
|
// Handle all messages
|
|
|
|
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;
|
2018-09-04 19:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::close()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-05 15:47:09 +00:00
|
|
|
void Application::base_init()
|
2018-09-04 19:25:54 +00:00
|
|
|
{
|
2018-09-05 20:26:50 +00:00
|
|
|
if (!glfwInit())
|
2018-09-05 15:47:09 +00:00
|
|
|
{
|
2018-09-05 20:26:50 +00:00
|
|
|
throw EXCEPTION("Unable to Initialize GLFW");
|
2018-09-05 15:47:09 +00:00
|
|
|
}
|
2018-09-05 20:26:50 +00:00
|
|
|
m_p_window = glfwCreateWindow(m_client_size.x, m_client_size.y, "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");
|
2018-09-04 19:25:54 +00:00
|
|
|
|
|
|
|
m_fps.prepare();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::base_close()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|