Advertisement
Ramaraunt1

openGL window

Feb 22nd, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. //GLEW
  2. #define GLEW_STATIC
  3. #include <GL/glew.h>
  4.  
  5. //GLFW
  6. #include <GLFW/glfw3.h>
  7.  
  8. //other includes
  9. #include<iostream> //cout and cin stuff
  10.  
  11. //The main method (gets called when program runs)
  12. int main()
  13. {
  14. //initialize GLFW
  15. if (!glfwInit())
  16. {
  17. std::cout << "GLFW ERROR: GLFW failed to initialize!" << std::endl;
  18. return EXIT_FAILURE;
  19. }
  20.  
  21. //initialize GLFW options (hints)
  22. glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); //say we are using version 3.X
  23. glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // say we are using version X.3
  24. glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //say we are using the core profile (not older immediate mode/fixed function pipeline)
  25. glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); //initialize the window as non resizable.
  26.  
  27. //now that options are set up, its time to create the window
  28. GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", nullptr, nullptr);
  29. if (window == nullptr) //check if window creation was successful
  30. {
  31. std::cout << "GLFW ERROR: Failed to create GLFW window!" << std::endl;
  32. glfwTerminate(); //Don't forget to terminate GLFW!
  33. return EXIT_FAILURE;
  34. }
  35. glfwMakeContextCurrent(window); //Make the current window's context the current context of the OpenGL state machine.
  36.  
  37. //Now lets initialize GLEW
  38. glewExperimental = GL_TRUE; //First turn on experimental glew features.
  39. if (glewInit() != GLEW_OK) //Init glew and test if it works at the same time.
  40. {
  41. std::cout << "GLEW ERROR: Failed to initialize GLEW!" << std::endl;
  42. return EXIT_FAILURE;
  43. }
  44.  
  45. int width, height;// create width and height variables
  46. glfwGetFramebufferSize(window, &width, &height); //store the window's size in the width and height variables.
  47.  
  48. glViewport(0, 0, width, height); //create gl viewport
  49.  
  50. //Now the game loop!
  51. while (!glfwWindowShouldClose(window))
  52. {
  53. //check for input events every step.
  54. glfwPollEvents();
  55.  
  56. //STEP BEGIN
  57.  
  58. //STEP END
  59.  
  60. //DRAW BEGIN
  61.  
  62. //DRAW END
  63.  
  64. //swap the buffers.
  65. glfwSwapBuffers(window);
  66. }
  67.  
  68. //Shutting Down
  69. glfwTerminate(); //lets terminate GLFW
  70. return EXIT_SUCCESS;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement