Renderer refactoring. WIP InputSystem.

This commit is contained in:
2014-03-07 02:28:19 +01:00
parent e65db077d5
commit b1f0bc7cce
8 changed files with 39 additions and 59 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ namespace Components
struct Input : Component
{
int KeyState[GLFW_KEY_LAST];
float MouseState[2];
int MouseState[GLFW_MOUSE_BUTTON_LAST];
float dX, dY;
};
+1 -1
View File
@@ -132,7 +132,7 @@
<ClInclude Include="logging.h" />
<ClInclude Include="glerror.h" />
<ClInclude Include="Model.h" />
<ClInclude Include="Renderer\Renderer.h" />
<ClInclude Include="Renderer.h" />
<ClInclude Include="ShaderProgram.h" />
<ClInclude Include="Systems\InputSystem.h" />
<ClInclude Include="System.h" />
@@ -30,7 +30,6 @@
<ItemGroup>
<ClInclude Include="Component.h" />
<ClInclude Include="Entity.h" />
<ClInclude Include="Renderer\Renderer.h" />
<ClInclude Include="System.h" />
<ClInclude Include="World.h" />
<ClInclude Include="Systems\CollisionSystem.h">
@@ -107,6 +106,7 @@
<ClInclude Include="logging.h">
<Filter>Util</Filter>
</ClInclude>
<ClInclude Include="Renderer.h" />
</ItemGroup>
<ItemGroup>
<None Include="Shaders\Fragment.glsl">
+21 -5
View File
@@ -1,3 +1,6 @@
#ifndef Renderer_h__
#define Renderer_h__
#include <string>
#include <fstream>
#include <iostream>
@@ -16,19 +19,32 @@
#include <glm/gtc/type_ptr.hpp>
#include "glerror.h"
#include "ShaderProgram.h"
class Renderer
{
public:
GLuint shaderProgram;
std::shared_ptr<ShaderProgram> m_ShaderProgram;
GLuint VAO;
std::vector<std::vector<float>> Vertices;
std::vector<std::vector<float>> Normals;
std::vector<std::vector<float>> TextureCoords;
Renderer();
void Draw();
void DrawText();
GLuint CompileShader(GLenum, std::string);
void AddObjectToDraw();
void AddTextToDraw();
};
void LoadContent();
GLFWwindow* GetWindow() const { return m_Window; }
private:
GLFWwindow* m_Window;
};
#endif // Renderer_h__
-42
View File
@@ -1,42 +0,0 @@
#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
#define _CRT_SECURE_NO_WARNINGS
#include <GL/glew.h>
#define GLFW_INCLUDE_GLU
#include <GLFW/glfw3.h>
#include <glext.h>
#define GLM_FORCE_RADIANS
#include <glm/glm.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "glerror.h"
#include "ShaderProgram.h"
class Renderer
{
public:
std::shared_ptr<ShaderProgram> m_ShaderProgram;
GLuint VAO;
std::vector<std::vector<float>> Vertices;
std::vector<std::vector<float>> Normals;
std::vector<std::vector<float>> TextureCoords;
Renderer();
void Draw();
void DrawText();
void AddObjectToDraw();
void AddTextToDraw();
void LoadContent();
GLuint CompileShader(GLenum, std::string);
};
+6
View File
@@ -7,6 +7,12 @@ void Systems::InputSystem::Update(double dt, EntityID entity, EntityID parent)
if (input == nullptr)
return;
for (int i = 0; i <= GLFW_KEY_LAST; ++i) {
input->KeyState[i] = glfwGetKey(m_Renderer->GetWindow(), i);
}
for (int i = 0; i <= GLFW_MOUSE_BUTTON_LAST; ++i) {
input->MouseState[i] = glfwGetMouseButton(m_Renderer->GetWindow(), i);
}
}
+7 -8
View File
@@ -1,10 +1,8 @@
#ifndef InputSystem_h__
#define InputSystem_h__
#include <GLFW/glfw3.h>
#include "System.h"
#include "Renderer.h"
#include "Components/Input.h"
namespace Systems
@@ -13,13 +11,14 @@ namespace Systems
class InputSystem : public System
{
public:
InputSystem(World* world)
: System(world)
{
}
InputSystem(World* world, Renderer* renderer)
: System(world), m_Renderer(renderer) { }
void Update(double dt, EntityID entity, EntityID parent) override;
private:
Renderer* m_Renderer;
float m_LastMouseX, m_LastMouseY;
};
}
+2 -1
View File
@@ -6,6 +6,8 @@
#include <vector>
#include <string>
#include "Renderer.h"
#include "Entity.h"
#include "Component.h"
#include "Factory.h"
@@ -64,7 +66,6 @@ public:
// Recursively update through the scene graph
void Update(double dt);
void RecursiveUpdate(std::shared_ptr<System> system, double dt, EntityID parentEntity);
private: