diff options
author | majortom6 <tombarrett@siu.edu> | 2017-02-19 09:17:35 -0600 |
---|---|---|
committer | Tom Barrett <tombarrett@siu.edu> | 2017-03-07 13:23:41 -0600 |
commit | 5c46e0f0a924989201c6784b0f956bc442f14a7e (patch) | |
tree | 33b5889b872023bd7d414f7baec45706330813b3 /inc/opengl | |
parent | 2cc21176467d4501adb7bfb9ee03eb9a2a7d14f2 (diff) |
-removed glm library, its in the debian repos
-made opengl and sdl folders in includes, moved various *hpps to them
Diffstat (limited to 'inc/opengl')
-rw-r--r-- | inc/opengl/camera.hpp | 57 | ||||
-rw-r--r-- | inc/opengl/geoshader.hpp | 30 | ||||
-rw-r--r-- | inc/opengl/graphicsdata.hpp | 49 | ||||
-rw-r--r-- | inc/opengl/rectdrawer.hpp | 47 | ||||
-rw-r--r-- | inc/opengl/shaders/basicshader.frag (renamed from inc/opengl/basicshader.frag) | 0 | ||||
-rw-r--r-- | inc/opengl/shaders/basicshader.geom (renamed from inc/opengl/basicshader.geom) | 0 | ||||
-rw-r--r-- | inc/opengl/shaders/basicshader.vert (renamed from inc/opengl/basicshader.vert) | 0 | ||||
-rw-r--r-- | inc/opengl/shaders/theshader.frag (renamed from inc/opengl/theshader.frag) | 0 | ||||
-rw-r--r-- | inc/opengl/shaders/theshader.geom (renamed from inc/opengl/theshader.geom) | 0 | ||||
-rw-r--r-- | inc/opengl/shaders/theshader.vert (renamed from inc/opengl/theshader.vert) | 0 | ||||
-rw-r--r-- | inc/opengl/spritebatch.hpp | 63 | ||||
-rw-r--r-- | inc/opengl/transform.hpp | 52 |
12 files changed, 298 insertions, 0 deletions
diff --git a/inc/opengl/camera.hpp b/inc/opengl/camera.hpp new file mode 100644 index 0000000..62ae837 --- /dev/null +++ b/inc/opengl/camera.hpp @@ -0,0 +1,57 @@ +#ifndef camera_h +#define camera_h + +struct Camera +{ + public: + Camera(const glm::vec3& pos, float fov, float aspect, float zNear, float zFar){ + this->pos = pos; + this->forward = glm::vec3(0.0f, 0.0f, -1.0f); + this->up = glm::vec3(0.0f, 1.0f, 0.0f); + this->projection = glm::perspective(fov, aspect, zNear, zFar); + } + + inline glm::mat4 GetViewProjection() const { + return projection * glm::lookAt(pos, pos + forward, up); + } + + void MoveForward(){ + pos += forward * amt; + } + + void MoveBackward(){ + pos += forward * -amt; + } + + void MoveRight(){ + pos += -glm::cross(up, forward) * amt; + } + + void MoveLeft(){ + pos += glm::cross(up, forward) * amt; + } + + void MoveUp(){ + pos += glm::vec3(0,.2,0); + } + + void MoveDown(){ + pos -= glm::vec3(0,.2,0); + } + + void Pitch(float angle){ + glm::vec3 right = glm::normalize(glm::cross(up, forward)); + + forward = glm::vec3(glm::normalize(glm::rotate(angle, right) * glm::vec4(forward, 0.0))); + up = glm::normalize(glm::cross(forward, right)); + } + + private: + float amt = .2; + glm::mat4 projection; + glm::vec3 pos; + glm::vec3 forward; + glm::vec3 up; +}; + +#endif diff --git a/inc/opengl/geoshader.hpp b/inc/opengl/geoshader.hpp new file mode 100644 index 0000000..2619a92 --- /dev/null +++ b/inc/opengl/geoshader.hpp @@ -0,0 +1,30 @@ +#ifndef geoshader_h
+#define geoshader_h
+
+#include <string>
+#include <GL/glew.h>
+
+#include "constants.hpp"
+#include "graphicsdata.hpp"
+#include "transform.hpp"
+
+class GeoShader
+{
+ public:
+ GeoShader(const std::string& fileName);
+
+ void Bind();
+ void Update(const Transform& transform, const Camera& camera);
+ virtual ~GeoShader();
+ GLuint m_program;
+
+ private:
+ std::string LoadShader(const std::string& fileName);
+ void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, const std::string& errorMessage);
+ GLuint CreateShader(const std::string& text, GLenum shaderType);
+
+ GLuint m_shaders[NUM_SHADERS];
+ GLuint m_uniforms[NUM_UNIFORMS];
+};
+
+#endif
diff --git a/inc/opengl/graphicsdata.hpp b/inc/opengl/graphicsdata.hpp new file mode 100644 index 0000000..df8d76e --- /dev/null +++ b/inc/opengl/graphicsdata.hpp @@ -0,0 +1,49 @@ +#ifndef graphicsdata_h
+#define graphicsdata_h
+
+#include <glm/glm.hpp>
+#include <glm/gtx/transform.hpp>
+
+#include "camera.hpp"
+
+class GraphicsData
+{
+ public:
+
+ float x;
+ float y;
+ float r;
+ float g;
+ float b;
+ float sides;
+
+ GraphicsData(){
+ this->x = 0;
+ this->y = 0;
+ this->r = 0;
+ this->g = 0;
+ this->b = 0;
+ this->sides = 0;
+ }
+
+
+ GraphicsData(float x,float y,float r,float g,float b,float sides){
+ this->x = 0;
+ this->y = 0;
+ this->r = 0;
+ this->g = 0;
+ this->b = 0;
+ this->sides = 0;
+ }
+
+ float getX(){
+ return x;
+ }
+
+ float getY(){
+ return y;
+ }
+
+};
+
+#endif
diff --git a/inc/opengl/rectdrawer.hpp b/inc/opengl/rectdrawer.hpp new file mode 100644 index 0000000..f2ca1e5 --- /dev/null +++ b/inc/opengl/rectdrawer.hpp @@ -0,0 +1,47 @@ +#ifndef rectdrawer_h
+#define rectdrawer_h
+
+
+#include <GL/glew.h>
+#include <vector>
+#include <iostream>
+#include "geoshader.hpp"
+#include "graphicsdata.hpp"
+#include "spritebatch.hpp"
+
+
+//merge this with spritebatch
+class Rectdrawer
+{
+public:
+ Rectdrawer(GeoShader theshader);
+ ~Rectdrawer();
+
+
+ //void init();
+ void begin();
+ void end();
+ void draw(const GraphicsData& gfxData);
+ void renderBatch();
+
+private:
+ // Creates all the needed RenderBatches
+ void createRenderBatches();
+
+
+ GLuint _vbo;
+ GLuint _vao;
+
+
+ std::vector<GraphicsData*> _gfxPtr; ///< This is for sorting
+ std::vector<GraphicsData> _gfx; ///< These are the actual glyphs
+ std::vector<RenderBatch> _renderBatches;
+
+ GeoShader shader;
+
+
+};
+
+
+#endif
+
diff --git a/inc/opengl/basicshader.frag b/inc/opengl/shaders/basicshader.frag index 9aa9d0b..9aa9d0b 100644 --- a/inc/opengl/basicshader.frag +++ b/inc/opengl/shaders/basicshader.frag diff --git a/inc/opengl/basicshader.geom b/inc/opengl/shaders/basicshader.geom index 3540d10..3540d10 100644 --- a/inc/opengl/basicshader.geom +++ b/inc/opengl/shaders/basicshader.geom diff --git a/inc/opengl/basicshader.vert b/inc/opengl/shaders/basicshader.vert index f17aef5..f17aef5 100644 --- a/inc/opengl/basicshader.vert +++ b/inc/opengl/shaders/basicshader.vert diff --git a/inc/opengl/theshader.frag b/inc/opengl/shaders/theshader.frag index 4f870cb..4f870cb 100644 --- a/inc/opengl/theshader.frag +++ b/inc/opengl/shaders/theshader.frag diff --git a/inc/opengl/theshader.geom b/inc/opengl/shaders/theshader.geom index a49e6bc..a49e6bc 100644 --- a/inc/opengl/theshader.geom +++ b/inc/opengl/shaders/theshader.geom diff --git a/inc/opengl/theshader.vert b/inc/opengl/shaders/theshader.vert index b7cfe3b..b7cfe3b 100644 --- a/inc/opengl/theshader.vert +++ b/inc/opengl/shaders/theshader.vert diff --git a/inc/opengl/spritebatch.hpp b/inc/opengl/spritebatch.hpp new file mode 100644 index 0000000..3ece593 --- /dev/null +++ b/inc/opengl/spritebatch.hpp @@ -0,0 +1,63 @@ +#ifndef spritebatch_h
+#define spritebatch_h
+
+#include <GL/glew.h>
+#include "graphicsdata.hpp"
+#include <vector>
+#include "geoshader.hpp"
+#include <iostream>
+
+
+class RenderBatch {
+public:
+ RenderBatch(GLuint Offset, GLuint NumVertices) : offset(Offset),
+ numVertices(NumVertices){
+ }
+ GLuint offset;
+ GLuint numVertices;
+ //GLuint texture;
+};
+
+
+class SpriteBatch
+{
+ public:
+ SpriteBatch(GeoShader theshader);
+ ~SpriteBatch();
+ // Initializes the spritebatch
+ void init();
+ // Begins the spritebatch
+ void begin();
+ // Ends the spritebatch
+ void end();
+ // Adds a glyph to the spritebatch
+ void draw(const GraphicsData& gfxData);
+ // Renders the entire SpriteBatch to the screen
+ void renderBatch();
+
+ private:
+ // Creates all the needed RenderBatches
+ void createRenderBatches();
+ // Generates our VAO and VBO
+ void createVertexArray();
+ // Sorts glyphs according to _sortType
+ //void sortGlyphs();
+ // Comparators used by sortGlyphs()
+ //static bool compareFrontToBack(Glyph* a, Glyph* b);
+ //static bool compareBackToFront(Glyph* a, Glyph* b);
+ //static bool compareTexture(Glyph* a, Glyph* b);
+
+ GLuint _vbo;
+ GLuint _vao;
+
+ //GlyphSortType _sortType;
+
+ std::vector<GraphicsData*> _gfxPtr; ///< This is for sorting
+ std::vector<GraphicsData> _gfx; ///< These are the actual glyphs
+ std::vector<RenderBatch> _renderBatches;
+
+ GeoShader shader;
+
+};
+
+#endif
diff --git a/inc/opengl/transform.hpp b/inc/opengl/transform.hpp new file mode 100644 index 0000000..9d0988c --- /dev/null +++ b/inc/opengl/transform.hpp @@ -0,0 +1,52 @@ +#ifndef transform_h +#define transform_h + +#include <glm/glm.hpp> +#include <glm/gtx/transform.hpp> + +#include "camera.hpp" + +struct Transform +{ +public: + Transform(const glm::vec3& pos = glm::vec3(), const glm::vec3& rot = glm::vec3(), const glm::vec3& scale = glm::vec3(1.0f, 1.0f, 1.0f)) + { + this->pos = pos; + this->rot = rot; + this->scale = scale; + } + + inline glm::mat4 GetModel() const + { + glm::mat4 posMat = glm::translate(pos); + glm::mat4 scaleMat = glm::scale(scale); + glm::mat4 rotX = glm::rotate(rot.x, glm::vec3(1.0, 0.0, 0.0)); + glm::mat4 rotY = glm::rotate(rot.y, glm::vec3(0.0, 1.0, 0.0)); + glm::mat4 rotZ = glm::rotate(rot.z, glm::vec3(0.0, 0.0, 1.0)); + glm::mat4 rotMat = rotX * rotY * rotZ; + + return posMat * rotMat * scaleMat; + } + + inline glm::mat4 GetMVP(const Camera& camera) const + { + glm::mat4 VP = camera.GetViewProjection(); + glm::mat4 M = GetModel(); + + return VP * M; + } + + inline glm::vec3* GetPos() { return &pos; } + inline glm::vec3* GetRot() { return &rot; } + inline glm::vec3* GetScale() { return &scale; } + + inline void SetPos(glm::vec3& pos) { this->pos = pos; } + inline void SetRot(glm::vec3& rot) { this->rot = rot; } + inline void SetScale(glm::vec3& scale) { this->scale = scale; } +private: + glm::vec3 pos; + glm::vec3 rot; + glm::vec3 scale; +}; + +#endif |