diff options
author | Adrian Kummerlaender | 2018-05-25 23:08:45 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2018-05-25 23:08:45 +0200 |
commit | b9269b2206797091a29536f4f612a793201cdda5 (patch) | |
tree | 15bf3733fcc781decf2195873c852cfb58eca5f5 /src/window.h | |
parent | 8462bcc82e4845d24588eab4ef20be197ffd6c2e (diff) | |
download | computicle-b9269b2206797091a29536f4f612a793201cdda5.tar computicle-b9269b2206797091a29536f4f612a793201cdda5.tar.gz computicle-b9269b2206797091a29536f4f612a793201cdda5.tar.bz2 computicle-b9269b2206797091a29536f4f612a793201cdda5.tar.lz computicle-b9269b2206797091a29536f4f612a793201cdda5.tar.xz computicle-b9269b2206797091a29536f4f612a793201cdda5.tar.zst computicle-b9269b2206797091a29536f4f612a793201cdda5.zip |
Abstract GLFW window
Diffstat (limited to 'src/window.h')
-rw-r--r-- | src/window.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/window.h b/src/window.h new file mode 100644 index 0000000..76f1e6a --- /dev/null +++ b/src/window.h @@ -0,0 +1,59 @@ +#pragma once + +class Window { +private: + bool _good = false; + int _width = 800; + int _height = 600; + + GLFWwindow* const _handle; + +public: + Window(const std::string& title): + _handle(glfwCreateWindow(_width, _height, title.c_str(), NULL, NULL)) { + if ( _handle != nullptr ) { + glfwMakeContextCurrent(_handle); + if ( glewInit() == GLEW_OK ) { + _good = true; + } + glfwMakeContextCurrent(nullptr); + } + } + + bool isGood() const { + return _good; + } + + int getWidth() const { + return _width; + } + + int getHeight() const { + return _height; + } + + template <class F> + void init(F f) { + glfwMakeContextCurrent(_handle); + f(); + glfwMakeContextCurrent(nullptr); + } + + template <class F> + void render(F loop) { + glfwMakeContextCurrent(_handle); + + while ( glfwGetKey(_handle, GLFW_KEY_ESCAPE ) != GLFW_PRESS && + glfwWindowShouldClose(_handle) == 0 ) { + glfwGetWindowSize(_handle, &_width, &_height); + + loop(); + + glfwSwapBuffers(_handle); + glfwPollEvents(); + } + + glfwMakeContextCurrent(nullptr); + } + +}; |