Advertisement
Ramaraunt1

OpenStellar Engine Class

May 4th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #define GLEW_STATIC
  4. #include <GL/glew.h>
  5. #include <windows.h>
  6.  
  7. #include <GLFW/glfw3.h>
  8.  
  9. #include "stellarEngine.h"
  10.  
  11. Engine::Engine(int width, int height, std::string title_bar_text, bool fullscreen, bool resizable, int vm, int vn, GLuint prof, GLuint forcom)
  12. {
  13.  
  14. //variable assigning
  15. std::cout << "Starting OpenStellar Engine! Please wait while it initializes!" << std::endl;
  16. std::cout << "Assigning Variables!" << std::endl;
  17. if (resizable)
  18. {
  19. resizable = GL_TRUE;
  20. }
  21. else
  22. {
  23. resizable = GL_FALSE;
  24. }
  25. screenTitleBarText = title_bar_text;
  26. if (fullscreen == true)
  27. {
  28. screenFullscreen = glfwGetPrimaryMonitor();
  29. }
  30. else
  31. {
  32. screenFullscreen = nullptr;
  33. }
  34. major = vm;
  35. minor = vn;
  36. profile = prof;
  37. forwardCompat = forcom;
  38. screenWidth = width;
  39. screenHeight = height;
  40.  
  41.  
  42. if (!GLFWinitialize())
  43. {
  44. std::cout << "ERROR_CODE::0::ERROR::GLFW - GLFW failed to initialize!" << std::endl;
  45. }
  46. std::cout << "Creating game window!" << std::endl;
  47. const char * titleText = screenTitleBarText.c_str();
  48. window = glfwCreateWindow(screenWidth, screenHeight, titleText, nullptr, nullptr);
  49. if (window == nullptr)
  50. {
  51. std::cout << "ERROR_CODE::1::ERROR::GLFW - GLFW failed window creation!" << std::endl;
  52. glfwTerminate();
  53. }
  54. glfwMakeContextCurrent(window);
  55.  
  56. std::cout << "Setting up GLEW!" << std::endl;
  57. glewExperimental = GL_TRUE;
  58. if (glewInit() != GLEW_OK)
  59. {
  60. std::cout << "ERROR_CODE::2::ERROR::GLEW - Glew failed to initialize!" << std::endl;
  61. }
  62.  
  63. int wid, hei;
  64. glfwGetFramebufferSize(window, &wid, &hei);
  65. glViewport(0, 0, wid, hei);
  66. }
  67.  
  68. bool Engine::GLFWinitialize()
  69. {
  70. std::cout << "Setting up GLFW!" << std::endl;
  71. if (!glfwInit())
  72. {
  73. return false;
  74. }
  75. glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major);
  76. glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor);
  77. glfwWindowHint(GLFW_OPENGL_PROFILE, profile);
  78. glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, forwardCompat);
  79. glfwWindowHint(GLFW_RESIZABLE, resizable);
  80. return true;
  81. }
  82.  
  83.  
  84. void Engine::RunGameLoop()
  85. {
  86. std::cout << "Starting game loop!" << std::endl;
  87. while (!glfwWindowShouldClose(this->window))
  88. {
  89. glfwSwapBuffers(this->window);
  90. glfwPollEvents();
  91. }
  92. std::cout << "Game loop stopped!" << std::endl;
  93. }
  94.  
  95. void Engine::Stop()
  96. {
  97. std::cout << "Stopping game loop!" << std::endl;
  98. glfwSetWindowShouldClose(this->window, GL_TRUE);
  99. }
  100.  
  101. void Engine::CleanUp()
  102. {
  103. std::cout << "Cleaning Up!" << std::endl;
  104. glfwTerminate();
  105. }
  106.  
  107. GLFWwindow* Engine::getWindow()
  108. {
  109. return window;
  110. }
  111.  
  112. bool Engine::windowShouldClose()
  113. {
  114. return glfwWindowShouldClose(window);
  115. }
  116.  
  117.  
  118.  
  119. std::string Engine::getPath() {
  120. char buffer[MAX_PATH];
  121. GetModuleFileName(NULL, buffer, MAX_PATH);
  122. std::string::size_type pos = std::string(buffer).find_last_of("\\/");
  123. return std::string(buffer).substr(0, pos);
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement