diff options
-rw-r--r-- | src/components/controllable.h | 6 | ||||
-rw-r--r-- | src/components/droppable.h | 2 | ||||
-rw-r--r-- | src/components/ponderable.h | 2 | ||||
-rw-r--r-- | src/components/transformable.cpp | 2 | ||||
-rw-r--r-- | src/components/transformable.h | 6 | ||||
-rw-r--r-- | src/entity_manager.cpp | 8 | ||||
-rw-r--r-- | src/entity_manager.h | 64 | ||||
-rw-r--r-- | src/game.cpp | 10 | ||||
-rw-r--r-- | src/game.h | 6 | ||||
-rw-r--r-- | src/main.cpp | 10 | ||||
-rw-r--r-- | src/renderer.cpp | 228 | ||||
-rw-r--r-- | src/renderer.h | 2 | ||||
-rw-r--r-- | src/system.h | 4 | ||||
-rw-r--r-- | src/system_manager.h | 8 | ||||
-rw-r--r-- | src/systems/controlling.cpp | 12 | ||||
-rw-r--r-- | src/systems/controlling.h | 6 | ||||
-rw-r--r-- | src/systems/pondering.cpp | 6 | ||||
-rw-r--r-- | src/systems/pondering.h | 2 | ||||
-rw-r--r-- | src/systems/rendering.h | 4 |
19 files changed, 194 insertions, 194 deletions
diff --git a/src/components/controllable.h b/src/components/controllable.h index 317d68d..baccf13 100644 --- a/src/components/controllable.h +++ b/src/components/controllable.h | |||
@@ -14,20 +14,20 @@ class ControllableComponent : public Component { | |||
14 | void setJumpKey(int k); | 14 | void setJumpKey(int k); |
15 | int getDropKey() const; | 15 | int getDropKey() const; |
16 | void setDropKey(int k); | 16 | void setDropKey(int k); |
17 | 17 | ||
18 | bool isFrozen() const; | 18 | bool isFrozen() const; |
19 | void setFrozen(bool f); | 19 | void setFrozen(bool f); |
20 | bool isHoldingLeft() const; | 20 | bool isHoldingLeft() const; |
21 | void setHoldingLeft(bool f); | 21 | void setHoldingLeft(bool f); |
22 | bool isHoldingRight() const; | 22 | bool isHoldingRight() const; |
23 | void setHoldingRight(bool f); | 23 | void setHoldingRight(bool f); |
24 | 24 | ||
25 | private: | 25 | private: |
26 | int leftKey = GLFW_KEY_LEFT; | 26 | int leftKey = GLFW_KEY_LEFT; |
27 | int rightKey = GLFW_KEY_RIGHT; | 27 | int rightKey = GLFW_KEY_RIGHT; |
28 | int jumpKey = GLFW_KEY_UP; | 28 | int jumpKey = GLFW_KEY_UP; |
29 | int dropKey = GLFW_KEY_DOWN; | 29 | int dropKey = GLFW_KEY_DOWN; |
30 | 30 | ||
31 | bool frozen = false; | 31 | bool frozen = false; |
32 | bool holdingLeft = false; | 32 | bool holdingLeft = false; |
33 | bool holdingRight = false; | 33 | bool holdingRight = false; |
diff --git a/src/components/droppable.h b/src/components/droppable.h index 1f5608b..83fcb9d 100644 --- a/src/components/droppable.h +++ b/src/components/droppable.h | |||
@@ -7,7 +7,7 @@ class DroppableComponent : public Component { | |||
7 | public: | 7 | public: |
8 | void setDroppable(bool can); | 8 | void setDroppable(bool can); |
9 | bool isDroppable() const; | 9 | bool isDroppable() const; |
10 | 10 | ||
11 | private: | 11 | private: |
12 | bool droppable = false; | 12 | bool droppable = false; |
13 | }; | 13 | }; |
diff --git a/src/components/ponderable.h b/src/components/ponderable.h index 5aab4b3..c836d2a 100644 --- a/src/components/ponderable.h +++ b/src/components/ponderable.h | |||
@@ -13,7 +13,7 @@ class PonderableComponent : public Component { | |||
13 | void setAccelX(double v); | 13 | void setAccelX(double v); |
14 | double getAccelY() const; | 14 | double getAccelY() const; |
15 | void setAccelY(double v); | 15 | void setAccelY(double v); |
16 | 16 | ||
17 | private: | 17 | private: |
18 | double velocityX = 0.0; | 18 | double velocityX = 0.0; |
19 | double velocityY = 0.0; | 19 | double velocityY = 0.0; |
diff --git a/src/components/transformable.cpp b/src/components/transformable.cpp index 0d6b67e..89b1e5d 100644 --- a/src/components/transformable.cpp +++ b/src/components/transformable.cpp | |||
@@ -3,7 +3,7 @@ | |||
3 | TransformableComponent::TransformableComponent(double x, double y, int w, int h) | 3 | TransformableComponent::TransformableComponent(double x, double y, int w, int h) |
4 | : x(x), y(y), w(w), h(h) | 4 | : x(x), y(y), w(w), h(h) |
5 | { | 5 | { |
6 | 6 | ||
7 | } | 7 | } |
8 | 8 | ||
9 | double TransformableComponent::getX() const | 9 | double TransformableComponent::getX() const |
diff --git a/src/components/transformable.h b/src/components/transformable.h index 87ba84d..69f4f0e 100644 --- a/src/components/transformable.h +++ b/src/components/transformable.h | |||
@@ -6,17 +6,17 @@ | |||
6 | class TransformableComponent : public Component { | 6 | class TransformableComponent : public Component { |
7 | public: | 7 | public: |
8 | TransformableComponent(double x, double y, int w, int h); | 8 | TransformableComponent(double x, double y, int w, int h); |
9 | 9 | ||
10 | double getX() const; | 10 | double getX() const; |
11 | double getY() const; | 11 | double getY() const; |
12 | int getW() const; | 12 | int getW() const; |
13 | int getH() const; | 13 | int getH() const; |
14 | 14 | ||
15 | void setX(double v); | 15 | void setX(double v); |
16 | void setY(double v); | 16 | void setY(double v); |
17 | void setW(int v); | 17 | void setW(int v); |
18 | void setH(int v); | 18 | void setH(int v); |
19 | 19 | ||
20 | private: | 20 | private: |
21 | double x; | 21 | double x; |
22 | double y; | 22 | double y; |
diff --git a/src/entity_manager.cpp b/src/entity_manager.cpp index 4bdfe8a..9ad758b 100644 --- a/src/entity_manager.cpp +++ b/src/entity_manager.cpp | |||
@@ -10,13 +10,13 @@ std::set<int> EntityManager::getEntitiesWithComponents<>(std::set<std::type_inde | |||
10 | { | 10 | { |
11 | return cachedComponents[componentTypes]; | 11 | return cachedComponents[componentTypes]; |
12 | } | 12 | } |
13 | 13 | ||
14 | std::set<int>& cache = cachedComponents[componentTypes]; | 14 | std::set<int>& cache = cachedComponents[componentTypes]; |
15 | for (auto& entity : entities) | 15 | for (auto& entity : entities) |
16 | { | 16 | { |
17 | EntityData& data = entity.second; | 17 | EntityData& data = entity.second; |
18 | bool cacheEntity = true; | 18 | bool cacheEntity = true; |
19 | 19 | ||
20 | for (auto& componentType : componentTypes) | 20 | for (auto& componentType : componentTypes) |
21 | { | 21 | { |
22 | if (data.components.count(componentType) == 0) | 22 | if (data.components.count(componentType) == 0) |
@@ -25,13 +25,13 @@ std::set<int> EntityManager::getEntitiesWithComponents<>(std::set<std::type_inde | |||
25 | break; | 25 | break; |
26 | } | 26 | } |
27 | } | 27 | } |
28 | 28 | ||
29 | if (cacheEntity) | 29 | if (cacheEntity) |
30 | { | 30 | { |
31 | cache.insert(entity.first); | 31 | cache.insert(entity.first); |
32 | } | 32 | } |
33 | } | 33 | } |
34 | 34 | ||
35 | return cache; | 35 | return cache; |
36 | } | 36 | } |
37 | 37 | ||
diff --git a/src/entity_manager.h b/src/entity_manager.h index 5f0f2d4..a36d720 100644 --- a/src/entity_manager.h +++ b/src/entity_manager.h | |||
@@ -13,30 +13,30 @@ class EntityManager { | |||
13 | struct EntityData { | 13 | struct EntityData { |
14 | std::map<std::type_index, std::unique_ptr<Component>> components; | 14 | std::map<std::type_index, std::unique_ptr<Component>> components; |
15 | }; | 15 | }; |
16 | 16 | ||
17 | std::map<int, EntityData> entities; | 17 | std::map<int, EntityData> entities; |
18 | std::map<std::set<std::type_index>, std::set<int>> cachedComponents; | 18 | std::map<std::set<std::type_index>, std::set<int>> cachedComponents; |
19 | 19 | ||
20 | int nextEntityID = 0; | 20 | int nextEntityID = 0; |
21 | 21 | ||
22 | template <class T, class... R> | 22 | template <class T, class... R> |
23 | std::set<int> getEntitiesWithComponentsHelper(std::set<std::type_index>& componentTypes) | 23 | std::set<int> getEntitiesWithComponentsHelper(std::set<std::type_index>& componentTypes) |
24 | { | 24 | { |
25 | componentTypes.insert(typeid(T)); | 25 | componentTypes.insert(typeid(T)); |
26 | 26 | ||
27 | return getEntitiesWithComponents<R...>(componentTypes); | 27 | return getEntitiesWithComponents<R...>(componentTypes); |
28 | } | 28 | } |
29 | 29 | ||
30 | template <class... R> | 30 | template <class... R> |
31 | std::set<int> getEntitiesWithComponents(std::set<std::type_index>& componentTypes) | 31 | std::set<int> getEntitiesWithComponents(std::set<std::type_index>& componentTypes) |
32 | { | 32 | { |
33 | return getEntitiesWithComponentsHelper<R...>(componentTypes); | 33 | return getEntitiesWithComponentsHelper<R...>(componentTypes); |
34 | } | 34 | } |
35 | 35 | ||
36 | public: | 36 | public: |
37 | EntityManager() = default; | 37 | EntityManager() = default; |
38 | EntityManager(const EntityManager& copy) = delete; | 38 | EntityManager(const EntityManager& copy) = delete; |
39 | 39 | ||
40 | int emplaceEntity() | 40 | int emplaceEntity() |
41 | { | 41 | { |
42 | // Find a suitable entity ID | 42 | // Find a suitable entity ID |
@@ -44,76 +44,76 @@ class EntityManager { | |||
44 | { | 44 | { |
45 | nextEntityID++; | 45 | nextEntityID++; |
46 | } | 46 | } |
47 | 47 | ||
48 | if (nextEntityID < 0) | 48 | if (nextEntityID < 0) |
49 | { | 49 | { |
50 | nextEntityID = 0; | 50 | nextEntityID = 0; |
51 | 51 | ||
52 | while ((entities.count(nextEntityID) == 1) && (nextEntityID >= 0)) | 52 | while ((entities.count(nextEntityID) == 1) && (nextEntityID >= 0)) |
53 | { | 53 | { |
54 | nextEntityID++; | 54 | nextEntityID++; |
55 | } | 55 | } |
56 | 56 | ||
57 | assert(nextEntityID >= 0); | 57 | assert(nextEntityID >= 0); |
58 | } | 58 | } |
59 | 59 | ||
60 | // Initialize the data | 60 | // Initialize the data |
61 | int id = nextEntityID++; | 61 | int id = nextEntityID++; |
62 | entities[id]; | 62 | entities[id]; |
63 | 63 | ||
64 | return id; | 64 | return id; |
65 | } | 65 | } |
66 | 66 | ||
67 | void deleteEntity(int entity) | 67 | void deleteEntity(int entity) |
68 | { | 68 | { |
69 | assert(entities.count(entity) == 1); | 69 | assert(entities.count(entity) == 1); |
70 | 70 | ||
71 | // Uncache components | 71 | // Uncache components |
72 | for (auto& cache : cachedComponents) | 72 | for (auto& cache : cachedComponents) |
73 | { | 73 | { |
74 | cache.second.erase(entity); | 74 | cache.second.erase(entity); |
75 | } | 75 | } |
76 | 76 | ||
77 | // Destroy the data | 77 | // Destroy the data |
78 | entities.erase(entity); | 78 | entities.erase(entity); |
79 | } | 79 | } |
80 | 80 | ||
81 | template <class T, class... Args> | 81 | template <class T, class... Args> |
82 | T& emplaceComponent(int entity, Args&&... args) | 82 | T& emplaceComponent(int entity, Args&&... args) |
83 | { | 83 | { |
84 | assert(entities.count(entity) == 1); | 84 | assert(entities.count(entity) == 1); |
85 | 85 | ||
86 | EntityData& data = entities[entity]; | 86 | EntityData& data = entities[entity]; |
87 | std::type_index componentType = typeid(T); | 87 | std::type_index componentType = typeid(T); |
88 | 88 | ||
89 | assert(data.components.count(componentType) == 0); | 89 | assert(data.components.count(componentType) == 0); |
90 | 90 | ||
91 | // Initialize the component | 91 | // Initialize the component |
92 | std::unique_ptr<T> ptr = std::unique_ptr<T>(new T(std::forward<Args>(args)...)); | 92 | std::unique_ptr<T> ptr = std::unique_ptr<T>(new T(std::forward<Args>(args)...)); |
93 | T& component = *ptr; | 93 | T& component = *ptr; |
94 | data.components[componentType] = std::move(ptr); | 94 | data.components[componentType] = std::move(ptr); |
95 | 95 | ||
96 | // Invalidate related caches | 96 | // Invalidate related caches |
97 | erase_if(cachedComponents, [&componentType] (std::pair<const std::set<std::type_index>, std::set<int>>& cache) { | 97 | erase_if(cachedComponents, [&componentType] (std::pair<const std::set<std::type_index>, std::set<int>>& cache) { |
98 | return cache.first.count(componentType) == 1; | 98 | return cache.first.count(componentType) == 1; |
99 | }); | 99 | }); |
100 | 100 | ||
101 | return component; | 101 | return component; |
102 | } | 102 | } |
103 | 103 | ||
104 | template <class T> | 104 | template <class T> |
105 | void removeComponent(int entity) | 105 | void removeComponent(int entity) |
106 | { | 106 | { |
107 | assert(entities.count(entity) == 1); | 107 | assert(entities.count(entity) == 1); |
108 | 108 | ||
109 | EntityData& data = entities[entity]; | 109 | EntityData& data = entities[entity]; |
110 | std::type_index componentType = typeid(T); | 110 | std::type_index componentType = typeid(T); |
111 | 111 | ||
112 | assert(data.components.count(componentType) == 1); | 112 | assert(data.components.count(componentType) == 1); |
113 | 113 | ||
114 | // Destroy the component | 114 | // Destroy the component |
115 | data.components.erase(componentType); | 115 | data.components.erase(componentType); |
116 | 116 | ||
117 | // Uncache the component | 117 | // Uncache the component |
118 | for (auto& cache : cachedComponents) | 118 | for (auto& cache : cachedComponents) |
119 | { | 119 | { |
@@ -123,25 +123,25 @@ class EntityManager { | |||
123 | } | 123 | } |
124 | } | 124 | } |
125 | } | 125 | } |
126 | 126 | ||
127 | template <class T> | 127 | template <class T> |
128 | T& getComponent(int entity) | 128 | T& getComponent(int entity) |
129 | { | 129 | { |
130 | assert(entities.count(entity) == 1); | 130 | assert(entities.count(entity) == 1); |
131 | 131 | ||
132 | EntityData& data = entities[entity]; | 132 | EntityData& data = entities[entity]; |
133 | std::type_index componentType = typeid(T); | 133 | std::type_index componentType = typeid(T); |
134 | 134 | ||
135 | assert(data.components.count(componentType) == 1); | 135 | assert(data.components.count(componentType) == 1); |
136 | 136 | ||
137 | return *((T*)data.components[componentType].get()); | 137 | return *((T*)data.components[componentType].get()); |
138 | } | 138 | } |
139 | 139 | ||
140 | template <class... R> | 140 | template <class... R> |
141 | std::set<int> getEntitiesWithComponents() | 141 | std::set<int> getEntitiesWithComponents() |
142 | { | 142 | { |
143 | std::set<std::type_index> componentTypes; | 143 | std::set<std::type_index> componentTypes; |
144 | 144 | ||
145 | return getEntitiesWithComponentsHelper<R...>(componentTypes); | 145 | return getEntitiesWithComponentsHelper<R...>(componentTypes); |
146 | } | 146 | } |
147 | }; | 147 | }; |
diff --git a/src/game.cpp b/src/game.cpp index b3fa9a8..5d1ec18 100644 --- a/src/game.cpp +++ b/src/game.cpp | |||
@@ -45,24 +45,24 @@ void Game::execute() | |||
45 | double lastTime = glfwGetTime(); | 45 | double lastTime = glfwGetTime(); |
46 | const double dt = 0.01; | 46 | const double dt = 0.01; |
47 | double accumulator = 0.0; | 47 | double accumulator = 0.0; |
48 | 48 | ||
49 | while (!(shouldQuit || glfwWindowShouldClose(window))) | 49 | while (!(shouldQuit || glfwWindowShouldClose(window))) |
50 | { | 50 | { |
51 | double currentTime = glfwGetTime(); | 51 | double currentTime = glfwGetTime(); |
52 | double frameTime = currentTime - lastTime; | 52 | double frameTime = currentTime - lastTime; |
53 | lastTime = currentTime; | 53 | lastTime = currentTime; |
54 | 54 | ||
55 | glfwPollEvents(); | 55 | glfwPollEvents(); |
56 | 56 | ||
57 | accumulator += frameTime; | 57 | accumulator += frameTime; |
58 | while (accumulator >= dt) | 58 | while (accumulator >= dt) |
59 | { | 59 | { |
60 | systemManager.getSystem<ControllingSystem>().tick(dt); | 60 | systemManager.getSystem<ControllingSystem>().tick(dt); |
61 | systemManager.getSystem<PonderingSystem>().tick(dt); | 61 | systemManager.getSystem<PonderingSystem>().tick(dt); |
62 | 62 | ||
63 | accumulator -= dt; | 63 | accumulator -= dt; |
64 | } | 64 | } |
65 | 65 | ||
66 | systemManager.getSystem<RenderingSystem>().tick(frameTime); | 66 | systemManager.getSystem<RenderingSystem>().tick(frameTime); |
67 | } | 67 | } |
68 | } | 68 | } |
diff --git a/src/game.h b/src/game.h index 3822700..ec667c8 100644 --- a/src/game.h +++ b/src/game.h | |||
@@ -8,12 +8,12 @@ | |||
8 | class Game { | 8 | class Game { |
9 | public: | 9 | public: |
10 | Game(GLFWwindow* window); | 10 | Game(GLFWwindow* window); |
11 | 11 | ||
12 | void execute(); | 12 | void execute(); |
13 | EntityManager& getEntityManager(); | 13 | EntityManager& getEntityManager(); |
14 | 14 | ||
15 | friend void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); | 15 | friend void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); |
16 | 16 | ||
17 | private: | 17 | private: |
18 | EntityManager entityManager; | 18 | EntityManager entityManager; |
19 | SystemManager systemManager; | 19 | SystemManager systemManager; |
diff --git a/src/main.cpp b/src/main.cpp index 35749f5..d51da7d 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
@@ -8,20 +8,20 @@ | |||
8 | int main() | 8 | int main() |
9 | { | 9 | { |
10 | srand(time(NULL)); | 10 | srand(time(NULL)); |
11 | 11 | ||
12 | GLFWwindow* window = initRenderer(); | 12 | GLFWwindow* window = initRenderer(); |
13 | glfwSwapInterval(1); | 13 | glfwSwapInterval(1); |
14 | 14 | ||
15 | initMuxer(); | 15 | initMuxer(); |
16 | 16 | ||
17 | // Put this in a block so game goes out of scope before we destroy the renderer | 17 | // Put this in a block so game goes out of scope before we destroy the renderer |
18 | { | 18 | { |
19 | Game game {window}; | 19 | Game game {window}; |
20 | game.execute(); | 20 | game.execute(); |
21 | } | 21 | } |
22 | 22 | ||
23 | destroyMuxer(); | 23 | destroyMuxer(); |
24 | destroyRenderer(); | 24 | destroyRenderer(); |
25 | 25 | ||
26 | return 0; | 26 | return 0; |
27 | } | 27 | } |
diff --git a/src/renderer.cpp b/src/renderer.cpp index 99d5389..d0d2b75 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp | |||
@@ -56,11 +56,11 @@ static GLuint mesh_normalbuffer; | |||
56 | static int mesh_numvertices; | 56 | static int mesh_numvertices; |
57 | 57 | ||
58 | GLuint LoadShaders(const char* vertex_file_path, const char* fragment_file_path) | 58 | GLuint LoadShaders(const char* vertex_file_path, const char* fragment_file_path) |
59 | { | 59 | { |
60 | // Create the shaders | 60 | // Create the shaders |
61 | GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER); | 61 | GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER); |
62 | GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER); | 62 | GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER); |
63 | 63 | ||
64 | // Read the Vertex Shader code from the file | 64 | // Read the Vertex Shader code from the file |
65 | std::string VertexShaderCode; | 65 | std::string VertexShaderCode; |
66 | std::ifstream VertexShaderStream(vertex_file_path, std::ios::in); | 66 | std::ifstream VertexShaderStream(vertex_file_path, std::ios::in); |
@@ -71,7 +71,7 @@ GLuint LoadShaders(const char* vertex_file_path, const char* fragment_file_path) | |||
71 | VertexShaderCode += "\n" + Line; | 71 | VertexShaderCode += "\n" + Line; |
72 | VertexShaderStream.close(); | 72 | VertexShaderStream.close(); |
73 | } | 73 | } |
74 | 74 | ||
75 | // Read the Fragment Shader code from the file | 75 | // Read the Fragment Shader code from the file |
76 | std::string FragmentShaderCode; | 76 | std::string FragmentShaderCode; |
77 | std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in); | 77 | std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in); |
@@ -81,53 +81,53 @@ GLuint LoadShaders(const char* vertex_file_path, const char* fragment_file_path) | |||
81 | FragmentShaderCode += "\n" + Line; | 81 | FragmentShaderCode += "\n" + Line; |
82 | FragmentShaderStream.close(); | 82 | FragmentShaderStream.close(); |
83 | } | 83 | } |
84 | 84 | ||
85 | GLint Result = GL_FALSE; | 85 | GLint Result = GL_FALSE; |
86 | int InfoLogLength; | 86 | int InfoLogLength; |
87 | 87 | ||
88 | // Compile Vertex Shader | 88 | // Compile Vertex Shader |
89 | printf("Compiling shader : %s\n", vertex_file_path); | 89 | printf("Compiling shader : %s\n", vertex_file_path); |
90 | char const * VertexSourcePointer = VertexShaderCode.c_str(); | 90 | char const * VertexSourcePointer = VertexShaderCode.c_str(); |
91 | glShaderSource(VertexShaderID, 1, &VertexSourcePointer , nullptr); | 91 | glShaderSource(VertexShaderID, 1, &VertexSourcePointer , nullptr); |
92 | glCompileShader(VertexShaderID); | 92 | glCompileShader(VertexShaderID); |
93 | 93 | ||
94 | // Check Vertex Shader | 94 | // Check Vertex Shader |
95 | glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result); | 95 | glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result); |
96 | glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); | 96 | glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); |
97 | std::vector<char> VertexShaderErrorMessage(InfoLogLength); | 97 | std::vector<char> VertexShaderErrorMessage(InfoLogLength); |
98 | glGetShaderInfoLog(VertexShaderID, InfoLogLength, nullptr, &VertexShaderErrorMessage[0]); | 98 | glGetShaderInfoLog(VertexShaderID, InfoLogLength, nullptr, &VertexShaderErrorMessage[0]); |
99 | fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]); | 99 | fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]); |
100 | 100 | ||
101 | // Compile Fragment Shader | 101 | // Compile Fragment Shader |
102 | printf("Compiling shader : %s\n", fragment_file_path); | 102 | printf("Compiling shader : %s\n", fragment_file_path); |
103 | char const * FragmentSourcePointer = FragmentShaderCode.c_str(); | 103 | char const * FragmentSourcePointer = FragmentShaderCode.c_str(); |
104 | glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , nullptr); | 104 | glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , nullptr); |
105 | glCompileShader(FragmentShaderID); | 105 | glCompileShader(FragmentShaderID); |
106 | 106 | ||
107 | // Check Fragment Shader | 107 | // Check Fragment Shader |
108 | glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result); | 108 | glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result); |
109 | glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); | 109 | glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); |
110 | std::vector<char> FragmentShaderErrorMessage(InfoLogLength); | 110 | std::vector<char> FragmentShaderErrorMessage(InfoLogLength); |
111 | glGetShaderInfoLog(FragmentShaderID, InfoLogLength, nullptr, &FragmentShaderErrorMessage[0]); | 111 | glGetShaderInfoLog(FragmentShaderID, InfoLogLength, nullptr, &FragmentShaderErrorMessage[0]); |
112 | fprintf(stdout, "%s\n", &FragmentShaderErrorMessage[0]); | 112 | fprintf(stdout, "%s\n", &FragmentShaderErrorMessage[0]); |
113 | 113 | ||
114 | // Link the program | 114 | // Link the program |
115 | fprintf(stdout, "Linking program\n"); | 115 | fprintf(stdout, "Linking program\n"); |
116 | GLuint ProgramID = glCreateProgram(); | 116 | GLuint ProgramID = glCreateProgram(); |
117 | glAttachShader(ProgramID, VertexShaderID); | 117 | glAttachShader(ProgramID, VertexShaderID); |
118 | glAttachShader(ProgramID, FragmentShaderID); | 118 | glAttachShader(ProgramID, FragmentShaderID); |
119 | glLinkProgram(ProgramID); | 119 | glLinkProgram(ProgramID); |
120 | 120 | ||
121 | // Check the program | 121 | // Check the program |
122 | glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result); | 122 | glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result); |
123 | glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength); | 123 | glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength); |
124 | std::vector<char> ProgramErrorMessage( glm::max(InfoLogLength, int(1)) ); | 124 | std::vector<char> ProgramErrorMessage( glm::max(InfoLogLength, int(1)) ); |
125 | glGetProgramInfoLog(ProgramID, InfoLogLength, nullptr, &ProgramErrorMessage[0]); | 125 | glGetProgramInfoLog(ProgramID, InfoLogLength, nullptr, &ProgramErrorMessage[0]); |
126 | fprintf(stdout, "%s\n", &ProgramErrorMessage[0]); | 126 | fprintf(stdout, "%s\n", &ProgramErrorMessage[0]); |
127 | 127 | ||
128 | glDeleteShader(VertexShaderID); | 128 | glDeleteShader(VertexShaderID); |
129 | glDeleteShader(FragmentShaderID); | 129 | glDeleteShader(FragmentShaderID); |
130 | 130 | ||
131 | return ProgramID; | 131 | return ProgramID; |
132 | } | 132 | } |
133 | 133 | ||
@@ -135,14 +135,14 @@ void flipImageData(unsigned char* data, int width, int height, int comps) | |||
135 | { | 135 | { |
136 | unsigned char* data_copy = (unsigned char*) malloc(width*height*comps*sizeof(unsigned char)); | 136 | unsigned char* data_copy = (unsigned char*) malloc(width*height*comps*sizeof(unsigned char)); |
137 | memcpy(data_copy, data, width*height*comps); | 137 | memcpy(data_copy, data, width*height*comps); |
138 | 138 | ||
139 | int row_size = width * comps; | 139 | int row_size = width * comps; |
140 | 140 | ||
141 | for (int i=0;i<height;i++) | 141 | for (int i=0;i<height;i++) |
142 | { | 142 | { |
143 | memcpy(data + (row_size*i), data_copy + (row_size*(height-i-1)), row_size); | 143 | memcpy(data + (row_size*i), data_copy + (row_size*(height-i-1)), row_size); |
144 | } | 144 | } |
145 | 145 | ||
146 | free(data_copy); | 146 | free(data_copy); |
147 | } | 147 | } |
148 | 148 | ||
@@ -154,11 +154,11 @@ void loadMesh(const char* filename, std::vector<glm::vec3>& out_vertices, std::v | |||
154 | fprintf(stderr, "Could not open mesh file %s\n", filename); | 154 | fprintf(stderr, "Could not open mesh file %s\n", filename); |
155 | exit(1); | 155 | exit(1); |
156 | } | 156 | } |
157 | 157 | ||
158 | std::vector<glm::vec3> temp_vertices; | 158 | std::vector<glm::vec3> temp_vertices; |
159 | std::vector<glm::vec2> temp_uvs; | 159 | std::vector<glm::vec2> temp_uvs; |
160 | std::vector<glm::vec3> temp_normals; | 160 | std::vector<glm::vec3> temp_normals; |
161 | 161 | ||
162 | for (;;) | 162 | for (;;) |
163 | { | 163 | { |
164 | char lineHeader[256]; | 164 | char lineHeader[256]; |
@@ -167,7 +167,7 @@ void loadMesh(const char* filename, std::vector<glm::vec3>& out_vertices, std::v | |||
167 | { | 167 | { |
168 | break; | 168 | break; |
169 | } | 169 | } |
170 | 170 | ||
171 | if (!strncmp(lineHeader, "v", 2)) | 171 | if (!strncmp(lineHeader, "v", 2)) |
172 | { | 172 | { |
173 | glm::vec3 vertex; | 173 | glm::vec3 vertex; |
@@ -187,7 +187,7 @@ void loadMesh(const char* filename, std::vector<glm::vec3>& out_vertices, std::v | |||
187 | { | 187 | { |
188 | int vertexIDs[3], uvIDs[3], normalIDs[3]; | 188 | int vertexIDs[3], uvIDs[3], normalIDs[3]; |
189 | fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", &vertexIDs[0], &uvIDs[0], &normalIDs[0], &vertexIDs[1], &uvIDs[1], &normalIDs[1], &vertexIDs[2], &uvIDs[2], &normalIDs[2]); | 189 | fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", &vertexIDs[0], &uvIDs[0], &normalIDs[0], &vertexIDs[1], &uvIDs[1], &normalIDs[1], &vertexIDs[2], &uvIDs[2], &normalIDs[2]); |
190 | 190 | ||
191 | for (int i=0; i<3; i++) | 191 | for (int i=0; i<3; i++) |
192 | { | 192 | { |
193 | out_vertices.push_back(temp_vertices[vertexIDs[i] - 1]); | 193 | out_vertices.push_back(temp_vertices[vertexIDs[i] - 1]); |
@@ -202,24 +202,24 @@ void setFramebufferSize(GLFWwindow* w, int width, int height) | |||
202 | { | 202 | { |
203 | buffer_width = width; | 203 | buffer_width = width; |
204 | buffer_height = height; | 204 | buffer_height = height; |
205 | 205 | ||
206 | glDeleteFramebuffers(1, &bloom_framebuffer); | 206 | glDeleteFramebuffers(1, &bloom_framebuffer); |
207 | glDeleteRenderbuffers(1, &bloom_depthbuffer); | 207 | glDeleteRenderbuffers(1, &bloom_depthbuffer); |
208 | 208 | ||
209 | glGenFramebuffers(1, &bloom_framebuffer); | 209 | glGenFramebuffers(1, &bloom_framebuffer); |
210 | glBindFramebuffer(GL_FRAMEBUFFER, bloom_framebuffer); | 210 | glBindFramebuffer(GL_FRAMEBUFFER, bloom_framebuffer); |
211 | GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT1}; | 211 | GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT1}; |
212 | glDrawBuffers(1, DrawBuffers); | 212 | glDrawBuffers(1, DrawBuffers); |
213 | 213 | ||
214 | glGenRenderbuffers(1, &bloom_depthbuffer); | 214 | glGenRenderbuffers(1, &bloom_depthbuffer); |
215 | glBindRenderbuffer(GL_RENDERBUFFER, bloom_depthbuffer); | 215 | glBindRenderbuffer(GL_RENDERBUFFER, bloom_depthbuffer); |
216 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height); | 216 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height); |
217 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, bloom_depthbuffer); | 217 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, bloom_depthbuffer); |
218 | 218 | ||
219 | glDeleteTextures(1, &preBloomTex); | 219 | glDeleteTextures(1, &preBloomTex); |
220 | glDeleteTextures(1, &bloomPassTex1); | 220 | glDeleteTextures(1, &bloomPassTex1); |
221 | glDeleteTextures(1, &bloomPassTex2); | 221 | glDeleteTextures(1, &bloomPassTex2); |
222 | 222 | ||
223 | glGenTextures(1, &preBloomTex); | 223 | glGenTextures(1, &preBloomTex); |
224 | glBindTexture(GL_TEXTURE_2D, preBloomTex); | 224 | glBindTexture(GL_TEXTURE_2D, preBloomTex); |
225 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); | 225 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); |
@@ -227,7 +227,7 @@ void setFramebufferSize(GLFWwindow* w, int width, int height) | |||
227 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 227 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
228 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 228 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
229 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 229 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
230 | 230 | ||
231 | glGenTextures(1, &bloomPassTex1); | 231 | glGenTextures(1, &bloomPassTex1); |
232 | glBindTexture(GL_TEXTURE_2D, bloomPassTex1); | 232 | glBindTexture(GL_TEXTURE_2D, bloomPassTex1); |
233 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width/4, height/4, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); | 233 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width/4, height/4, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); |
@@ -235,7 +235,7 @@ void setFramebufferSize(GLFWwindow* w, int width, int height) | |||
235 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 235 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
236 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 236 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
237 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 237 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
238 | 238 | ||
239 | glGenTextures(1, &bloomPassTex2); | 239 | glGenTextures(1, &bloomPassTex2); |
240 | glBindTexture(GL_TEXTURE_2D, bloomPassTex2); | 240 | glBindTexture(GL_TEXTURE_2D, bloomPassTex2); |
241 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width/4, height/4, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); | 241 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width/4, height/4, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); |
@@ -252,20 +252,20 @@ GLFWwindow* initRenderer() | |||
252 | fprintf(stderr, "Renderer already initialized\n"); | 252 | fprintf(stderr, "Renderer already initialized\n"); |
253 | exit(-1); | 253 | exit(-1); |
254 | } | 254 | } |
255 | 255 | ||
256 | // Initialize GLFW | 256 | // Initialize GLFW |
257 | if (!glfwInit()) | 257 | if (!glfwInit()) |
258 | { | 258 | { |
259 | fprintf(stderr, "Failed to initialize GLFW\n"); | 259 | fprintf(stderr, "Failed to initialize GLFW\n"); |
260 | exit(-1); | 260 | exit(-1); |
261 | } | 261 | } |
262 | 262 | ||
263 | glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing | 263 | glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing |
264 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // We want version 3.3 | 264 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // We want version 3.3 |
265 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); | 265 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); |
266 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Mac requires this | 266 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Mac requires this |
267 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); | 267 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); |
268 | 268 | ||
269 | // Create a window | 269 | // Create a window |
270 | window = glfwCreateWindow(1024, 768, "Aromatherapy", nullptr, nullptr); | 270 | window = glfwCreateWindow(1024, 768, "Aromatherapy", nullptr, nullptr); |
271 | if (window == nullptr) | 271 | if (window == nullptr) |
@@ -274,7 +274,7 @@ GLFWwindow* initRenderer() | |||
274 | glfwTerminate(); | 274 | glfwTerminate(); |
275 | exit(-1); | 275 | exit(-1); |
276 | } | 276 | } |
277 | 277 | ||
278 | glfwMakeContextCurrent(window); | 278 | glfwMakeContextCurrent(window); |
279 | glewExperimental = true; // Needed in core profile | 279 | glewExperimental = true; // Needed in core profile |
280 | if (glewInit() != GLEW_OK) | 280 | if (glewInit() != GLEW_OK) |
@@ -282,37 +282,37 @@ GLFWwindow* initRenderer() | |||
282 | fprintf(stderr, "Failed to initialize GLEW\n"); | 282 | fprintf(stderr, "Failed to initialize GLEW\n"); |
283 | exit(-1); | 283 | exit(-1); |
284 | } | 284 | } |
285 | 285 | ||
286 | glfwSetFramebufferSizeCallback(window, &setFramebufferSize); | 286 | glfwSetFramebufferSizeCallback(window, &setFramebufferSize); |
287 | 287 | ||
288 | // Set up vertex array object | 288 | // Set up vertex array object |
289 | glGenVertexArrays(1, &VertexArrayID); | 289 | glGenVertexArrays(1, &VertexArrayID); |
290 | glBindVertexArray(VertexArrayID); | 290 | glBindVertexArray(VertexArrayID); |
291 | 291 | ||
292 | // Enable depth testing | 292 | // Enable depth testing |
293 | glEnable(GL_DEPTH_TEST); | 293 | glEnable(GL_DEPTH_TEST); |
294 | glDepthFunc(GL_LESS); | 294 | glDepthFunc(GL_LESS); |
295 | 295 | ||
296 | // Enable blending | 296 | // Enable blending |
297 | glEnable(GL_BLEND); | 297 | glEnable(GL_BLEND); |
298 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 298 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
299 | 299 | ||
300 | // Set up the framebuffer | 300 | // Set up the framebuffer |
301 | glGenFramebuffers(1, &generic_framebuffer); | 301 | glGenFramebuffers(1, &generic_framebuffer); |
302 | glBindFramebuffer(GL_FRAMEBUFFER, generic_framebuffer); | 302 | glBindFramebuffer(GL_FRAMEBUFFER, generic_framebuffer); |
303 | GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; | 303 | GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0}; |
304 | glDrawBuffers(1, DrawBuffers); | 304 | glDrawBuffers(1, DrawBuffers); |
305 | 305 | ||
306 | glGenFramebuffers(1, &bloom_framebuffer); | 306 | glGenFramebuffers(1, &bloom_framebuffer); |
307 | glBindFramebuffer(GL_FRAMEBUFFER, bloom_framebuffer); | 307 | glBindFramebuffer(GL_FRAMEBUFFER, bloom_framebuffer); |
308 | GLenum DrawBuffers2[1] = {GL_COLOR_ATTACHMENT1}; | 308 | GLenum DrawBuffers2[1] = {GL_COLOR_ATTACHMENT1}; |
309 | glDrawBuffers(1, DrawBuffers2); | 309 | glDrawBuffers(1, DrawBuffers2); |
310 | 310 | ||
311 | glGenRenderbuffers(1, &bloom_depthbuffer); | 311 | glGenRenderbuffers(1, &bloom_depthbuffer); |
312 | glBindRenderbuffer(GL_RENDERBUFFER, bloom_depthbuffer); | 312 | glBindRenderbuffer(GL_RENDERBUFFER, bloom_depthbuffer); |
313 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, 1024, 768); | 313 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, 1024, 768); |
314 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, bloom_depthbuffer); | 314 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, bloom_depthbuffer); |
315 | 315 | ||
316 | // Set up the NTSC rendering buffers | 316 | // Set up the NTSC rendering buffers |
317 | glGenTextures(1, &renderedTex1); | 317 | glGenTextures(1, &renderedTex1); |
318 | glBindTexture(GL_TEXTURE_2D, renderedTex1); | 318 | glBindTexture(GL_TEXTURE_2D, renderedTex1); |
@@ -322,7 +322,7 @@ GLFWwindow* initRenderer() | |||
322 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 322 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
323 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 323 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
324 | renderedTexBufs[0] = renderedTex1; | 324 | renderedTexBufs[0] = renderedTex1; |
325 | 325 | ||
326 | glGenTextures(1, &renderedTex2); | 326 | glGenTextures(1, &renderedTex2); |
327 | glBindTexture(GL_TEXTURE_2D, renderedTex2); | 327 | glBindTexture(GL_TEXTURE_2D, renderedTex2); |
328 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, GAME_WIDTH, GAME_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); | 328 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, GAME_WIDTH, GAME_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); |
@@ -331,7 +331,7 @@ GLFWwindow* initRenderer() | |||
331 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 331 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
332 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 332 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
333 | renderedTexBufs[1] = renderedTex2; | 333 | renderedTexBufs[1] = renderedTex2; |
334 | 334 | ||
335 | // Set up bloom rendering buffers | 335 | // Set up bloom rendering buffers |
336 | glGenTextures(1, &preBloomTex); | 336 | glGenTextures(1, &preBloomTex); |
337 | glBindTexture(GL_TEXTURE_2D, preBloomTex); | 337 | glBindTexture(GL_TEXTURE_2D, preBloomTex); |
@@ -340,7 +340,7 @@ GLFWwindow* initRenderer() | |||
340 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 340 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
341 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 341 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
342 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 342 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
343 | 343 | ||
344 | glGenTextures(1, &bloomPassTex1); | 344 | glGenTextures(1, &bloomPassTex1); |
345 | glBindTexture(GL_TEXTURE_2D, bloomPassTex1); | 345 | glBindTexture(GL_TEXTURE_2D, bloomPassTex1); |
346 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024/4, 768/4, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); | 346 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024/4, 768/4, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); |
@@ -348,7 +348,7 @@ GLFWwindow* initRenderer() | |||
348 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 348 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
349 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 349 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
350 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 350 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
351 | 351 | ||
352 | glGenTextures(1, &bloomPassTex2); | 352 | glGenTextures(1, &bloomPassTex2); |
353 | glBindTexture(GL_TEXTURE_2D, bloomPassTex2); | 353 | glBindTexture(GL_TEXTURE_2D, bloomPassTex2); |
354 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024/4, 768/4, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); | 354 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024/4, 768/4, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); |
@@ -356,31 +356,31 @@ GLFWwindow* initRenderer() | |||
356 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 356 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
357 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 357 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
358 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 358 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
359 | 359 | ||
360 | curBuf = 0; | 360 | curBuf = 0; |
361 | 361 | ||
362 | // Load the mesh! | 362 | // Load the mesh! |
363 | std::vector<glm::vec3> mesh_vertices; | 363 | std::vector<glm::vec3> mesh_vertices; |
364 | std::vector<glm::vec2> mesh_uvs; | 364 | std::vector<glm::vec2> mesh_uvs; |
365 | std::vector<glm::vec3> mesh_normals; | 365 | std::vector<glm::vec3> mesh_normals; |
366 | loadMesh("res/monitor-fef.obj", mesh_vertices, mesh_uvs, mesh_normals); | 366 | loadMesh("res/monitor-fef.obj", mesh_vertices, mesh_uvs, mesh_normals); |
367 | 367 | ||
368 | mesh_numvertices = mesh_vertices.size(); | 368 | mesh_numvertices = mesh_vertices.size(); |
369 | 369 | ||
370 | glGenBuffers(1, &mesh_vertexbuffer); | 370 | glGenBuffers(1, &mesh_vertexbuffer); |
371 | glBindBuffer(GL_ARRAY_BUFFER, mesh_vertexbuffer); | 371 | glBindBuffer(GL_ARRAY_BUFFER, mesh_vertexbuffer); |
372 | glBufferData(GL_ARRAY_BUFFER, mesh_vertices.size() * sizeof(glm::vec3), &mesh_vertices[0], GL_STATIC_DRAW); | 372 | glBufferData(GL_ARRAY_BUFFER, mesh_vertices.size() * sizeof(glm::vec3), &mesh_vertices[0], GL_STATIC_DRAW); |
373 | 373 | ||
374 | glGenBuffers(1, &mesh_uvbuffer); | 374 | glGenBuffers(1, &mesh_uvbuffer); |
375 | glBindBuffer(GL_ARRAY_BUFFER, mesh_uvbuffer); | 375 | glBindBuffer(GL_ARRAY_BUFFER, mesh_uvbuffer); |
376 | glBufferData(GL_ARRAY_BUFFER, mesh_uvs.size() * sizeof(glm::vec3), &mesh_uvs[0], GL_STATIC_DRAW); | 376 | glBufferData(GL_ARRAY_BUFFER, mesh_uvs.size() * sizeof(glm::vec3), &mesh_uvs[0], GL_STATIC_DRAW); |
377 | 377 | ||
378 | glGenBuffers(1, &mesh_normalbuffer); | 378 | glGenBuffers(1, &mesh_normalbuffer); |
379 | glBindBuffer(GL_ARRAY_BUFFER, mesh_normalbuffer); | 379 | glBindBuffer(GL_ARRAY_BUFFER, mesh_normalbuffer); |
380 | glBufferData(GL_ARRAY_BUFFER, mesh_normals.size() * sizeof(glm::vec3), &mesh_normals[0], GL_STATIC_DRAW); | 380 | glBufferData(GL_ARRAY_BUFFER, mesh_normals.size() * sizeof(glm::vec3), &mesh_normals[0], GL_STATIC_DRAW); |
381 | 381 | ||
382 | // Load the vertices of a flat surface | 382 | // Load the vertices of a flat surface |
383 | GLfloat g_quad_vertex_buffer_data[] = { | 383 | GLfloat g_quad_vertex_buffer_data[] = { |
384 | -1.0f, -1.0f, 0.0f, | 384 | -1.0f, -1.0f, 0.0f, |
385 | 1.0f, -1.0f, 0.0f, | 385 | 1.0f, -1.0f, 0.0f, |
386 | -1.0f, 1.0f, 0.0f, | 386 | -1.0f, 1.0f, 0.0f, |
@@ -392,7 +392,7 @@ GLFWwindow* initRenderer() | |||
392 | glGenBuffers(1, &quad_vertexbuffer); | 392 | glGenBuffers(1, &quad_vertexbuffer); |
393 | glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); | 393 | glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); |
394 | glBufferData(GL_ARRAY_BUFFER, sizeof(g_quad_vertex_buffer_data), g_quad_vertex_buffer_data, GL_STATIC_DRAW); | 394 | glBufferData(GL_ARRAY_BUFFER, sizeof(g_quad_vertex_buffer_data), g_quad_vertex_buffer_data, GL_STATIC_DRAW); |
395 | 395 | ||
396 | glGenTextures(1, &artifactsTex); | 396 | glGenTextures(1, &artifactsTex); |
397 | glBindTexture(GL_TEXTURE_2D, artifactsTex); | 397 | glBindTexture(GL_TEXTURE_2D, artifactsTex); |
398 | int atdw, atdh; | 398 | int atdw, atdh; |
@@ -403,7 +403,7 @@ GLFWwindow* initRenderer() | |||
403 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 403 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
404 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); | 404 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
405 | glGenerateMipmap(GL_TEXTURE_2D); | 405 | glGenerateMipmap(GL_TEXTURE_2D); |
406 | 406 | ||
407 | glGenTextures(1, &scanlinesTex); | 407 | glGenTextures(1, &scanlinesTex); |
408 | glBindTexture(GL_TEXTURE_2D, scanlinesTex); | 408 | glBindTexture(GL_TEXTURE_2D, scanlinesTex); |
409 | int stdw, stdh; | 409 | int stdw, stdh; |
@@ -414,7 +414,7 @@ GLFWwindow* initRenderer() | |||
414 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 414 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
415 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); | 415 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
416 | glGenerateMipmap(GL_TEXTURE_2D); | 416 | glGenerateMipmap(GL_TEXTURE_2D); |
417 | 417 | ||
418 | // Load the shaders | 418 | // Load the shaders |
419 | ntscShader = LoadShaders("shaders/ntsc.vertex", "shaders/ntsc.fragment"); | 419 | ntscShader = LoadShaders("shaders/ntsc.vertex", "shaders/ntsc.fragment"); |
420 | finalShader = LoadShaders("shaders/final.vertex", "shaders/final.fragment"); | 420 | finalShader = LoadShaders("shaders/final.vertex", "shaders/final.fragment"); |
@@ -422,9 +422,9 @@ GLFWwindow* initRenderer() | |||
422 | fillShader = LoadShaders("shaders/fill.vertex", "shaders/fill.fragment"); | 422 | fillShader = LoadShaders("shaders/fill.vertex", "shaders/fill.fragment"); |
423 | bloom1Shader = LoadShaders("shaders/bloom1.vertex", "shaders/bloom1.fragment"); | 423 | bloom1Shader = LoadShaders("shaders/bloom1.vertex", "shaders/bloom1.fragment"); |
424 | bloom2Shader = LoadShaders("shaders/bloom2.vertex", "shaders/bloom2.fragment"); | 424 | bloom2Shader = LoadShaders("shaders/bloom2.vertex", "shaders/bloom2.fragment"); |
425 | 425 | ||
426 | rendererInitialized = true; | 426 | rendererInitialized = true; |
427 | 427 | ||
428 | return window; | 428 | return window; |
429 | } | 429 | } |
430 | 430 | ||
@@ -435,13 +435,13 @@ void destroyRenderer() | |||
435 | fprintf(stderr, "Renderer not initialized\n"); | 435 | fprintf(stderr, "Renderer not initialized\n"); |
436 | exit(-1); | 436 | exit(-1); |
437 | } | 437 | } |
438 | 438 | ||
439 | // Delete the plane buffer | 439 | // Delete the plane buffer |
440 | glDeleteBuffers(1, &quad_vertexbuffer); | 440 | glDeleteBuffers(1, &quad_vertexbuffer); |
441 | glDeleteBuffers(1, &mesh_vertexbuffer); | 441 | glDeleteBuffers(1, &mesh_vertexbuffer); |
442 | glDeleteBuffers(1, &mesh_uvbuffer); | 442 | glDeleteBuffers(1, &mesh_uvbuffer); |
443 | glDeleteBuffers(1, &mesh_normalbuffer); | 443 | glDeleteBuffers(1, &mesh_normalbuffer); |
444 | 444 | ||
445 | // Delete the shaders | 445 | // Delete the shaders |
446 | glDeleteProgram(ntscShader); | 446 | glDeleteProgram(ntscShader); |
447 | glDeleteProgram(finalShader); | 447 | glDeleteProgram(finalShader); |
@@ -449,7 +449,7 @@ void destroyRenderer() | |||
449 | glDeleteProgram(fillShader); | 449 | glDeleteProgram(fillShader); |
450 | glDeleteProgram(bloom1Shader); | 450 | glDeleteProgram(bloom1Shader); |
451 | glDeleteProgram(bloom2Shader); | 451 | glDeleteProgram(bloom2Shader); |
452 | 452 | ||
453 | // Delete the NTSC rendering buffers | 453 | // Delete the NTSC rendering buffers |
454 | glDeleteTextures(1, &renderedTex1); | 454 | glDeleteTextures(1, &renderedTex1); |
455 | glDeleteTextures(1, &renderedTex2); | 455 | glDeleteTextures(1, &renderedTex2); |
@@ -458,18 +458,18 @@ void destroyRenderer() | |||
458 | glDeleteTextures(1, &preBloomTex); | 458 | glDeleteTextures(1, &preBloomTex); |
459 | glDeleteTextures(1, &bloomPassTex1); | 459 | glDeleteTextures(1, &bloomPassTex1); |
460 | glDeleteTextures(1, &bloomPassTex2); | 460 | glDeleteTextures(1, &bloomPassTex2); |
461 | 461 | ||
462 | // Delete the framebuffer | 462 | // Delete the framebuffer |
463 | glDeleteRenderbuffers(1, &bloom_depthbuffer); | 463 | glDeleteRenderbuffers(1, &bloom_depthbuffer); |
464 | glDeleteFramebuffers(1, &bloom_framebuffer); | 464 | glDeleteFramebuffers(1, &bloom_framebuffer); |
465 | glDeleteFramebuffers(1, &generic_framebuffer); | 465 | glDeleteFramebuffers(1, &generic_framebuffer); |
466 | 466 | ||
467 | // Delete the VAO | 467 | // Delete the VAO |
468 | glDeleteVertexArrays(1, &VertexArrayID); | 468 | glDeleteVertexArrays(1, &VertexArrayID); |
469 | 469 | ||
470 | // Kill the window | 470 | // Kill the window |
471 | glfwTerminate(); | 471 | glfwTerminate(); |
472 | 472 | ||
473 | rendererInitialized = false; | 473 | rendererInitialized = false; |
474 | } | 474 | } |
475 | 475 | ||
@@ -480,10 +480,10 @@ Texture::Texture(int width, int height) | |||
480 | fprintf(stderr, "Renderer not initialized\n"); | 480 | fprintf(stderr, "Renderer not initialized\n"); |
481 | exit(-1); | 481 | exit(-1); |
482 | } | 482 | } |
483 | 483 | ||
484 | this->width = width; | 484 | this->width = width; |
485 | this->height = height; | 485 | this->height = height; |
486 | 486 | ||
487 | glGenTextures(1, &texID); | 487 | glGenTextures(1, &texID); |
488 | glBindTexture(GL_TEXTURE_2D, texID); | 488 | glBindTexture(GL_TEXTURE_2D, texID); |
489 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); | 489 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); |
@@ -500,7 +500,7 @@ Texture::Texture(const char* filename) | |||
500 | fprintf(stderr, "Renderer not initialized\n"); | 500 | fprintf(stderr, "Renderer not initialized\n"); |
501 | exit(-1); | 501 | exit(-1); |
502 | } | 502 | } |
503 | 503 | ||
504 | glGenTextures(1, &texID); | 504 | glGenTextures(1, &texID); |
505 | glBindTexture(GL_TEXTURE_2D, texID); | 505 | glBindTexture(GL_TEXTURE_2D, texID); |
506 | unsigned char* data = stbi_load(filename, &width, &height, 0, 4); | 506 | unsigned char* data = stbi_load(filename, &width, &height, 0, 4); |
@@ -520,14 +520,14 @@ Texture::Texture(const Texture& tex) | |||
520 | fprintf(stderr, "Renderer not initialized\n"); | 520 | fprintf(stderr, "Renderer not initialized\n"); |
521 | exit(-1); | 521 | exit(-1); |
522 | } | 522 | } |
523 | 523 | ||
524 | width = tex.width; | 524 | width = tex.width; |
525 | height = tex.height; | 525 | height = tex.height; |
526 | 526 | ||
527 | unsigned char* data = (unsigned char*) malloc(4 * width * height); | 527 | unsigned char* data = (unsigned char*) malloc(4 * width * height); |
528 | glBindTexture(GL_TEXTURE_2D, tex.texID); | 528 | glBindTexture(GL_TEXTURE_2D, tex.texID); |
529 | glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); | 529 | glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); |
530 | 530 | ||
531 | glGenTextures(1, &texID); | 531 | glGenTextures(1, &texID); |
532 | glBindTexture(GL_TEXTURE_2D, texID); | 532 | glBindTexture(GL_TEXTURE_2D, texID); |
533 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); | 533 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); |
@@ -535,7 +535,7 @@ Texture::Texture(const Texture& tex) | |||
535 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 535 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
536 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 536 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
537 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 537 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
538 | 538 | ||
539 | free(data); | 539 | free(data); |
540 | } | 540 | } |
541 | 541 | ||
@@ -551,14 +551,14 @@ Texture::~Texture() | |||
551 | fprintf(stderr, "Renderer not initialized\n"); | 551 | fprintf(stderr, "Renderer not initialized\n"); |
552 | exit(-1); | 552 | exit(-1); |
553 | } | 553 | } |
554 | 554 | ||
555 | glDeleteTextures(1, &texID); | 555 | glDeleteTextures(1, &texID); |
556 | } | 556 | } |
557 | 557 | ||
558 | Texture& Texture::operator= (Texture tex) | 558 | Texture& Texture::operator= (Texture tex) |
559 | { | 559 | { |
560 | swap(*this, tex); | 560 | swap(*this, tex); |
561 | 561 | ||
562 | return *this; | 562 | return *this; |
563 | } | 563 | } |
564 | 564 | ||
@@ -576,17 +576,17 @@ void Texture::fill(Rectangle dstrect, int r, int g, int b) | |||
576 | fprintf(stderr, "Renderer not initialized\n"); | 576 | fprintf(stderr, "Renderer not initialized\n"); |
577 | exit(-1); | 577 | exit(-1); |
578 | } | 578 | } |
579 | 579 | ||
580 | // Target the framebuffer | 580 | // Target the framebuffer |
581 | glBindFramebuffer(GL_FRAMEBUFFER, generic_framebuffer); | 581 | glBindFramebuffer(GL_FRAMEBUFFER, generic_framebuffer); |
582 | glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texID, 0); | 582 | glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texID, 0); |
583 | 583 | ||
584 | // Set up the vertex attributes | 584 | // Set up the vertex attributes |
585 | GLfloat minx = (GLfloat) dstrect.x / width * 2.0 - 1.0; | 585 | GLfloat minx = (GLfloat) dstrect.x / width * 2.0 - 1.0; |
586 | GLfloat miny = -((GLfloat) dstrect.y / height * 2.0 - 1.0); | 586 | GLfloat miny = -((GLfloat) dstrect.y / height * 2.0 - 1.0); |
587 | GLfloat maxx = (GLfloat) (dstrect.x + dstrect.w) / width * 2.0 - 1.0; | 587 | GLfloat maxx = (GLfloat) (dstrect.x + dstrect.w) / width * 2.0 - 1.0; |
588 | GLfloat maxy = -((GLfloat) (dstrect.y + dstrect.h) / height * 2.0 - 1.0); | 588 | GLfloat maxy = -((GLfloat) (dstrect.y + dstrect.h) / height * 2.0 - 1.0); |
589 | 589 | ||
590 | GLfloat vertexbuffer_data[] = { | 590 | GLfloat vertexbuffer_data[] = { |
591 | minx, miny, | 591 | minx, miny, |
592 | maxx, miny, | 592 | maxx, miny, |
@@ -601,14 +601,14 @@ void Texture::fill(Rectangle dstrect, int r, int g, int b) | |||
601 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertexbuffer_data), vertexbuffer_data, GL_STATIC_DRAW); | 601 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertexbuffer_data), vertexbuffer_data, GL_STATIC_DRAW); |
602 | glEnableVertexAttribArray(0); | 602 | glEnableVertexAttribArray(0); |
603 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)0); | 603 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)0); |
604 | 604 | ||
605 | glViewport(0, 0, width, height); | 605 | glViewport(0, 0, width, height); |
606 | glClear(GL_DEPTH_BUFFER_BIT); | 606 | glClear(GL_DEPTH_BUFFER_BIT); |
607 | glUseProgram(fillShader); | 607 | glUseProgram(fillShader); |
608 | glUniform3f(glGetUniformLocation(fillShader, "vecColor"), r / 255.0, g / 255.0, b / 255.0); | 608 | glUniform3f(glGetUniformLocation(fillShader, "vecColor"), r / 255.0, g / 255.0, b / 255.0); |
609 | 609 | ||
610 | glDrawArrays(GL_TRIANGLES, 0, 6); | 610 | glDrawArrays(GL_TRIANGLES, 0, 6); |
611 | 611 | ||
612 | glDisableVertexAttribArray(0); | 612 | glDisableVertexAttribArray(0); |
613 | glDeleteBuffers(1, &vertexbuffer); | 613 | glDeleteBuffers(1, &vertexbuffer); |
614 | } | 614 | } |
@@ -620,19 +620,19 @@ void Texture::blit(const Texture& srctex, Rectangle srcrect, Rectangle dstrect, | |||
620 | fprintf(stderr, "Renderer not initialized\n"); | 620 | fprintf(stderr, "Renderer not initialized\n"); |
621 | exit(-1); | 621 | exit(-1); |
622 | } | 622 | } |
623 | 623 | ||
624 | alpha = glm::clamp(alpha, 0.0, 1.0); | 624 | alpha = glm::clamp(alpha, 0.0, 1.0); |
625 | 625 | ||
626 | // Target the framebuffer | 626 | // Target the framebuffer |
627 | glBindFramebuffer(GL_FRAMEBUFFER, generic_framebuffer); | 627 | glBindFramebuffer(GL_FRAMEBUFFER, generic_framebuffer); |
628 | glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texID, 0); | 628 | glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texID, 0); |
629 | 629 | ||
630 | // Set up the vertex attributes | 630 | // Set up the vertex attributes |
631 | GLfloat minx = (GLfloat) dstrect.x / width * 2.0 - 1.0; | 631 | GLfloat minx = (GLfloat) dstrect.x / width * 2.0 - 1.0; |
632 | GLfloat miny = -((GLfloat) dstrect.y / height * 2.0 - 1.0); | 632 | GLfloat miny = -((GLfloat) dstrect.y / height * 2.0 - 1.0); |
633 | GLfloat maxx = (GLfloat) (dstrect.x + dstrect.w) / width * 2.0 - 1.0; | 633 | GLfloat maxx = (GLfloat) (dstrect.x + dstrect.w) / width * 2.0 - 1.0; |
634 | GLfloat maxy = -((GLfloat) (dstrect.y + dstrect.h) / height * 2.0 - 1.0); | 634 | GLfloat maxy = -((GLfloat) (dstrect.y + dstrect.h) / height * 2.0 - 1.0); |
635 | 635 | ||
636 | GLfloat vertexbuffer_data[] = { | 636 | GLfloat vertexbuffer_data[] = { |
637 | minx, miny, | 637 | minx, miny, |
638 | maxx, miny, | 638 | maxx, miny, |
@@ -645,12 +645,12 @@ void Texture::blit(const Texture& srctex, Rectangle srcrect, Rectangle dstrect, | |||
645 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertexbuffer_data), vertexbuffer_data, GL_STATIC_DRAW); | 645 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertexbuffer_data), vertexbuffer_data, GL_STATIC_DRAW); |
646 | glEnableVertexAttribArray(0); | 646 | glEnableVertexAttribArray(0); |
647 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)0); | 647 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)0); |
648 | 648 | ||
649 | GLfloat minu = (GLfloat) srcrect.x / srctex.width; | 649 | GLfloat minu = (GLfloat) srcrect.x / srctex.width; |
650 | GLfloat minv = 1 - ((GLfloat) srcrect.y / srctex.height); | 650 | GLfloat minv = 1 - ((GLfloat) srcrect.y / srctex.height); |
651 | GLfloat maxu = (GLfloat) (srcrect.x + srcrect.w) / srctex.width; | 651 | GLfloat maxu = (GLfloat) (srcrect.x + srcrect.w) / srctex.width; |
652 | GLfloat maxv = 1 - ((GLfloat) (srcrect.y + srcrect.h) / srctex.height); | 652 | GLfloat maxv = 1 - ((GLfloat) (srcrect.y + srcrect.h) / srctex.height); |
653 | 653 | ||
654 | GLfloat texcoordbuffer_data[] = { | 654 | GLfloat texcoordbuffer_data[] = { |
655 | minu, minv, | 655 | minu, minv, |
656 | maxu, minv, | 656 | maxu, minv, |
@@ -663,20 +663,20 @@ void Texture::blit(const Texture& srctex, Rectangle srcrect, Rectangle dstrect, | |||
663 | glBufferData(GL_ARRAY_BUFFER, sizeof(texcoordbuffer_data), texcoordbuffer_data, GL_STATIC_DRAW); | 663 | glBufferData(GL_ARRAY_BUFFER, sizeof(texcoordbuffer_data), texcoordbuffer_data, GL_STATIC_DRAW); |
664 | glEnableVertexAttribArray(1); | 664 | glEnableVertexAttribArray(1); |
665 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0); | 665 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0); |
666 | 666 | ||
667 | // Set up the shader | 667 | // Set up the shader |
668 | glUseProgram(blitShader); | 668 | glUseProgram(blitShader); |
669 | glClear(GL_DEPTH_BUFFER_BIT); | 669 | glClear(GL_DEPTH_BUFFER_BIT); |
670 | glViewport(0, 0, width, height); | 670 | glViewport(0, 0, width, height); |
671 | 671 | ||
672 | glActiveTexture(GL_TEXTURE0); | 672 | glActiveTexture(GL_TEXTURE0); |
673 | glBindTexture(GL_TEXTURE_2D, srctex.texID); | 673 | glBindTexture(GL_TEXTURE_2D, srctex.texID); |
674 | glUniform1i(glGetUniformLocation(blitShader, "srctex"), 0); | 674 | glUniform1i(glGetUniformLocation(blitShader, "srctex"), 0); |
675 | glUniform1f(glGetUniformLocation(blitShader, "alpha"), alpha); | 675 | glUniform1f(glGetUniformLocation(blitShader, "alpha"), alpha); |
676 | 676 | ||
677 | // Blit! | 677 | // Blit! |
678 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | 678 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
679 | 679 | ||
680 | // Unload everything | 680 | // Unload everything |
681 | glDisableVertexAttribArray(1); | 681 | glDisableVertexAttribArray(1); |
682 | glDisableVertexAttribArray(0); | 682 | glDisableVertexAttribArray(0); |
@@ -691,11 +691,11 @@ void bloomPass1(GLuint srcTex, GLuint dstTex, bool horizontal, glm::vec2 srcRes, | |||
691 | glViewport(0,0,dstRes.x,dstRes.y); | 691 | glViewport(0,0,dstRes.x,dstRes.y); |
692 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 692 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
693 | glUseProgram(bloom1Shader); | 693 | glUseProgram(bloom1Shader); |
694 | 694 | ||
695 | glActiveTexture(GL_TEXTURE0); | 695 | glActiveTexture(GL_TEXTURE0); |
696 | glBindTexture(GL_TEXTURE_2D, srcTex); | 696 | glBindTexture(GL_TEXTURE_2D, srcTex); |
697 | glUniform1i(glGetUniformLocation(bloom1Shader, "inTex"), 0); | 697 | glUniform1i(glGetUniformLocation(bloom1Shader, "inTex"), 0); |
698 | 698 | ||
699 | glm::vec2 offset = glm::vec2(0.0); | 699 | glm::vec2 offset = glm::vec2(0.0); |
700 | if (horizontal) | 700 | if (horizontal) |
701 | { | 701 | { |
@@ -703,9 +703,9 @@ void bloomPass1(GLuint srcTex, GLuint dstTex, bool horizontal, glm::vec2 srcRes, | |||
703 | } else { | 703 | } else { |
704 | offset.y = 1.2/srcRes.y; | 704 | offset.y = 1.2/srcRes.y; |
705 | } | 705 | } |
706 | 706 | ||
707 | glUniform2f(glGetUniformLocation(bloom1Shader, "offset"), offset.x, offset.y); | 707 | glUniform2f(glGetUniformLocation(bloom1Shader, "offset"), offset.x, offset.y); |
708 | 708 | ||
709 | glEnableVertexAttribArray(0); | 709 | glEnableVertexAttribArray(0); |
710 | glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); | 710 | glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); |
711 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); | 711 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); |
@@ -720,17 +720,17 @@ void Texture::renderScreen() const | |||
720 | fprintf(stderr, "Renderer not initialized\n"); | 720 | fprintf(stderr, "Renderer not initialized\n"); |
721 | exit(-1); | 721 | exit(-1); |
722 | } | 722 | } |
723 | 723 | ||
724 | // First we're going to composite our frame with the previous frame | 724 | // First we're going to composite our frame with the previous frame |
725 | // We start by setting up the framebuffer | 725 | // We start by setting up the framebuffer |
726 | glBindFramebuffer(GL_FRAMEBUFFER, generic_framebuffer); | 726 | glBindFramebuffer(GL_FRAMEBUFFER, generic_framebuffer); |
727 | glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexBufs[curBuf], 0); | 727 | glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexBufs[curBuf], 0); |
728 | 728 | ||
729 | // Set up the shader | 729 | // Set up the shader |
730 | glViewport(0,0,GAME_WIDTH,GAME_HEIGHT); | 730 | glViewport(0,0,GAME_WIDTH,GAME_HEIGHT); |
731 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 731 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
732 | glUseProgram(ntscShader); | 732 | glUseProgram(ntscShader); |
733 | 733 | ||
734 | // Use the current frame texture, nearest neighbor and clamped to edge | 734 | // Use the current frame texture, nearest neighbor and clamped to edge |
735 | glActiveTexture(GL_TEXTURE0); | 735 | glActiveTexture(GL_TEXTURE0); |
736 | glBindTexture(GL_TEXTURE_2D, texID); | 736 | glBindTexture(GL_TEXTURE_2D, texID); |
@@ -739,7 +739,7 @@ void Texture::renderScreen() const | |||
739 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 739 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
740 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 740 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
741 | glUniform1i(glGetUniformLocation(ntscShader, "curFrameSampler"), 0); | 741 | glUniform1i(glGetUniformLocation(ntscShader, "curFrameSampler"), 0); |
742 | 742 | ||
743 | // Use the previous frame composite texture, nearest neighbor and clamped to edge | 743 | // Use the previous frame composite texture, nearest neighbor and clamped to edge |
744 | glActiveTexture(GL_TEXTURE1); | 744 | glActiveTexture(GL_TEXTURE1); |
745 | glBindTexture(GL_TEXTURE_2D, renderedTexBufs[(curBuf + 1) % 2]); | 745 | glBindTexture(GL_TEXTURE_2D, renderedTexBufs[(curBuf + 1) % 2]); |
@@ -748,13 +748,13 @@ void Texture::renderScreen() const | |||
748 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 748 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
749 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 749 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
750 | glUniform1i(glGetUniformLocation(ntscShader, "prevFrameSampler"), 1); | 750 | glUniform1i(glGetUniformLocation(ntscShader, "prevFrameSampler"), 1); |
751 | 751 | ||
752 | // Load the NTSC artifact texture | 752 | // Load the NTSC artifact texture |
753 | glActiveTexture(GL_TEXTURE2); | 753 | glActiveTexture(GL_TEXTURE2); |
754 | glBindTexture(GL_TEXTURE_2D, artifactsTex); | 754 | glBindTexture(GL_TEXTURE_2D, artifactsTex); |
755 | glUniform1i(glGetUniformLocation(ntscShader, "NTSCArtifactSampler"), 2); | 755 | glUniform1i(glGetUniformLocation(ntscShader, "NTSCArtifactSampler"), 2); |
756 | glUniform1f(glGetUniformLocation(ntscShader, "NTSCLerp"), curBuf * 1.0); | 756 | glUniform1f(glGetUniformLocation(ntscShader, "NTSCLerp"), curBuf * 1.0); |
757 | 757 | ||
758 | if ((rand() % 60) == 0) | 758 | if ((rand() % 60) == 0) |
759 | { | 759 | { |
760 | // Change the 0.0 to a 1.0 or a 10.0 for a glitchy effect! | 760 | // Change the 0.0 to a 1.0 or a 10.0 for a glitchy effect! |
@@ -762,7 +762,7 @@ void Texture::renderScreen() const | |||
762 | } else { | 762 | } else { |
763 | glUniform1f(glGetUniformLocation(ntscShader, "Tuning_NTSC"), 0.0); | 763 | glUniform1f(glGetUniformLocation(ntscShader, "Tuning_NTSC"), 0.0); |
764 | } | 764 | } |
765 | 765 | ||
766 | // Render our composition | 766 | // Render our composition |
767 | glEnableVertexAttribArray(0); | 767 | glEnableVertexAttribArray(0); |
768 | glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); | 768 | glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); |
@@ -776,7 +776,7 @@ void Texture::renderScreen() const | |||
776 | glViewport(0,0,buffer_width,buffer_height); | 776 | glViewport(0,0,buffer_width,buffer_height); |
777 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 777 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
778 | glUseProgram(finalShader); | 778 | glUseProgram(finalShader); |
779 | 779 | ||
780 | // Use the composited frame texture, linearly filtered and filling in black for the border | 780 | // Use the composited frame texture, linearly filtered and filling in black for the border |
781 | glActiveTexture(GL_TEXTURE0); | 781 | glActiveTexture(GL_TEXTURE0); |
782 | glBindTexture(GL_TEXTURE_2D, renderedTexBufs[curBuf]); | 782 | glBindTexture(GL_TEXTURE_2D, renderedTexBufs[curBuf]); |
@@ -788,69 +788,69 @@ void Texture::renderScreen() const | |||
788 | glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border_color); | 788 | glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border_color); |
789 | glGenerateMipmap(GL_TEXTURE_2D); | 789 | glGenerateMipmap(GL_TEXTURE_2D); |
790 | glUniform1i(glGetUniformLocation(finalShader, "rendertex"), 0); | 790 | glUniform1i(glGetUniformLocation(finalShader, "rendertex"), 0); |
791 | 791 | ||
792 | // Use the scanlines texture | 792 | // Use the scanlines texture |
793 | glActiveTexture(GL_TEXTURE1); | 793 | glActiveTexture(GL_TEXTURE1); |
794 | glBindTexture(GL_TEXTURE_2D, scanlinesTex); | 794 | glBindTexture(GL_TEXTURE_2D, scanlinesTex); |
795 | glUniform1i(glGetUniformLocation(finalShader, "scanlinestex"), 1); | 795 | glUniform1i(glGetUniformLocation(finalShader, "scanlinestex"), 1); |
796 | 796 | ||
797 | // Initialize the MVP matrices | 797 | // Initialize the MVP matrices |
798 | glm::mat4 p_matrix = glm::perspective(42.5f, (float) buffer_width / (float) buffer_height, 0.1f, 100.0f); | 798 | glm::mat4 p_matrix = glm::perspective(42.5f, (float) buffer_width / (float) buffer_height, 0.1f, 100.0f); |
799 | glm::mat4 v_matrix = glm::lookAt(glm::vec3(2,0,0), glm::vec3(0,0,0), glm::vec3(0,1,0)); | 799 | glm::mat4 v_matrix = glm::lookAt(glm::vec3(2,0,0), glm::vec3(0,0,0), glm::vec3(0,1,0)); |
800 | glm::mat4 m_matrix = glm::mat4(1.0); | 800 | glm::mat4 m_matrix = glm::mat4(1.0); |
801 | glm::mat4 mvp_matrix = p_matrix * v_matrix * m_matrix; | 801 | glm::mat4 mvp_matrix = p_matrix * v_matrix * m_matrix; |
802 | 802 | ||
803 | glUniformMatrix4fv(glGetUniformLocation(finalShader, "MVP"), 1, GL_FALSE, &mvp_matrix[0][0]); | 803 | glUniformMatrix4fv(glGetUniformLocation(finalShader, "MVP"), 1, GL_FALSE, &mvp_matrix[0][0]); |
804 | glUniformMatrix4fv(glGetUniformLocation(finalShader, "worldMat"), 1, GL_FALSE, &m_matrix[0][0]); | 804 | glUniformMatrix4fv(glGetUniformLocation(finalShader, "worldMat"), 1, GL_FALSE, &m_matrix[0][0]); |
805 | glUniform2f(glGetUniformLocation(finalShader, "resolution"), buffer_width, buffer_height); | 805 | glUniform2f(glGetUniformLocation(finalShader, "resolution"), buffer_width, buffer_height); |
806 | glUniform1f(glGetUniformLocation(finalShader, "iGlobalTime"), glfwGetTime()); | 806 | glUniform1f(glGetUniformLocation(finalShader, "iGlobalTime"), glfwGetTime()); |
807 | 807 | ||
808 | glEnableVertexAttribArray(0); | 808 | glEnableVertexAttribArray(0); |
809 | glBindBuffer(GL_ARRAY_BUFFER, mesh_vertexbuffer); | 809 | glBindBuffer(GL_ARRAY_BUFFER, mesh_vertexbuffer); |
810 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); | 810 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); |
811 | 811 | ||
812 | glEnableVertexAttribArray(1); | 812 | glEnableVertexAttribArray(1); |
813 | glBindBuffer(GL_ARRAY_BUFFER, mesh_normalbuffer); | 813 | glBindBuffer(GL_ARRAY_BUFFER, mesh_normalbuffer); |
814 | glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); | 814 | glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); |
815 | 815 | ||
816 | glEnableVertexAttribArray(2); | 816 | glEnableVertexAttribArray(2); |
817 | glBindBuffer(GL_ARRAY_BUFFER, mesh_uvbuffer); | 817 | glBindBuffer(GL_ARRAY_BUFFER, mesh_uvbuffer); |
818 | glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (void*)0); | 818 | glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (void*)0); |
819 | 819 | ||
820 | glDrawArrays(GL_TRIANGLES, 0, mesh_numvertices); | 820 | glDrawArrays(GL_TRIANGLES, 0, mesh_numvertices); |
821 | glDisableVertexAttribArray(2); | 821 | glDisableVertexAttribArray(2); |
822 | glDisableVertexAttribArray(1); | 822 | glDisableVertexAttribArray(1); |
823 | glDisableVertexAttribArray(0); | 823 | glDisableVertexAttribArray(0); |
824 | 824 | ||
825 | // First pass of bloom! | 825 | // First pass of bloom! |
826 | glm::vec2 buffer_size = glm::vec2(buffer_width, buffer_height); | 826 | glm::vec2 buffer_size = glm::vec2(buffer_width, buffer_height); |
827 | bloomPass1(preBloomTex, bloomPassTex1, true, buffer_size, buffer_size / 4.0f); | 827 | bloomPass1(preBloomTex, bloomPassTex1, true, buffer_size, buffer_size / 4.0f); |
828 | bloomPass1(bloomPassTex1, bloomPassTex2, false, buffer_size / 4.0f, buffer_size / 4.0f); | 828 | bloomPass1(bloomPassTex1, bloomPassTex2, false, buffer_size / 4.0f, buffer_size / 4.0f); |
829 | 829 | ||
830 | // Do the second pass of bloom and render to screen | 830 | // Do the second pass of bloom and render to screen |
831 | glBindFramebuffer(GL_FRAMEBUFFER, 0); | 831 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
832 | glViewport(0, 0, buffer_width, buffer_height); | 832 | glViewport(0, 0, buffer_width, buffer_height); |
833 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 833 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
834 | glUseProgram(bloom2Shader); | 834 | glUseProgram(bloom2Shader); |
835 | 835 | ||
836 | glActiveTexture(GL_TEXTURE0); | 836 | glActiveTexture(GL_TEXTURE0); |
837 | glBindTexture(GL_TEXTURE_2D, preBloomTex); | 837 | glBindTexture(GL_TEXTURE_2D, preBloomTex); |
838 | glUniform1i(glGetUniformLocation(bloom2Shader, "clearTex"), 0); | 838 | glUniform1i(glGetUniformLocation(bloom2Shader, "clearTex"), 0); |
839 | 839 | ||
840 | glActiveTexture(GL_TEXTURE1); | 840 | glActiveTexture(GL_TEXTURE1); |
841 | glBindTexture(GL_TEXTURE_2D, bloomPassTex2); | 841 | glBindTexture(GL_TEXTURE_2D, bloomPassTex2); |
842 | glUniform1i(glGetUniformLocation(bloom2Shader, "blurTex"), 1); | 842 | glUniform1i(glGetUniformLocation(bloom2Shader, "blurTex"), 1); |
843 | 843 | ||
844 | glUniform1f(glGetUniformLocation(bloom2Shader, "iGlobalTime"), glfwGetTime()); | 844 | glUniform1f(glGetUniformLocation(bloom2Shader, "iGlobalTime"), glfwGetTime()); |
845 | 845 | ||
846 | glEnableVertexAttribArray(0); | 846 | glEnableVertexAttribArray(0); |
847 | glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); | 847 | glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); |
848 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); | 848 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); |
849 | glDrawArrays(GL_TRIANGLES, 0, 6); | 849 | glDrawArrays(GL_TRIANGLES, 0, 6); |
850 | glDisableVertexAttribArray(0); | 850 | glDisableVertexAttribArray(0); |
851 | 851 | ||
852 | glfwSwapBuffers(window); | 852 | glfwSwapBuffers(window); |
853 | 853 | ||
854 | curBuf = (curBuf + 1) % 2; | 854 | curBuf = (curBuf + 1) % 2; |
855 | } | 855 | } |
856 | 856 | ||
diff --git a/src/renderer.h b/src/renderer.h index 84ad688..6dccf7a 100644 --- a/src/renderer.h +++ b/src/renderer.h | |||
@@ -24,7 +24,7 @@ class Texture { | |||
24 | void blit(const Texture& src, Rectangle srcrect, Rectangle dstrect, double alpha = 1.0); | 24 | void blit(const Texture& src, Rectangle srcrect, Rectangle dstrect, double alpha = 1.0); |
25 | void renderScreen() const; | 25 | void renderScreen() const; |
26 | Rectangle entirety() const; | 26 | Rectangle entirety() const; |
27 | 27 | ||
28 | private: | 28 | private: |
29 | GLuint texID; | 29 | GLuint texID; |
30 | int width; | 30 | int width; |
diff --git a/src/system.h b/src/system.h index e08db0a..af3fb77 100644 --- a/src/system.h +++ b/src/system.h | |||
@@ -7,9 +7,9 @@ class System { | |||
7 | public: | 7 | public: |
8 | System(Game& game) | 8 | System(Game& game) |
9 | : game(game) {} | 9 | : game(game) {} |
10 | 10 | ||
11 | virtual void tick(double dt) = 0; | 11 | virtual void tick(double dt) = 0; |
12 | 12 | ||
13 | protected: | 13 | protected: |
14 | Game& game; | 14 | Game& game; |
15 | }; | 15 | }; |
diff --git a/src/system_manager.h b/src/system_manager.h index 8f76db2..087b71c 100644 --- a/src/system_manager.h +++ b/src/system_manager.h | |||
@@ -18,18 +18,18 @@ class SystemManager { | |||
18 | { | 18 | { |
19 | std::unique_ptr<T> ptr = std::unique_ptr<T>(new T(game, std::forward<Args>(args)...)); | 19 | std::unique_ptr<T> ptr = std::unique_ptr<T>(new T(game, std::forward<Args>(args)...)); |
20 | std::type_index systemType = typeid(T); | 20 | std::type_index systemType = typeid(T); |
21 | 21 | ||
22 | systems[systemType] = ptr.get(); | 22 | systems[systemType] = ptr.get(); |
23 | loop.push_back(std::move(ptr)); | 23 | loop.push_back(std::move(ptr)); |
24 | } | 24 | } |
25 | 25 | ||
26 | template <class T> | 26 | template <class T> |
27 | T& getSystem() | 27 | T& getSystem() |
28 | { | 28 | { |
29 | std::type_index systemType = typeid(T); | 29 | std::type_index systemType = typeid(T); |
30 | 30 | ||
31 | assert(systems.count(systemType) == 1); | 31 | assert(systems.count(systemType) == 1); |
32 | 32 | ||
33 | return *((T*)systems[systemType]); | 33 | return *((T*)systems[systemType]); |
34 | } | 34 | } |
35 | }; | 35 | }; |
diff --git a/src/systems/controlling.cpp b/src/systems/controlling.cpp index b1e73ad..456da3b 100644 --- a/src/systems/controlling.cpp +++ b/src/systems/controlling.cpp | |||
@@ -14,12 +14,12 @@ void ControllingSystem::tick(double dt) | |||
14 | { | 14 | { |
15 | int key = actions.front().first; | 15 | int key = actions.front().first; |
16 | int action = actions.front().second; | 16 | int action = actions.front().second; |
17 | 17 | ||
18 | auto entities = game.getEntityManager().getEntitiesWithComponents<ControllableComponent, PonderableComponent, AnimatableComponent, DroppableComponent>(); | 18 | auto entities = game.getEntityManager().getEntitiesWithComponents<ControllableComponent, PonderableComponent, AnimatableComponent, DroppableComponent>(); |
19 | for (auto entity : entities) | 19 | for (auto entity : entities) |
20 | { | 20 | { |
21 | auto& controllable = game.getEntityManager().getComponent<ControllableComponent>(entity); | 21 | auto& controllable = game.getEntityManager().getComponent<ControllableComponent>(entity); |
22 | 22 | ||
23 | if (action == GLFW_PRESS) | 23 | if (action == GLFW_PRESS) |
24 | { | 24 | { |
25 | if (key == controllable.getLeftKey()) | 25 | if (key == controllable.getLeftKey()) |
@@ -33,7 +33,7 @@ void ControllingSystem::tick(double dt) | |||
33 | } else if (key == controllable.getRightKey()) | 33 | } else if (key == controllable.getRightKey()) |
34 | { | 34 | { |
35 | controllable.setHoldingRight(true); | 35 | controllable.setHoldingRight(true); |
36 | 36 | ||
37 | if (!controllable.isFrozen()) | 37 | if (!controllable.isFrozen()) |
38 | { | 38 | { |
39 | walkRight(entity); | 39 | walkRight(entity); |
@@ -56,7 +56,7 @@ void ControllingSystem::tick(double dt) | |||
56 | if (key == controllable.getLeftKey()) | 56 | if (key == controllable.getLeftKey()) |
57 | { | 57 | { |
58 | controllable.setHoldingLeft(false); | 58 | controllable.setHoldingLeft(false); |
59 | 59 | ||
60 | if (!controllable.isFrozen()) | 60 | if (!controllable.isFrozen()) |
61 | { | 61 | { |
62 | if (controllable.isHoldingRight()) | 62 | if (controllable.isHoldingRight()) |
@@ -69,7 +69,7 @@ void ControllingSystem::tick(double dt) | |||
69 | } else if (key == controllable.getRightKey()) | 69 | } else if (key == controllable.getRightKey()) |
70 | { | 70 | { |
71 | controllable.setHoldingRight(false); | 71 | controllable.setHoldingRight(false); |
72 | 72 | ||
73 | if (!controllable.isFrozen()) | 73 | if (!controllable.isFrozen()) |
74 | { | 74 | { |
75 | if (controllable.isHoldingRight()) | 75 | if (controllable.isHoldingRight()) |
@@ -94,7 +94,7 @@ void ControllingSystem::tick(double dt) | |||
94 | } | 94 | } |
95 | } | 95 | } |
96 | } | 96 | } |
97 | 97 | ||
98 | actions.pop(); | 98 | actions.pop(); |
99 | } | 99 | } |
100 | } | 100 | } |
diff --git a/src/systems/controlling.h b/src/systems/controlling.h index 61f86eb..30210b3 100644 --- a/src/systems/controlling.h +++ b/src/systems/controlling.h | |||
@@ -8,10 +8,10 @@ class ControllingSystem : public System { | |||
8 | public: | 8 | public: |
9 | ControllingSystem(Game& game) | 9 | ControllingSystem(Game& game) |
10 | : System(game) {} | 10 | : System(game) {} |
11 | 11 | ||
12 | void tick(double dt); | 12 | void tick(double dt); |
13 | void input(int key, int action); | 13 | void input(int key, int action); |
14 | 14 | ||
15 | private: | 15 | private: |
16 | void walkLeft(int entity); | 16 | void walkLeft(int entity); |
17 | void walkRight(int entity); | 17 | void walkRight(int entity); |
@@ -19,7 +19,7 @@ class ControllingSystem : public System { | |||
19 | void jump(int entity); | 19 | void jump(int entity); |
20 | void stopJumping(int entity); | 20 | void stopJumping(int entity); |
21 | void drop(int entity, bool start); | 21 | void drop(int entity, bool start); |
22 | 22 | ||
23 | std::queue<std::pair<int,int>> actions; | 23 | std::queue<std::pair<int,int>> actions; |
24 | }; | 24 | }; |
25 | 25 | ||
diff --git a/src/systems/pondering.cpp b/src/systems/pondering.cpp index 96775d0..50a8bc8 100644 --- a/src/systems/pondering.cpp +++ b/src/systems/pondering.cpp | |||
@@ -6,16 +6,16 @@ | |||
6 | void PonderingSystem::tick(double dt) | 6 | void PonderingSystem::tick(double dt) |
7 | { | 7 | { |
8 | auto entities = game.getEntityManager().getEntitiesWithComponents<PonderableComponent, TransformableComponent>(); | 8 | auto entities = game.getEntityManager().getEntitiesWithComponents<PonderableComponent, TransformableComponent>(); |
9 | 9 | ||
10 | for (auto entity : entities) | 10 | for (auto entity : entities) |
11 | { | 11 | { |
12 | auto& transformable = game.getEntityManager().getComponent<TransformableComponent>(entity); | 12 | auto& transformable = game.getEntityManager().getComponent<TransformableComponent>(entity); |
13 | auto& ponderable = game.getEntityManager().getComponent<PonderableComponent>(entity); | 13 | auto& ponderable = game.getEntityManager().getComponent<PonderableComponent>(entity); |
14 | 14 | ||
15 | // Accelerate | 15 | // Accelerate |
16 | ponderable.setVelocityX(ponderable.getVelocityX() + ponderable.getAccelX() * dt); | 16 | ponderable.setVelocityX(ponderable.getVelocityX() + ponderable.getAccelX() * dt); |
17 | ponderable.setVelocityY(ponderable.getVelocityY() + ponderable.getAccelY() * dt); | 17 | ponderable.setVelocityY(ponderable.getVelocityY() + ponderable.getAccelY() * dt); |
18 | 18 | ||
19 | // Move | 19 | // Move |
20 | transformable.setX(transformable.getX() + ponderable.getVelocityX() * dt); | 20 | transformable.setX(transformable.getX() + ponderable.getVelocityX() * dt); |
21 | transformable.setY(transformable.getY() + ponderable.getVelocityY() * dt); | 21 | transformable.setY(transformable.getY() + ponderable.getVelocityY() * dt); |
diff --git a/src/systems/pondering.h b/src/systems/pondering.h index ad01a22..3fe5473 100644 --- a/src/systems/pondering.h +++ b/src/systems/pondering.h | |||
@@ -7,7 +7,7 @@ class PonderingSystem : public System { | |||
7 | public: | 7 | public: |
8 | PonderingSystem(Game& game) | 8 | PonderingSystem(Game& game) |
9 | : System(game) {} | 9 | : System(game) {} |
10 | 10 | ||
11 | void tick(double dt); | 11 | void tick(double dt); |
12 | }; | 12 | }; |
13 | 13 | ||
diff --git a/src/systems/rendering.h b/src/systems/rendering.h index 9b6e27e..cec72e2 100644 --- a/src/systems/rendering.h +++ b/src/systems/rendering.h | |||
@@ -9,9 +9,9 @@ class RenderingSystem : public System { | |||
9 | public: | 9 | public: |
10 | RenderingSystem(Game& game) | 10 | RenderingSystem(Game& game) |
11 | : System(game) {} | 11 | : System(game) {} |
12 | 12 | ||
13 | void tick(double dt); | 13 | void tick(double dt); |
14 | 14 | ||
15 | private: | 15 | private: |
16 | Texture texture {GAME_WIDTH, GAME_HEIGHT}; | 16 | Texture texture {GAME_WIDTH, GAME_HEIGHT}; |
17 | }; | 17 | }; |