Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef WINDOW_H
- #define WINDOW_H
- #include <GLFW/glfw3.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include "colors.h"
- // DECLARE
- static void error_callback(int error, const char* description){ fputs(description, stderr); }
- static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods){ if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) { glfwSetWindowShouldClose(window, GL_TRUE); } }
- // Window info
- static int WindowWidth = 1000, WindowHeight = 1000;
- GLFWwindow* window; // declare the window
- // INIT
- static int InitGLFW(){
- if (!glfwInit()) { return -1; }
- return 1;
- }
- // Window Settings, such as resizable... and so on...
- class WindowSettings{
- public:
- int width;
- int height;
- bool resizable;
- bool focused;
- bool floating;
- bool bordered;
- bool hidden;
- char* title;
- rgbaColor backgroundColor;
- WindowSettings(char* engrave, int WindowWidth = 512, int WindowHeight = 512, rgbaColor BGC = COLOR_BLACK){
- title = engrave;
- width = WindowWidth;
- height = WindowHeight;
- resizable = true;
- focused = true;
- floating = false;
- bordered = true;
- hidden = false;
- backgroundColor = BGC;
- }
- };
- static int InitWindow(WindowSettings Ws) {
- // Setup window
- WindowWidth = Ws.width; WindowHeight = Ws.height;
- // Set all hints
- if(Ws.resizable){ glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); } else { glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); }
- if(Ws.focused){ glfwWindowHint( GLFW_FOCUSED, GL_TRUE); } else { glfwWindowHint(GLFW_FOCUSED, GL_FALSE); }
- if(Ws.floating){ glfwWindowHint( GLFW_FLOATING, GL_TRUE); } else { glfwWindowHint(GLFW_FLOATING, GL_FALSE); }
- if(Ws.bordered){ glfwWindowHint( GLFW_DECORATED, GL_TRUE); } else { glfwWindowHint(GLFW_DECORATED, GL_FALSE); }
- if(!Ws.hidden){ glfwWindowHint( GLFW_VISIBLE, GL_TRUE); } else { glfwWindowHint(GLFW_VISIBLE, GL_FALSE); }
- window = glfwCreateWindow(WindowWidth, WindowHeight, Ws.title, NULL, NULL);
- if (!window){ glfwTerminate(); exit(EXIT_FAILURE); }
- // Setup callback
- glfwSetErrorCallback(error_callback);
- glfwSetKeyCallback(window, key_callback);
- // Add the window to the context
- glfwMakeContextCurrent(window);
- // Add the clear color
- glClearColor(Ws.backgroundColor.GetR(), Ws.backgroundColor.GetG(), Ws.backgroundColor.GetB(), Ws.backgroundColor.GetA());
- return 1;
- }
- static void TerminateWindow() { glfwDestroyWindow(window); }
- static void TerminateGLFW() { glfwTerminate(); exit(EXIT_SUCCESS); }
- static void CoordinateWindow(){
- glfwGetFramebufferSize(window, &WindowWidth, &WindowHeight);
- glViewport(0, 0, WindowWidth, WindowHeight);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, WindowWidth, WindowHeight, 0, -1, 1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
- static void UpdateWindow(){
- glfwSwapBuffers(window);
- glfwPollEvents();
- }
- static void ClearWindow(){
- glClear(GL_COLOR_BUFFER_BIT);
- }
- static void ClearColor(rgbaColor color){
- glClearColor(color.GetR(), color.GetG(), color.GetB(), color.GetA());
- ClearWindow();
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement