Engine
Frameworkcreatedbymeusableforthecreationofsimplegames.CurrentlysupportsOpenGL(Verysimple)andVulkan.
OpenGLWindow.cpp
Go to the documentation of this file.
2 #include <string>
3 #ifdef USING_OPENGL
8 #include <iostream>
9 
10 namespace Engine
11 {
12  OpenGLWindow::OpenGLWindow(int width, int height, const char* title) noexcept
13  {
14  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
15  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
16  glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
17  glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
18 
19  windowReference = eastl::shared_ptr<Window>(new Window(width, height, title));
20 
21  window = windowReference->GetGLFWWindow().lock();
22  this->width = windowReference->GetWidth();
23  this->displayWidth = windowReference->GetDisplayWidth();
24  this->displayHeight = windowReference->GetDisplayHeight();
25  this->height = windowReference->GetHeight();
26  this->title = windowReference->GetTitle();
27 
28  int major = glfwGetWindowAttrib(window.get(), GLFW_CONTEXT_VERSION_MAJOR);
29  int minor = glfwGetWindowAttrib(window.get(), GLFW_CONTEXT_VERSION_MINOR);
30  int revision = glfwGetWindowAttrib(window.get(), GLFW_CONTEXT_REVISION);
31  debug_info("OpenGLWindow", "Constructor", eastl::string(eastl::string("OpenGL Version ") + std::to_string(major).c_str() + "." + std::to_string(minor).c_str() + "." + std::to_string(revision).c_str()));
32 
33  glfwMakeContextCurrent(window.get());
34  //glfwSwapInterval(1);
35 
36  glewExperimental = true; // Required because we use the Core profile (line 15)
37  GLenum glewError = glewInit();
38  if (glewError != GLEW_OK)
39  {
40  debug_error("OpenGLWindow", "Constructor", "Failed to initialize OpenGL context");
41  return;
42  }
43 
44  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
45  // Enable depth test
46  glEnable(GL_DEPTH_TEST);
47  // Accept fragment if it closer to the camera than the former one
48  glDepthFunc(GL_LESS);
49  // Cull triangles which normal is not towards the camera
50  glEnable(GL_CULL_FACE);
51  }
52 
53  OpenGLWindow::~OpenGLWindow() noexcept
54  {
55  }
56 } //namespace Engine
57 #endif
#define debug_error(debug_class, function, value)
This functions logs a debug error to the log and console. This does not halt the program! ...
Definition: Logging.hpp:30
#define debug_info(debug_class, function, value)
This functions logs a debug info to the log and console. Use this for useless information.
Definition: Logging.hpp:60