summaryrefslogtreecommitdiffstats
path: root/Project/Renderer.cpp
diff options
context:
space:
mode:
authorThales Lima Oliveira <thaleslima.ufu@gmail.com>2020-07-07 23:12:04 -0300
committerThales Lima Oliveira <thaleslima.ufu@gmail.com>2020-07-07 23:12:04 -0300
commitab30228b1a57053323363674fa7f137c0329a180 (patch)
tree50849a3680d61a2428665cc1035f1f4215870acb /Project/Renderer.cpp
parent6c0e98a2727d07e1fbb38b78c27d68e98ad09465 (diff)
downloadPSP.git-ab30228b1a57053323363674fa7f137c0329a180.tar.gz
PSP.git-ab30228b1a57053323363674fa7f137c0329a180.tar.xz
PSP.git-ab30228b1a57053323363674fa7f137c0329a180.zip
Voltage heat map implemented
Voltage heat map implemented using modern OpenGL =) New external library required: -GLEW -GLFW -GLM (incorporeted at the source) Old memory leaks fixed =)
Diffstat (limited to 'Project/Renderer.cpp')
-rw-r--r--Project/Renderer.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/Project/Renderer.cpp b/Project/Renderer.cpp
new file mode 100644
index 0000000..8a80686
--- /dev/null
+++ b/Project/Renderer.cpp
@@ -0,0 +1,77 @@
+#include "Renderer.h"
+#include <wx/msgdlg.h>
+#include <wx/string.h>
+
+#include <fstream>
+#include <sstream>
+#include <string>
+
+void GLClearError()
+{
+ while (glGetError() != GL_NO_ERROR);
+}
+
+bool GLCheckError()
+{
+ while (GLenum error = glGetError())
+ {
+ wxMessageBox(wxString::Format("[OpenGL error (%X)]", error));
+ return false;
+ }
+ return true;
+}
+
+void Renderer::Draw(const VertexArray& va, const IndexBuffer& ib, const Shader& shader) const
+{
+ // Set shader
+ shader.Bind();
+ //shader.SetUniform4f("u_Color", colourVec4[0], colourVec4[1], colourVec4[2], colourVec4[3]);
+
+ // Bind vertex array object
+ va.Bind();
+
+ // Bind index buffer
+ ib.Bind();
+
+ GLCall(glDrawElements(GL_TRIANGLES, ib.GetCount(), GL_UNSIGNED_INT, nullptr));
+}
+
+void Renderer::Clear()
+{
+ GLCall(glClear(GL_COLOR_BUFFER_BIT));
+}
+
+void Renderer::Ortho2D(float* mat, float left, float right, float bottom, float top)
+{
+ // this is basically from
+ // http://en.wikipedia.org/wiki/Orthographic_projection_(geometry)
+ const float zNear = -1.0f;
+ const float zFar = 1.0f;
+ const float inv_z = 1.0f / (zFar - zNear);
+ const float inv_y = 1.0f / (top - bottom);
+ const float inv_x = 1.0f / (right - left);
+
+ //first column
+ *mat++ = (2.0f * inv_x);
+ *mat++ = (0.0f);
+ *mat++ = (0.0f);
+ *mat++ = (0.0f);
+
+ //second
+ *mat++ = (0.0f);
+ *mat++ = (2.0 * inv_y);
+ *mat++ = (0.0f);
+ *mat++ = (0.0f);
+
+ //third
+ *mat++ = (0.0f);
+ *mat++ = (0.0f);
+ *mat++ = (-2.0f * inv_z);
+ *mat++ = (0.0f);
+
+ //fourth
+ *mat++ = (-(right + left) * inv_x);
+ *mat++ = (-(top + bottom) * inv_y);
+ *mat++ = (-(zFar + zNear) * inv_z);
+ *mat++ = (1.0f);
+}