Created
May 7, 2021 18:13
-
-
Save CaptainHandyman/782452b6fdd0bf098d1f4124c290256e to your computer and use it in GitHub Desktop.
OpenGL window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <GL/glew.h> | |
#include <GLFW/glfw3.h> | |
#include <glm/glm.hpp> | |
#include <iostream> | |
using namespace std; | |
GLFWwindow* window = NULL; | |
GLFWmonitor* monitor = NULL; | |
void setWindowFillColor(const uint16_t& r, const uint16_t& g, | |
const uint16_t& b) { | |
glClearColor(static_cast<float>(r > 0 ? r / 255 : 0), | |
static_cast<float>(g > 0 ? g / 255 : 0), | |
static_cast<float>(b > 0 ? b / 255 : 0), 1); | |
} | |
int main() { | |
glewExperimental = true; | |
glfwInit(); | |
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); | |
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); | |
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); | |
monitor = glfwGetPrimaryMonitor(); | |
const GLFWvidmode* mode = glfwGetVideoMode(monitor); | |
window = glfwCreateWindow(800, 800, "OpenGL", NULL, NULL); | |
glfwSetWindowPos(window, mode->width / 2 - 400, mode->height / 2 - 400); | |
glfwMakeContextCurrent(window); | |
glewInit(); | |
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); | |
do { | |
setWindowFillColor(255, 0, 0); | |
glClear(GL_COLOR_BUFFER_BIT); | |
glfwSwapBuffers(window); | |
glfwPollEvents(); | |
} while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS | |
&& !glfwWindowShouldClose(window)); | |
glfwTerminate(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment