48 lines
866 B
C++
48 lines
866 B
C++
![]() |
#include "Application.hpp"
|
||
|
|
||
|
#include <stdexcept>
|
||
|
#include <sstream>
|
||
|
#include <GLFW/glfw3.h>
|
||
|
|
||
|
Application::~Application()
|
||
|
{
|
||
|
if (window != nullptr)
|
||
|
{
|
||
|
glfwDestroyWindow(window);
|
||
|
window = nullptr;
|
||
|
}
|
||
|
|
||
|
glfwTerminate();
|
||
|
}
|
||
|
|
||
|
void Application::Init(int width, int height, const std::string& title)
|
||
|
{
|
||
|
if(window == nullptr)
|
||
|
glfwInit();
|
||
|
|
||
|
window = glfwCreateWindow(width, height, title.c_str(), NULL, NULL);
|
||
|
if (window == nullptr)
|
||
|
{
|
||
|
const char* errorbuf;
|
||
|
int errorcode = glfwGetError(&errorbuf);
|
||
|
|
||
|
glfwTerminate();
|
||
|
|
||
|
std::stringstream errorstream;
|
||
|
errorstream << "Failed to create GLFWwindow (" << errorcode << "): \n" << errorbuf << std::endl;
|
||
|
throw std::runtime_error(errorstream.str());
|
||
|
}
|
||
|
|
||
|
glfwMakeContextCurrent(window);
|
||
|
}
|
||
|
|
||
|
void Application::Launch()
|
||
|
{
|
||
|
while (!glfwWindowShouldClose(window))
|
||
|
{
|
||
|
glfwPollEvents();
|
||
|
|
||
|
glfwSwapBuffers(window);
|
||
|
}
|
||
|
}
|