minor refactor

This commit is contained in:
MihailRis 2024-03-29 12:24:02 +03:00
parent 3b3c5f081c
commit a4960097f0
5 changed files with 386 additions and 390 deletions

View File

@ -3,69 +3,65 @@
#include <glm/ext.hpp>
using glm::vec3;
using glm::vec4;
using glm::mat4;
Camera::Camera(vec3 position, float fov) : fov(fov), position(position), zoom(1.0f), rotation(1.0f) {
updateVectors();
Camera::Camera(glm::vec3 position, float fov) : fov(fov), position(position), zoom(1.0f), rotation(1.0f) {
updateVectors();
}
void Camera::updateVectors(){
front = vec3(rotation * vec4(0,0,-1,1));
right = vec3(rotation * vec4(1,0,0,1));
up = vec3(rotation * vec4(0,1,0,1));
dir = vec3(rotation * vec4(0,0,-1,1));
dir.y = 0;
float len = length(dir);
if (len > 0.0f){
dir.x /= len;
dir.z /= len;
}
front = glm::vec3(rotation * glm::vec4(0,0,-1,1));
right = glm::vec3(rotation * glm::vec4(1,0,0,1));
up = glm::vec3(rotation * glm::vec4(0,1,0,1));
dir = glm::vec3(rotation * glm::vec4(0,0,-1,1));
dir.y = 0;
float len = glm::length(dir);
if (len > 0.0f){
dir.x /= len;
dir.z /= len;
}
}
void Camera::rotate(float x, float y, float z){
rotation = glm::rotate(rotation, z, vec3(0,0,1));
rotation = glm::rotate(rotation, y, vec3(0,1,0));
rotation = glm::rotate(rotation, x, vec3(1,0,0));
rotation = glm::rotate(rotation, z, glm::vec3(0,0,1));
rotation = glm::rotate(rotation, y, glm::vec3(0,1,0));
rotation = glm::rotate(rotation, x, glm::vec3(1,0,0));
updateVectors();
updateVectors();
}
mat4 Camera::getProjection(){
float aspect = this->aspect;
if (aspect == 0.0f){
aspect = (float)Window::width / (float)Window::height;
}
if (perspective)
return glm::perspective(fov*zoom, aspect, 0.05f, 1500.0f);
else
if (flipped)
return glm::ortho(0.0f, fov*aspect, fov, 0.0f);
else
return glm::ortho(0.0f, fov*aspect, 0.0f, fov);
glm::mat4 Camera::getProjection(){
float aspect = this->aspect;
if (aspect == 0.0f){
aspect = (float)Window::width / (float)Window::height;
}
if (perspective)
return glm::perspective(fov*zoom, aspect, 0.05f, 1500.0f);
else
if (flipped)
return glm::ortho(0.0f, fov*aspect, fov, 0.0f);
else
return glm::ortho(0.0f, fov*aspect, 0.0f, fov);
}
mat4 Camera::getView(bool pos){
vec3 position = this->position;
if (!pos) {
position = vec3(0.0f);
}
if (perspective) {
return glm::lookAt(position, position+front, up);
} else {
return glm::translate(glm::mat4(1.0f), position);
}
glm::mat4 Camera::getView(bool pos){
glm::vec3 position = this->position;
if (!pos) {
position = glm::vec3(0.0f);
}
if (perspective) {
return glm::lookAt(position, position+front, up);
} else {
return glm::translate(glm::mat4(1.0f), position);
}
}
mat4 Camera::getProjView(bool pos){
return getProjection()*getView(pos);
glm::mat4 Camera::getProjView(bool pos){
return getProjection()*getView(pos);
}
void Camera::setFov(float fov) {
this->fov = fov;
this->fov = fov;
}
float Camera::getFov() const {
return fov;
return fov;
}

View File

@ -4,31 +4,31 @@
#include <glm/glm.hpp>
class Camera {
void updateVectors();
float fov;
void updateVectors();
float fov;
public:
glm::vec3 front;
glm::vec3 up;
glm::vec3 right;
glm::vec3 dir;
glm::vec3 front;
glm::vec3 up;
glm::vec3 right;
glm::vec3 dir;
glm::vec3 position;
glm::vec3 position;
float zoom;
glm::mat4 rotation;
bool perspective = true;
bool flipped = false;
float aspect = 0.0f;
Camera(glm::vec3 position, float fov);
float zoom;
glm::mat4 rotation;
bool perspective = true;
bool flipped = false;
float aspect = 0.0f;
Camera(glm::vec3 position, float fov);
void rotate(float x, float y, float z);
void rotate(float x, float y, float z);
glm::mat4 getProjection();
glm::mat4 getView(bool position=true);
glm::mat4 getProjView(bool position=true);
glm::mat4 getProjection();
glm::mat4 getView(bool position=true);
glm::mat4 getProjView(bool position=true);
void setFov(float fov);
float getFov() const;
void setFov(float fov);
float getFov() const;
};
#endif /* WINDOW_CAMERA_H_ */

View File

@ -24,25 +24,25 @@ void mouse_button_callback(GLFWwindow*, int button, int action, int) {
}
void key_callback(GLFWwindow*, int key, int scancode, int action, int /*mode*/) {
if (key == GLFW_KEY_UNKNOWN) return;
if (action == GLFW_PRESS) {
if (key == GLFW_KEY_UNKNOWN) return;
if (action == GLFW_PRESS) {
Events::setKey(key, true);
Events::pressedKeys.push_back(static_cast<keycode>(key));
}
else if (action == GLFW_RELEASE) {
Events::pressedKeys.push_back(static_cast<keycode>(key));
}
else if (action == GLFW_RELEASE) {
Events::setKey(key, false);
}
else if (action == GLFW_REPEAT) {
Events::pressedKeys.push_back(static_cast<keycode>(key));
}
}
else if (action == GLFW_REPEAT) {
Events::pressedKeys.push_back(static_cast<keycode>(key));
}
}
void scroll_callback(GLFWwindow*, double xoffset, double yoffset) {
Events::scroll += yoffset;
Events::scroll += yoffset;
}
bool Window::isMaximized() {
return glfwGetWindowAttrib(window, GLFW_MAXIMIZED);
return glfwGetWindowAttrib(window, GLFW_MAXIMIZED);
}
bool Window::isIconified() {
@ -51,67 +51,67 @@ bool Window::isIconified() {
bool Window::isFocused()
{
return glfwGetWindowAttrib(window, GLFW_FOCUSED);
return glfwGetWindowAttrib(window, GLFW_FOCUSED);
}
void window_size_callback(GLFWwindow*, int width, int height) {
if (width && height) {
if (Window::isFocused()) {
glViewport(0, 0, width, height);
Window::width = width;
Window::height = height;
}
if (width && height) {
if (Window::isFocused()) {
glViewport(0, 0, width, height);
Window::width = width;
Window::height = height;
}
if (!Window::isFullscreen() && !Window::isMaximized()) {
Window::getSettings()->width = width;
Window::getSettings()->height = height;
}
}
Window::resetScissor();
if (!Window::isFullscreen() && !Window::isMaximized()) {
Window::getSettings()->width = width;
Window::getSettings()->height = height;
}
}
Window::resetScissor();
}
void character_callback(GLFWwindow* window, unsigned int codepoint){
Events::codepoints.push_back(codepoint);
Events::codepoints.push_back(codepoint);
}
const char* glfwErrorName(int error) {
switch (error) {
case GLFW_NO_ERROR: return "no error";
case GLFW_NOT_INITIALIZED: return "not initialized";
case GLFW_NO_CURRENT_CONTEXT: return "no current context";
case GLFW_INVALID_ENUM: return "invalid enum";
case GLFW_INVALID_VALUE: return "invalid value";
case GLFW_OUT_OF_MEMORY: return "out of memory";
case GLFW_API_UNAVAILABLE: return "api unavailable";
case GLFW_VERSION_UNAVAILABLE: return "version unavailable";
case GLFW_PLATFORM_ERROR: return "platform error";
case GLFW_FORMAT_UNAVAILABLE: return "format unavailable";
case GLFW_NO_WINDOW_CONTEXT: return "no window context";
default: return "unknown error";
}
switch (error) {
case GLFW_NO_ERROR: return "no error";
case GLFW_NOT_INITIALIZED: return "not initialized";
case GLFW_NO_CURRENT_CONTEXT: return "no current context";
case GLFW_INVALID_ENUM: return "invalid enum";
case GLFW_INVALID_VALUE: return "invalid value";
case GLFW_OUT_OF_MEMORY: return "out of memory";
case GLFW_API_UNAVAILABLE: return "api unavailable";
case GLFW_VERSION_UNAVAILABLE: return "version unavailable";
case GLFW_PLATFORM_ERROR: return "platform error";
case GLFW_FORMAT_UNAVAILABLE: return "format unavailable";
case GLFW_NO_WINDOW_CONTEXT: return "no window context";
default: return "unknown error";
}
}
void error_callback(int error, const char* description) {
std::cerr << "GLFW error [0x" << std::hex << error << "]: ";
std::cerr << glfwErrorName(error) << std::endl;
if (description) {
std::cerr << description << std::endl;
}
std::cerr << "GLFW error [0x" << std::hex << error << "]: ";
std::cerr << glfwErrorName(error) << std::endl;
if (description) {
std::cerr << description << std::endl;
}
}
int Window::initialize(DisplaySettings& settings){
Window::settings = &settings;
Window::width = settings.width;
Window::height = settings.height;
Window::settings = &settings;
Window::width = settings.width;
Window::height = settings.height;
glfwSetErrorCallback(error_callback);
if (glfwInit() == GLFW_FALSE) {
std::cerr << "Failed to initialize GLFW" << std::endl;
return -1;
}
glfwSetErrorCallback(error_callback);
if (glfwInit() == GLFW_FALSE) {
std::cerr << "Failed to initialize GLFW" << std::endl;
return -1;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
@ -119,48 +119,48 @@ int Window::initialize(DisplaySettings& settings){
#else
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
#endif
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
glfwWindowHint(GLFW_SAMPLES, settings.samples);
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
glfwWindowHint(GLFW_SAMPLES, settings.samples);
window = glfwCreateWindow(width, height, settings.title.c_str(), nullptr, nullptr);
if (window == nullptr){
std::cerr << "Failed to create GLFW Window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
window = glfwCreateWindow(width, height, settings.title.c_str(), nullptr, nullptr);
if (window == nullptr){
std::cerr << "Failed to create GLFW Window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental = GL_TRUE;
GLenum glewErr = glewInit();
if (glewErr != GLEW_OK){
std::cerr << "Failed to initialize GLEW: " << std::endl;
std::cerr << glewGetErrorString(glewErr) << std::endl;
return -1;
}
glewExperimental = GL_TRUE;
GLenum glewErr = glewInit();
if (glewErr != GLEW_OK){
std::cerr << "Failed to initialize GLEW: " << std::endl;
std::cerr << glewGetErrorString(glewErr) << std::endl;
return -1;
}
glViewport(0,0, width, height);
glClearColor(0.0f,0.0f,0.0f, 1);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glViewport(0,0, width, height);
glClearColor(0.0f,0.0f,0.0f, 1);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glfwSetKeyCallback(window, key_callback);
glfwSetMouseButtonCallback(window, mouse_button_callback);
glfwSetCursorPosCallback(window, cursor_position_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetCharCallback(window, character_callback);
glfwSetScrollCallback(window, scroll_callback);
if (settings.fullscreen) {
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, GLFW_DONT_CARE);
}
glfwSwapInterval(settings.swapInterval);
const GLubyte* vendor = glGetString(GL_VENDOR);
const GLubyte* renderer = glGetString(GL_RENDERER);
std::cout << "GL Vendor: " << (char*)vendor << std::endl;
std::cout << "GL Renderer: " << (char*)renderer << std::endl;
glfwSetKeyCallback(window, key_callback);
glfwSetMouseButtonCallback(window, mouse_button_callback);
glfwSetCursorPosCallback(window, cursor_position_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetCharCallback(window, character_callback);
glfwSetScrollCallback(window, scroll_callback);
if (settings.fullscreen) {
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, GLFW_DONT_CARE);
}
glfwSwapInterval(settings.swapInterval);
const GLubyte* vendor = glGetString(GL_VENDOR);
const GLubyte* renderer = glGetString(GL_RENDERER);
std::cout << "GL Vendor: " << (char*)vendor << std::endl;
std::cout << "GL Renderer: " << (char*)renderer << std::endl;
std::cout << "GLFW: " << glfwGetVersionString() << std::endl;
return 0;
return 0;
}
void Window::setBlendMode(blendmode mode) {
@ -178,140 +178,140 @@ void Window::setBlendMode(blendmode mode) {
}
void Window::clear() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void Window::clearDepth() {
glClear(GL_DEPTH_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
}
void Window::setBgColor(glm::vec3 color) {
glClearColor(color.r, color.g, color.b, 1.0f);
glClearColor(color.r, color.g, color.b, 1.0f);
}
void Window::setBgColor(glm::vec4 color) {
glClearColor(color.r, color.g, color.b, color.a);
glClearColor(color.r, color.g, color.b, color.a);
}
void Window::viewport(int x, int y, int width, int height){
glViewport(x, y, width, height);
glViewport(x, y, width, height);
}
void Window::setCursorMode(int mode){
glfwSetInputMode(window, GLFW_CURSOR, mode);
glfwSetInputMode(window, GLFW_CURSOR, mode);
}
void Window::resetScissor() {
scissorArea = glm::vec4(0.0f, 0.0f, width, height);
scissorStack = std::stack<glm::vec4>();
glDisable(GL_SCISSOR_TEST);
scissorArea = glm::vec4(0.0f, 0.0f, width, height);
scissorStack = std::stack<glm::vec4>();
glDisable(GL_SCISSOR_TEST);
}
void Window::pushScissor(glm::vec4 area) {
if (scissorStack.empty()) {
glEnable(GL_SCISSOR_TEST);
}
scissorStack.push(scissorArea);
if (scissorStack.empty()) {
glEnable(GL_SCISSOR_TEST);
}
scissorStack.push(scissorArea);
area.z += area.x;
area.w += area.y;
area.z += area.x;
area.w += area.y;
area.x = fmax(area.x, scissorArea.x);
area.y = fmax(area.y, scissorArea.y);
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);
area.z = fmin(area.z, scissorArea.z);
area.w = fmin(area.w, scissorArea.w);
if (area.z < 0.0f || area.w < 0.0f) {
glScissor(0, 0, 0, 0);
} else {
glScissor(area.x, Window::height-area.w,
std::max(0, int(area.z-area.x)),
std::max(0, int(area.w-area.y)));
}
scissorArea = area;
if (area.z < 0.0f || area.w < 0.0f) {
glScissor(0, 0, 0, 0);
} else {
glScissor(area.x, Window::height-area.w,
std::max(0, int(area.z-area.x)),
std::max(0, int(area.w-area.y)));
}
scissorArea = area;
}
void Window::popScissor() {
if (scissorStack.empty()) {
std::cerr << "warning: extra Window::popScissor call" << std::endl;
return;
}
glm::vec4 area = scissorStack.top();
scissorStack.pop();
if (area.z < 0.0f || area.w < 0.0f) {
glScissor(0, 0, 0, 0);
} else {
glScissor(area.x, Window::height-area.w,
std::max(0, int(area.z-area.x)),
std::max(0, int(area.w-area.y)));
}
if (scissorStack.empty()) {
glDisable(GL_SCISSOR_TEST);
}
scissorArea = area;
if (scissorStack.empty()) {
std::cerr << "warning: extra Window::popScissor call" << std::endl;
return;
}
glm::vec4 area = scissorStack.top();
scissorStack.pop();
if (area.z < 0.0f || area.w < 0.0f) {
glScissor(0, 0, 0, 0);
} else {
glScissor(area.x, Window::height-area.w,
std::max(0, int(area.z-area.x)),
std::max(0, int(area.w-area.y)));
}
if (scissorStack.empty()) {
glDisable(GL_SCISSOR_TEST);
}
scissorArea = area;
}
void Window::terminate(){
glfwTerminate();
glfwTerminate();
}
bool Window::isShouldClose(){
return glfwWindowShouldClose(window);
return glfwWindowShouldClose(window);
}
void Window::setShouldClose(bool flag){
glfwSetWindowShouldClose(window, flag);
glfwSetWindowShouldClose(window, flag);
}
void Window::swapInterval(int interval){
glfwSwapInterval(interval);
glfwSwapInterval(interval);
}
void Window::toggleFullscreen(){
settings->fullscreen = !settings->fullscreen;
settings->fullscreen = !settings->fullscreen;
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
if (Events::_cursor_locked) Events::toggleCursor();
if (Events::_cursor_locked) Events::toggleCursor();
if (settings->fullscreen) {
glfwGetWindowPos(window, &posX, &posY);
glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, GLFW_DONT_CARE);
}
else {
glfwSetWindowMonitor(window, nullptr, posX, posY, settings->width, settings->height, GLFW_DONT_CARE);
glfwSetWindowAttrib(window, GLFW_MAXIMIZED, GLFW_FALSE);
}
if (settings->fullscreen) {
glfwGetWindowPos(window, &posX, &posY);
glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, GLFW_DONT_CARE);
}
else {
glfwSetWindowMonitor(window, nullptr, posX, posY, settings->width, settings->height, GLFW_DONT_CARE);
glfwSetWindowAttrib(window, GLFW_MAXIMIZED, GLFW_FALSE);
}
double xPos, yPos;
glfwGetCursorPos(window, &xPos, &yPos);
double xPos, yPos;
glfwGetCursorPos(window, &xPos, &yPos);
Events::setPosition(xPos, yPos);
}
bool Window::isFullscreen() {
return settings->fullscreen;
return settings->fullscreen;
}
void Window::swapBuffers(){
glfwSwapBuffers(window);
Window::resetScissor();
glfwSwapBuffers(window);
Window::resetScissor();
}
double Window::time() {
return glfwGetTime();
return glfwGetTime();
}
DisplaySettings* Window::getSettings() {
return settings;
return settings;
}
ImageData* Window::takeScreenshot() {
ubyte* data = new ubyte[width * height * 3];
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);
return new ImageData(ImageFormat::rgb888, width, height, data);
ubyte* data = new ubyte[width * height * 3];
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);
return new ImageData(ImageFormat::rgb888, width, height, data);
}
const char* Window::getClipboardText() {
@ -323,19 +323,19 @@ void Window::setClipboardText(const char* text) {
}
bool Window::tryToMaximize(GLFWwindow* window, GLFWmonitor* monitor) {
glm::ivec4 windowFrame(0);
glm::ivec4 workArea(0);
glfwGetWindowFrameSize(window, &windowFrame.x, &windowFrame.y, &windowFrame.z, &windowFrame.w);
glfwGetMonitorWorkarea(monitor, &workArea.x, &workArea.y, &workArea.z, &workArea.w);
if (Window::width > (uint)workArea.z) Window::width = (uint)workArea.z;
if (Window::height > (uint)workArea.w) Window::height = (uint)workArea.w;
if (Window::width >= (uint)(workArea.z - (windowFrame.x + windowFrame.z)) &&
Window::height >= (uint)(workArea.w - (windowFrame.y + windowFrame.w))) {
glfwMaximizeWindow(window);
return true;
}
glfwSetWindowSize(window, Window::width, Window::height);
glfwSetWindowPos(window, workArea.x + (workArea.z - Window::width) / 2,
workArea.y + (workArea.w - Window::height) / 2 + windowFrame.y / 2);
return false;
glm::ivec4 windowFrame(0);
glm::ivec4 workArea(0);
glfwGetWindowFrameSize(window, &windowFrame.x, &windowFrame.y, &windowFrame.z, &windowFrame.w);
glfwGetMonitorWorkarea(monitor, &workArea.x, &workArea.y, &workArea.z, &workArea.w);
if (Window::width > (uint)workArea.z) Window::width = (uint)workArea.z;
if (Window::height > (uint)workArea.w) Window::height = (uint)workArea.w;
if (Window::width >= (uint)(workArea.z - (windowFrame.x + windowFrame.z)) &&
Window::height >= (uint)(workArea.w - (windowFrame.y + windowFrame.w))) {
glfwMaximizeWindow(window);
return true;
}
glfwSetWindowSize(window, Window::width, Window::height);
glfwSetWindowPos(window, workArea.x + (workArea.z - Window::width) / 2,
workArea.y + (workArea.w - Window::height) / 2 + windowFrame.y / 2);
return false;
}

View File

@ -19,52 +19,52 @@ enum class blendmode {
};
class Window {
static GLFWwindow* window;
static DisplaySettings* settings;
static std::stack<glm::vec4> scissorStack;
static glm::vec4 scissorArea;
static GLFWwindow* window;
static DisplaySettings* settings;
static std::stack<glm::vec4> scissorStack;
static glm::vec4 scissorArea;
static bool tryToMaximize(GLFWwindow* window, GLFWmonitor* monitor);
static bool tryToMaximize(GLFWwindow* window, GLFWmonitor* monitor);
public:
static int posX;
static int posY;
static uint width;
static uint height;
static int initialize(DisplaySettings& settings);
static void terminate();
static int posX;
static int posY;
static uint width;
static uint height;
static int initialize(DisplaySettings& settings);
static void terminate();
static void viewport(int x, int y, int width, int height);
static void setCursorMode(int mode);
static bool isShouldClose();
static void setShouldClose(bool flag);
static void swapBuffers();
static void swapInterval(int interval);
static void toggleFullscreen();
static bool isFullscreen();
static bool isMaximized();
static bool isFocused();
static void viewport(int x, int y, int width, int height);
static void setCursorMode(int mode);
static bool isShouldClose();
static void setShouldClose(bool flag);
static void swapBuffers();
static void swapInterval(int interval);
static void toggleFullscreen();
static bool isFullscreen();
static bool isMaximized();
static bool isFocused();
static bool isIconified();
static void pushScissor(glm::vec4 area);
static void popScissor();
static void resetScissor();
static void pushScissor(glm::vec4 area);
static void popScissor();
static void resetScissor();
static void clear();
static void clearDepth();
static void setBgColor(glm::vec3 color);
static void clear();
static void clearDepth();
static void setBgColor(glm::vec3 color);
static void setBgColor(glm::vec4 color);
static double time();
static double time();
static const char* getClipboardText();
static void setClipboardText(const char* text);
static DisplaySettings* getSettings();
static DisplaySettings* getSettings();
static void setBlendMode(blendmode mode);
static glm::vec2 size() {
return glm::vec2(width, height);
}
static glm::vec2 size() {
return glm::vec2(width, height);
}
static ImageData* takeScreenshot();
static ImageData* takeScreenshot();
};
#endif /* WINDOW_WINDOW_H_ */

View File

@ -5,84 +5,84 @@
/// @brief Represents glfw3 keycode values.
enum class keycode : int {
ENTER = 257,
TAB = 258,
SPACE = 32,
BACKSPACE = 259,
LEFT_SHIFT = 340,
LEFT_CONTROL = 341,
LEFT_ALT = 342,
RIGHT_SHIFT = 344,
RIGHT_CONTROL = 345,
RIGHT_ALT = 346,
ESCAPE = 256,
CAPS_LOCK = 280,
LEFT = 263,
RIGHT = 262,
DOWN = 264,
UP = 265,
F1 = 290,
F2 = 291,
F3 = 292,
F4 = 293,
F5 = 294,
F6 = 295,
F7 = 296,
F8 = 297,
F9 = 298,
F10 = 299,
F11 = 300,
F12 = 301,
A = 65,
B = 66,
C = 67,
D = 68,
E = 69,
F = 70,
G = 71,
H = 72,
I = 73,
J = 74,
K = 75,
L = 76,
M = 77,
N = 78,
O = 79,
P = 80,
Q = 81,
R = 82,
S = 83,
T = 84,
U = 85,
V = 86,
W = 87,
X = 88,
Y = 89,
Z = 90,
NUM_0 = 48,
NUM_1 = 49,
NUM_2 = 50,
NUM_3 = 51,
NUM_4 = 52,
NUM_5 = 53,
NUM_6 = 54,
NUM_7 = 55,
NUM_8 = 56,
NUM_9 = 57,
MENU = 348,
PAUSE = 284,
INSERT = 260,
LEFT_SUPER = 343,
RIGHT_SUPER = 347,
DELETE = 261,
PAGE_UP = 266,
PAGE_DOWN = 267,
HOME = 268,
END = 269,
PRINT_SCREEN = 283,
NUM_LOCK = 282,
LEFT_BRACKET = 91,
RIGHT_BRACKET = 93,
ENTER = 257,
TAB = 258,
SPACE = 32,
BACKSPACE = 259,
LEFT_SHIFT = 340,
LEFT_CONTROL = 341,
LEFT_ALT = 342,
RIGHT_SHIFT = 344,
RIGHT_CONTROL = 345,
RIGHT_ALT = 346,
ESCAPE = 256,
CAPS_LOCK = 280,
LEFT = 263,
RIGHT = 262,
DOWN = 264,
UP = 265,
F1 = 290,
F2 = 291,
F3 = 292,
F4 = 293,
F5 = 294,
F6 = 295,
F7 = 296,
F8 = 297,
F9 = 298,
F10 = 299,
F11 = 300,
F12 = 301,
A = 65,
B = 66,
C = 67,
D = 68,
E = 69,
F = 70,
G = 71,
H = 72,
I = 73,
J = 74,
K = 75,
L = 76,
M = 77,
N = 78,
O = 79,
P = 80,
Q = 81,
R = 82,
S = 83,
T = 84,
U = 85,
V = 86,
W = 87,
X = 88,
Y = 89,
Z = 90,
NUM_0 = 48,
NUM_1 = 49,
NUM_2 = 50,
NUM_3 = 51,
NUM_4 = 52,
NUM_5 = 53,
NUM_6 = 54,
NUM_7 = 55,
NUM_8 = 56,
NUM_9 = 57,
MENU = 348,
PAUSE = 284,
INSERT = 260,
LEFT_SUPER = 343,
RIGHT_SUPER = 347,
DELETE = 261,
PAGE_UP = 266,
PAGE_DOWN = 267,
HOME = 268,
END = 269,
PRINT_SCREEN = 283,
NUM_LOCK = 282,
LEFT_BRACKET = 91,
RIGHT_BRACKET = 93,
};
@ -90,58 +90,58 @@ enum class keycode : int {
/// @brief Represents glfw3 mouse button IDs.
/// @details There is a subset of glfw3 mouse button IDs.
enum class mousecode : int {
BUTTON_1 = 0, // Left mouse button
BUTTON_2 = 1, // Right mouse button
BUTTON_3 = 2, // Middle mouse button
BUTTON_1 = 0, // Left mouse button
BUTTON_2 = 1, // Right mouse button
BUTTON_3 = 2, // Middle mouse button
};
inline mousecode MOUSECODES_ALL[] {
mousecode::BUTTON_1,
mousecode::BUTTON_2,
mousecode::BUTTON_3
mousecode::BUTTON_1,
mousecode::BUTTON_2,
mousecode::BUTTON_3
};
namespace input_util {
/// @return Key label by keycode
std::string to_string(keycode code);
/// @return Mouse button label by keycode
std::string to_string(mousecode code);
/// @return Key label by keycode
std::string to_string(keycode code);
/// @return Mouse button label by keycode
std::string to_string(mousecode code);
}
enum class inputtype {
keyboard,
mouse,
keyboard,
mouse,
};
struct Binding {
inputtype type;
int code;
bool state = false;
bool justChange = false;
inputtype type;
int code;
bool state = false;
bool justChange = false;
bool active() const {
return state;
}
bool active() const {
return state;
}
bool jactive() const {
return state && justChange;
}
void reset(inputtype, int);
void reset(keycode);
void reset(mousecode);
bool jactive() const {
return state && justChange;
}
void reset(inputtype, int);
void reset(keycode);
void reset(mousecode);
inline const std::string text() const {
switch (type) {
case inputtype::keyboard: {
return input_util::to_string(static_cast<keycode>(code));
}
case inputtype::mouse: {
return input_util::to_string(static_cast<mousecode>(code));
}
}
return "<unknown input type>";
}
inline const std::string text() const {
switch (type) {
case inputtype::keyboard: {
return input_util::to_string(static_cast<keycode>(code));
}
case inputtype::mouse: {
return input_util::to_string(static_cast<mousecode>(code));
}
}
return "<unknown input type>";
}
};