GLFW-related update & -lstdc++fs
This commit is contained in:
parent
bfc7c85856
commit
086f04af39
@ -10,7 +10,7 @@ target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
|
|||||||
if(MSVC)
|
if(MSVC)
|
||||||
target_compile_options(${PROJECT_NAME} PRIVATE /W4)
|
target_compile_options(${PROJECT_NAME} PRIVATE /W4)
|
||||||
else()
|
else()
|
||||||
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra
|
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -lstdc++fs
|
||||||
# additional warnings
|
# additional warnings
|
||||||
-Wformat-nonliteral -Wcast-align
|
-Wformat-nonliteral -Wcast-align
|
||||||
-Wpointer-arith -Winline -Wundef
|
-Wpointer-arith -Winline -Wundef
|
||||||
|
|||||||
@ -12,8 +12,8 @@ float Events::x = 0.0f;
|
|||||||
float Events::y = 0.0f;
|
float Events::y = 0.0f;
|
||||||
bool Events::_cursor_locked = false;
|
bool Events::_cursor_locked = false;
|
||||||
bool Events::_cursor_started = false;
|
bool Events::_cursor_started = false;
|
||||||
|
std::vector<uint> Events::codepoints;
|
||||||
|
std::vector<int> Events::pressedKeys;
|
||||||
|
|
||||||
int Events::initialize(){
|
int Events::initialize(){
|
||||||
_keys = new bool[1032];
|
_keys = new bool[1032];
|
||||||
@ -61,5 +61,7 @@ void Events::pullEvents(){
|
|||||||
_current++;
|
_current++;
|
||||||
deltaX = 0.0f;
|
deltaX = 0.0f;
|
||||||
deltaY = 0.0f;
|
deltaY = 0.0f;
|
||||||
|
codepoints.clear();
|
||||||
|
pressedKeys.clear();
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,8 @@ public:
|
|||||||
static float y;
|
static float y;
|
||||||
static bool _cursor_locked;
|
static bool _cursor_locked;
|
||||||
static bool _cursor_started;
|
static bool _cursor_started;
|
||||||
|
static std::vector<uint> codepoints;
|
||||||
|
static std::vector<int> pressedKeys;
|
||||||
|
|
||||||
static int initialize();
|
static int initialize();
|
||||||
static void finalize();
|
static void finalize();
|
||||||
|
|||||||
@ -4,7 +4,11 @@
|
|||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
using glm::vec4;
|
||||||
|
|
||||||
GLFWwindow* Window::window = nullptr;
|
GLFWwindow* Window::window = nullptr;
|
||||||
|
std::stack<vec4> Window::scissorStack;
|
||||||
|
vec4 Window::scissorArea;
|
||||||
uint Window::width = 0;
|
uint Window::width = 0;
|
||||||
uint Window::height = 0;
|
uint Window::height = 0;
|
||||||
|
|
||||||
@ -31,23 +35,33 @@ void mouse_button_callback(GLFWwindow*, int button, int action, int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void key_callback(GLFWwindow*, int key, int /*scancode*/, int action, int /*mode*/) {
|
void key_callback(GLFWwindow*, int key, int scancode, int action, int /*mode*/) {
|
||||||
if (action == GLFW_PRESS) {
|
if (action == GLFW_PRESS) {
|
||||||
Events::_keys[key] = true;
|
Events::_keys[key] = true;
|
||||||
Events::_frames[key] = Events::_current;
|
Events::_frames[key] = Events::_current;
|
||||||
|
Events::pressedKeys.push_back(key);
|
||||||
}
|
}
|
||||||
else if (action == GLFW_RELEASE) {
|
else if (action == GLFW_RELEASE) {
|
||||||
Events::_keys[key] = false;
|
Events::_keys[key] = false;
|
||||||
Events::_frames[key] = Events::_current;
|
Events::_frames[key] = Events::_current;
|
||||||
}
|
}
|
||||||
|
else if (action == GLFW_REPEAT) {
|
||||||
|
Events::pressedKeys.push_back(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void window_size_callback(GLFWwindow*, int width, int height) {
|
void window_size_callback(GLFWwindow*, int width, int height) {
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
Window::width = width;
|
Window::width = width;
|
||||||
Window::height = height;
|
Window::height = height;
|
||||||
|
Window::resetScissor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void character_callback(GLFWwindow* window, unsigned int codepoint){
|
||||||
|
Events::codepoints.push_back(codepoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int Window::initialize(uint width, uint height, const char* title, int samples){
|
int Window::initialize(uint width, uint height, const char* title, int samples){
|
||||||
glfwInit();
|
glfwInit();
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
@ -75,7 +89,6 @@ int Window::initialize(uint width, uint height, const char* title, int samples){
|
|||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glEnable(GL_MULTISAMPLE);
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
Window::width = width;
|
Window::width = width;
|
||||||
@ -86,6 +99,7 @@ int Window::initialize(uint width, uint height, const char* title, int samples){
|
|||||||
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
||||||
glfwSetCursorPosCallback(window, cursor_position_callback);
|
glfwSetCursorPosCallback(window, cursor_position_callback);
|
||||||
glfwSetWindowSizeCallback(window, window_size_callback);
|
glfwSetWindowSizeCallback(window, window_size_callback);
|
||||||
|
glfwSetCharCallback(window, character_callback);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +111,42 @@ void Window::setCursorMode(int mode){
|
|||||||
glfwSetInputMode(window, GLFW_CURSOR, mode);
|
glfwSetInputMode(window, GLFW_CURSOR, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::resetScissor() {
|
||||||
|
scissorArea = vec4(0.0f, 0.0f, width, height);
|
||||||
|
scissorStack = std::stack<vec4>();
|
||||||
|
glDisable(GL_SCISSOR_TEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::pushScissor(vec4 area) {
|
||||||
|
if (scissorStack.empty()) {
|
||||||
|
glEnable(GL_SCISSOR_TEST);
|
||||||
|
}
|
||||||
|
scissorStack.push(scissorArea);
|
||||||
|
|
||||||
|
area.x = fmax(area.x, scissorArea.x);
|
||||||
|
area.y = fmax(area.y, scissorArea.y);
|
||||||
|
|
||||||
|
area.z = fmin(area.z, scissorArea.z);
|
||||||
|
area.w = fmin(area.w, scissorArea.w);
|
||||||
|
|
||||||
|
glScissor(area.x, Window::height-area.y-area.w, area.z, area.w);
|
||||||
|
scissorArea = area;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::popScissor() {
|
||||||
|
if (scissorStack.empty()) {
|
||||||
|
std::cerr << "warning: extra Window::popScissor call" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
vec4 area = scissorStack.top();
|
||||||
|
scissorStack.pop();
|
||||||
|
glScissor(area.x, Window::height-area.y-area.w, area.z, area.w);
|
||||||
|
if (scissorStack.empty()) {
|
||||||
|
glDisable(GL_SCISSOR_TEST);
|
||||||
|
}
|
||||||
|
scissorArea = area;
|
||||||
|
}
|
||||||
|
|
||||||
void Window::terminate(){
|
void Window::terminate(){
|
||||||
Events::finalize();
|
Events::finalize();
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
@ -116,4 +166,5 @@ void Window::swapInterval(int interval){
|
|||||||
|
|
||||||
void Window::swapBuffers(){
|
void Window::swapBuffers(){
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
Window::resetScissor();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,11 +2,17 @@
|
|||||||
#define WINDOW_WINDOW_H_
|
#define WINDOW_WINDOW_H_
|
||||||
|
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
#include <stack>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
class GLFWwindow;
|
class GLFWwindow;
|
||||||
|
|
||||||
class Window {
|
class Window {
|
||||||
static GLFWwindow* window;
|
static GLFWwindow* window;
|
||||||
|
static std::stack<glm::vec4> scissorStack;
|
||||||
|
static glm::vec4 scissorArea;
|
||||||
public:
|
public:
|
||||||
static uint width;
|
static uint width;
|
||||||
static uint height;
|
static uint height;
|
||||||
@ -19,6 +25,10 @@ public:
|
|||||||
static void setShouldClose(bool flag);
|
static void setShouldClose(bool flag);
|
||||||
static void swapBuffers();
|
static void swapBuffers();
|
||||||
static void swapInterval(int interval);
|
static void swapInterval(int interval);
|
||||||
|
|
||||||
|
static void pushScissor(glm::vec4 area);
|
||||||
|
static void popScissor();
|
||||||
|
static void resetScissor();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* WINDOW_WINDOW_H_ */
|
#endif /* WINDOW_WINDOW_H_ */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user