Add perspective view

This commit is contained in:
2020-03-23 17:26:32 +01:00
parent 4a7e0ac82a
commit 8238e94eea
12 changed files with 203 additions and 61 deletions

View File

@@ -0,0 +1,21 @@
#ifndef GLOBALCANVASSETTINGS_H
#define GLOBALCANVASSETTINGS_H
#include <glm/glm.hpp>
class GlobalCanvasSettings
{
public:
static void setProjectionMatrix(const glm::mat4 &proj);
static void setViewMatrix(const glm::mat4 &view);
static const glm::mat4 &getViewMatrix();
static const glm::mat4 &getProjectionMatrix();
static const glm::mat4 &getPVMatrix();
private:
static void calculatePVMatrix();
static glm::mat4 m_proj;
static glm::mat4 m_view;
static glm::mat4 m_proj_view;
};
#endif // GLOBALCANVASSETTINGS_H

View File

@@ -9,21 +9,19 @@ class OpenGlShaderProgram
{
public:
OpenGlShaderProgram(std::string vertex_file, std::string geometry_file, std::string fragment_file);
OpenGlShaderProgram(const OpenGlShaderProgram &) = delete;
OpenGlShaderProgram(const OpenGlShaderProgram &&) = delete;
~OpenGlShaderProgram();
void setProjectionView(const glm::mat4 &projection, const glm::mat4 &view);
glm::mat4 getProjection();
glm::mat4 getView();
int compile();
void unload();
int use();
int getUniformLoc(const std::string &uniform);
void setUniformFloat(const std::string &uniform, float value);
void setUniformInt(const std::string &uniform, int value);
void setUniformVec2(const std::string &uniform, float *vector);
void setUniformMat4(const std::string &uniform, const glm::mat4 &matrix);
void setUniformVec4(const std::string &uniform, const glm::vec4 &vector);
private:
glm::mat4 proj;
glm::mat4 view;
glm::mat4 proj_view;
bool compiled;
GLuint shader_program;
std::string vertex_file;

View File

@@ -7,9 +7,12 @@ class OpenGlTexture
{
public:
OpenGlTexture();
OpenGlTexture(const OpenGlTexture &tex);
OpenGlTexture(const OpenGlTexture &&tex);
OpenGlTexture(const OpenGlTexture &tex) = delete;
OpenGlTexture(const OpenGlTexture &&tex) = delete;
~OpenGlTexture();
void setRGBDataFromBytes(unsigned int width, unsigned int height, char *buffer);
void use(unsigned int slot);
void use();
protected:
GLuint texture;

View File

@@ -2,13 +2,15 @@
#define TEXTURED_RECTANGLE_H
#include <opengl-playground/openglgraphics.hpp>
#include <opengl-playground/opengltexture.hpp>
#include <epoxy/gl.h>
#include <memory>
class TexturedRectangle : OpenGlGraphics
class TexturedRectangle : public OpenGlGraphics
{
public:
TexturedRectangle(float x0, float y0, float x1, float y1, std::shared_ptr<OpenGlShaderProgram> shaderprog);
TexturedRectangle(float x0, float y0, float x1, float y1, std::shared_ptr<OpenGlShaderProgram> &shaderprog,
std::shared_ptr<OpenGlTexture> &texture);
void realize();
void render();
void setZoom(float zoom);
@@ -16,8 +18,11 @@ class TexturedRectangle : OpenGlGraphics
void setOffset(float x_off, float y_off);
float getOffsetX();
float getOffsetY();
void setBaseColor(const glm::vec4 &color);
private:
std::shared_ptr<OpenGlTexture> m_texture;
void calculateModelMatrix();
glm::vec4 base_color;
float pos1[2];
float pos2[2];
float x_offset;