charcoal/OpenGLEngine/Application.cpp
elipzer ada349c0a2 Added builtin Namespace
The builtin namespace is intended to be a slighly higher level
interface with OpenGL through the charcoal engine. It is inteneded
to allow the developer to create applications without needing to
create shader code or worry about rendering techniques. Eventually,
applications with lighting, textures, vertex coloring, shadows, and
a text-based UI should be available through the builtin namespace
2018-09-14 14:20:09 -04:00

83 lines
1.7 KiB
C++

#include "Application.h"
#include "Exception.h"
#include "Util.h"
namespace charcoal
{
Application::Application(int width, int height)
: m_screen_size(width, height)
{
if (width < 0 || height < 0)
throw EXCEPTION("Invalid screen dimensions");
if (!glfwInit())
throw EXCEPTION("Unable to Initialize GLFW");
m_p_window = glfwCreateWindow(width, height, "OpenGLEngine", NULL, NULL);
if (!m_p_window)
{
glfwTerminate();
throw EXCEPTION("Unable to Create GLFW Window");
}
glfwMakeContextCurrent(m_p_window);
glfwSwapInterval(1);
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");
// TODO: Mouse Movement, Mouse Scroll
m_glfw_input_manager.init(m_p_window);
glfwSetKeyCallback(m_p_window, &GLFWInputManager::key_callback);
m_fps.prepare();
}
int Application::run()
{
try
{
init();
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);
prerender();
render();
CHECK_GL_ERR();
glfwSwapBuffers(m_p_window);
}
return 0;
}
catch (Exception& e)
{
glfwTerminate();
throw e;
}
}
void Application::base_close()
{
close();
}
}