Advertisement
Guest User

TC32

a guest
Jun 17th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. MAIN.CPP
  2.  
  3. #include "System.h"
  4.  
  5. int main()
  6. {
  7. System::Initialize();
  8.  
  9.  
  10.  
  11. System::Shutdown();
  12. return 0;
  13. }
  14.  
  15.  
  16. SYSTEM.H
  17.  
  18. #define GLEW_STATIC
  19. #include <GL\glew.h>
  20. #include <GLFW\glfw3.h>
  21. #include <iostream>
  22.  
  23. GLFWwindow* window;
  24.  
  25. namespace System
  26. {
  27. //Objects and variables
  28. GLFWwindow* window;
  29.  
  30. //Function prototypes
  31. bool Initialize();
  32. void Shutdown();
  33. }
  34.  
  35.  
  36. SYSTEM.CPP
  37.  
  38. #include "System.h"
  39. #include "Settings.h"
  40.  
  41. using namespace System;
  42.  
  43. bool System::Initialize()
  44. {
  45. std::cout << "Initializing GLFW: OpenGL version 3.3 \n";
  46.  
  47. //Initialize GLFW
  48. glfwInit();
  49. //Set window properties (version 3.3, core profile, not resizeable)
  50. glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  51. glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  52. glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  53. glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
  54.  
  55. //Create Window
  56. window = glfwCreateWindow(Settings::defaultScreenWidth, Settings::defaultScreenHeight, "Learn OpenGL", nullptr, nullptr);
  57. if (window = nullptr)
  58. {
  59. std::cout << "Failed to create GLFW window \n";
  60. glfwTerminate();
  61. return false;
  62. }
  63.  
  64. //Make the context current
  65. glfwMakeContextCurrent(window);
  66.  
  67. //Initialize GLEW
  68. glewExperimental = GL_TRUE;
  69. std::cout << "Initializing GLEW: Experimental = " << glewExperimental << "\n";
  70.  
  71. if (glewInit() != GLEW_OK)
  72. {
  73. std::cout << "Falied to initialize GLEW \n";
  74. return false;
  75. }
  76.  
  77. //Set up viewport
  78. glfwGetFramebufferSize(window, &Settings::defaultScreenWidth, &Settings::defaultScreenHeight);
  79. glViewport(0, 0, Settings::screenWidth, Settings::screenHeight);
  80.  
  81.  
  82. return true;
  83. }
  84.  
  85. void System::Shutdown()
  86. {
  87. glfwTerminate();
  88. }
  89.  
  90.  
  91. SETTINGS.H
  92.  
  93. namespace Settings
  94. {
  95. //Variables
  96. int defaultScreenWidth = 100;
  97. int defaultScreenHeight = 100;
  98.  
  99. int screenWidth = defaultScreenWidth;
  100. int screenHeight = defaultScreenHeight;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement