Created
July 13, 2019 16:35
-
-
Save dorosch/29b3c3f9a7ab15317fdc3d1a4ca1c18f to your computer and use it in GitHub Desktop.
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 <stdio.h> | |
#include <stdlib.h> | |
#include <GL/glew.h> | |
#include <GLFW/glfw3.h> | |
GLFWwindow* window; | |
/* | |
$ gcc -Wall -lGL -lglfw -lGLEW opengl.c -o opengl && ./opengl | |
*/ | |
int main() { | |
if (!glfwInit()) { | |
fprintf( stderr, "Failed to initialize GLFW\n" ); | |
getchar(); | |
return -1; | |
} | |
GLFWmonitor* monitor = glfwGetPrimaryMonitor(); | |
const GLFWvidmode* mode = glfwGetVideoMode(monitor); | |
window = glfwCreateWindow(mode->width, mode->height, "My Title", monitor, NULL); | |
if( window == NULL ){ | |
fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" ); | |
getchar(); | |
glfwTerminate(); | |
return -1; | |
} | |
glfwMakeContextCurrent(window); | |
if (glewInit() != GLEW_OK) { | |
fprintf(stderr, "Failed to initialize GLEW\n"); | |
getchar(); | |
glfwTerminate(); | |
return -1; | |
} | |
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); | |
glClearColor(0.3f, 0.0f, 0.1f, 0.0f); | |
do{ | |
glClear( GL_COLOR_BUFFER_BIT ); | |
// Draw nothing | |
glfwSwapBuffers(window); | |
glfwPollEvents(); | |
} while(glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && | |
glfwWindowShouldClose(window) == 0); | |
glfwTerminate(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment