Advertisement
baronleonardo

OpenGL dummy window

Mar 14th, 2015
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <GL/glew.h>
  3. #include <GLFW/glfw3.h>
  4. #include <iostream>
  5. using std::cerr;
  6.  
  7. bool InitGraphics();
  8.  
  9. int main( void )
  10. {
  11.     InitGraphics();
  12.     return 0;
  13. }
  14.  
  15. /**
  16. Creates the main window and initializes OpenGL stuff.
  17. */
  18. bool InitGraphics()
  19. {
  20.     GLFWwindow* window;
  21.  
  22.     // ******************** Initialise GLFW ******************** //
  23.     if( !glfwInit() )
  24.     {
  25.         cerr << "Failed to initialize GLFW\n";
  26.         return false;
  27.     }
  28.  
  29.     glfwWindowHint(GLFW_SAMPLES, 4);
  30.     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); //OpenGL version 3.
  31.     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // 3.3
  32.     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //If requesting an OpenGL version below 3.2, GLFW_OPENGL_ANY_PROFILE
  33.  
  34.     // Open a window and create its OpenGL context
  35.     window = glfwCreateWindow( 1024, 768, "Red triangle", NULL, NULL);
  36.     if( window == NULL )
  37.     {
  38.         cerr << "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";
  39.         glfwTerminate();
  40.         return false;
  41.     }
  42.     glfwMakeContextCurrent(window);
  43.  
  44.     // ******************** Initialize GLEW ******************** //
  45.     glewExperimental = true; // Needed for core profile
  46.     if (glewInit() != GLEW_OK)
  47.     {
  48.         cerr << "Failed to initialize GLEW\n";
  49.         return false;
  50.     }
  51.  
  52.     // Ensure we can capture the escape key being pressed below
  53.     glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
  54.  
  55.  
  56.     // ******************** Initialize OpenGL ******************** //
  57.  
  58.     do{ // Loop
  59.  
  60.         // Swap buffers
  61.         glfwSwapBuffers(window); //Displaying our finished scene
  62.         glfwPollEvents(); //try to comment it
  63.  
  64.     } // Check if the ESC key was pressed or the window was closed
  65.     while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
  66.            glfwWindowShouldClose(window) == 0 );
  67.  
  68.     // Close OpenGL window and terminate GLFW
  69.     glfwTerminate();
  70.     return true;
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement