Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import stdio and rendering libraries
- #include <cstdio>
- #include <GL/glew.h>
- #include <GLFW/glfw3.h>
- // callback to print errors to console
- void error_callback(int error, const char* description) {
- fprintf(stderr, "Error: %s\n", description);
- }
- // play the game
- int main(int argc, char* argv[])
- {
- // on error, print errors to console
- glfwSetErrorCallback(error_callback);
- // initialize glfw. if it fails, exit the program.
- if(!glfwInit())
- {
- return -1;
- }
- // create a 640x480 window titled "Space Invaders"
- GLFWwindow* window = glfwCreateWindow(640, 480, "Space Invaders", NULL, NULL);
- // window doesn't render => close the program
- if(!window)
- {
- glfwTerminate();
- return -1;
- }
- // bind OpenGL calls to this window (allows us to draw on this window)
- glfwMakeContextCurrent(window);
- // initialize GLEW so we can make OpenGL calls. Print an error and close the window if it fails
- GLenum err = glewInit();
- if(err != GLEW_OK)
- {
- fprintf(stderr, "Error initializing GLEW.\n");
- glfwTerminate();
- return -1;
- }
- // if we see the below log statements, we've successfully attached OpenGL to the window
- // query the openGL version
- int glVersion[2] = {-1, 1};
- glGetIntegerv(GL_MAJOR_VERSION, &glVersion[0]);
- glGetIntegerv(GL_MINOR_VERSION, &glVersion[1]);
- // on error, log filepath and line number
- gl_debug(__FILE__, __LINE__);
- // print some information about our version of OpenGL.
- printf("Using OpenGL: %d.%d\n", glVersion[0], glVersion[1]);
- printf("Renderer used: %s\n", glGetString(GL_RENDERER));
- printf("Shading Language: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment