Advertisement
Guest User

Untitled

a guest
Sep 30th, 2020
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <GLFW/glfw3.h>
  3.  
  4. // Function prototypes
  5. void Init();
  6. void Terminate();
  7.  
  8. /// <summary>
  9. /// A simple class to mimic was Vixnil described
  10. /// </summary>
  11. class CustomWindowObject
  12. {
  13. public:
  14.     // Constructor
  15.     CustomWindowObject()
  16.     {
  17.         m_window = glfwCreateWindow(500, 500, "Vixnil Test", nullptr, nullptr);
  18.     }
  19.  
  20.     // Destructor
  21.     ~CustomWindowObject()
  22.     {
  23.         if (m_window)
  24.         {
  25.             glfwDestroyWindow(m_window);
  26.             m_window = nullptr;
  27.         }
  28.     }
  29.  
  30.     // Public property
  31.     GLFWwindow* m_window;
  32. };
  33.  
  34. /// <summary>
  35. /// Main entry point
  36. /// </summary>
  37. int main(int argc, const char** argv)
  38. {
  39.     // Attempt to initialize GLFW
  40.     Init();
  41.  
  42.     // Set some window hints
  43.     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
  44.     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
  45.     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  46. #ifdef __APPLE__
  47.     glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
  48. #endif // __APPLE__
  49.  
  50.     // Create the window
  51.     auto myWindow = new CustomWindowObject();
  52.  
  53.     // Begin the draw loop
  54.     while (!glfwWindowShouldClose(myWindow->m_window))
  55.     {
  56.         glfwSwapBuffers(myWindow->m_window);
  57.         glfwPollEvents();
  58.     }
  59.  
  60.     // Delete the custom window object
  61.     delete myWindow;
  62.     myWindow = nullptr;
  63.  
  64.     // Terminate the app
  65.     Terminate();
  66.  
  67.     // Satisfy the main function
  68.     return 0;
  69. }
  70.  
  71. /// <summary>
  72. /// Attempt to initialize the app
  73. /// </summary>
  74. void Init()
  75. {
  76.     if (!glfwInit())
  77.     {
  78.         exit(EXIT_FAILURE);
  79.     }
  80. }
  81.  
  82. /// <summary>
  83. /// Terminates the app
  84. /// </summary>
  85. void Terminate()
  86. {
  87.     glfwTerminate();
  88. }
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement