Encapsulated Renderer WIDTH and HEIGHT variables.

This commit is contained in:
2014-04-29 13:58:27 +02:00
parent 57d29d0db7
commit d0211ef8d6
3 changed files with 12 additions and 11 deletions
+6 -6
View File
@@ -31,11 +31,11 @@ void Renderer::Initialize()
} }
// Create a window // Create a window
WIDTH = 1280; m_Width = 1280;
HEIGHT = 720; m_Height = 720;
// Antialiasing // Antialiasing
//glfwWindowHint(GLFW_SAMPLES, 16); //glfwWindowHint(GLFW_SAMPLES, 16);
m_Window = glfwCreateWindow(WIDTH, HEIGHT, "OpenGL", nullptr, nullptr); m_Window = glfwCreateWindow(m_Width, m_Height, "OpenGL", nullptr, nullptr);
if (!m_Window) if (!m_Window)
{ {
LOG_ERROR("GLFW: Failed to create window"); LOG_ERROR("GLFW: Failed to create window");
@@ -63,7 +63,7 @@ void Renderer::Initialize()
} }
// Create Camera // Create Camera
m_Camera = std::make_shared<Camera>(45.f, (float)WIDTH / HEIGHT, 0.01f, 1000.f); m_Camera = std::make_shared<Camera>(45.f, (float)m_Width / m_Height, 0.01f, 1000.f);
m_Camera->Position(glm::vec3(0.0f, 0.0f, 2.f)); m_Camera->Position(glm::vec3(0.0f, 0.0f, 2.f));
glfwSwapInterval(m_VSync); glfwSwapInterval(m_VSync);
@@ -187,7 +187,7 @@ void Renderer::Draw(double dt)
void Renderer::DrawSkybox() void Renderer::DrawSkybox()
{ {
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, WIDTH, HEIGHT); glViewport(0, 0, m_Width, m_Height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_ShaderProgramSkybox.Bind(); m_ShaderProgramSkybox.Bind();
@@ -200,7 +200,7 @@ void Renderer::DrawSkybox()
void Renderer::DrawScene() void Renderer::DrawScene()
{ {
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, WIDTH, HEIGHT); glViewport(0, 0, m_Width, m_Height);
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
//glClearColor(1.0f, 1.0f, 0.0f, 1.0f); //glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
+4 -3
View File
@@ -20,7 +20,9 @@ public:
glm::mat4 viewMatrix; glm::mat4 viewMatrix;
glm::mat4 projectionMatrix; glm::mat4 projectionMatrix;
int HEIGHT, WIDTH;
int Width() const { return m_Width; }
int Height() const { return m_Height; }
std::list<std::tuple<Model*, glm::mat4, bool, bool>> ModelsToRender; std::list<std::tuple<Model*, glm::mat4, bool, bool>> ModelsToRender;
int Lights; int Lights;
@@ -65,9 +67,8 @@ public:
void DrawBounds(bool val) { m_DrawBounds = val; } void DrawBounds(bool val) { m_DrawBounds = val; }
void DrawSkybox(); void DrawSkybox();
private: private:
int m_Width, m_Height;
GLFWwindow* m_Window; GLFWwindow* m_Window;
GLint m_glVersion[2]; GLint m_glVersion[2];
GLchar* m_glVendor; GLchar* m_glVendor;
+2 -2
View File
@@ -51,8 +51,8 @@ void Systems::InputSystem::Update(double dt)
// Lock mouse while holding LMB // Lock mouse while holding LMB
if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT]) if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT])
{ {
m_LastMouseX = m_Renderer->WIDTH / 2.f; // xpos; m_LastMouseX = m_Renderer->Width() / 2.f; // xpos;
m_LastMouseY = m_Renderer->HEIGHT / 2.f; // ypos; m_LastMouseY = m_Renderer->Height() / 2.f; // ypos;
glfwSetCursorPos(m_Renderer->GetWindow(), m_LastMouseX, m_LastMouseY); glfwSetCursorPos(m_Renderer->GetWindow(), m_LastMouseX, m_LastMouseY);
} }
// Hide/show cursor with LMB // Hide/show cursor with LMB