Created
April 6, 2020 06:10
-
-
Save sniperykun/2f5e1a0265caba83b03385b6b8547831 to your computer and use it in GitHub Desktop.
openglwindow
This file contains hidden or 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
// set Library Search Paths for project | |
// set Frameworks glfw glew opengl | |
// set header include serach path | |
// Signing&Capabilities Disable Library Validation | |
// #define GL_SILENCE_DEPRECATION | |
#ifdef __APPLE__ | |
#define GL_SILENCE_DEPRECATION | |
#endif | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <GLFW/glfw3.h> | |
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); | |
} | |
int mWidth = 800; | |
int mHeight = 600; | |
int main(void) | |
{ | |
printf("Hello OpenGL\n"); | |
// Load GLFW and Create a Window | |
glfwInit(); | |
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); | |
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); | |
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); | |
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); | |
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); | |
auto mWindow = glfwCreateWindow(mWidth, mHeight, "OpenGL Kun", nullptr, nullptr); | |
// Check for Valid Context | |
if (mWindow == nullptr) { | |
fprintf(stderr, "Failed to Create OpenGL Context"); | |
return EXIT_FAILURE; | |
} | |
// Create OpenGL Context | |
glfwMakeContextCurrent(mWindow); | |
// Set KeyCallBack | |
glfwSetKeyCallback(mWindow, key_callback); | |
fprintf(stderr, "OpenGL %s\n", glGetString(GL_VERSION)); | |
// Rendering Loop | |
while (glfwWindowShouldClose(mWindow) == false) | |
{ | |
// Background Fill Color | |
glClearColor(0.25f, 0.25f, 0.25f, 1.0f); | |
glClear(GL_COLOR_BUFFER_BIT); | |
// Flip Buffers and Draw | |
glfwSwapBuffers(mWindow); | |
glfwPollEvents(); | |
} | |
glfwTerminate(); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment