Switch to sprite renderer
This commit is contained in:
@@ -3,13 +3,12 @@
|
||||
|
||||
#include <Dengine/OpenGL.h>
|
||||
#include <Dengine/Common.h>
|
||||
#include <Dengine/Sprite.h>
|
||||
#include <Dengine/Renderer.h>
|
||||
#include <Dengine/Shader.h>
|
||||
#include <Dengine/AssetManager.h>
|
||||
|
||||
namespace Breakout
|
||||
{
|
||||
|
||||
GLOBAL_VAR const i32 NUM_KEYS = 1024;
|
||||
|
||||
enum GameState
|
||||
@@ -29,14 +28,14 @@ public:
|
||||
Game(i32 width, i32 height);
|
||||
~Game();
|
||||
|
||||
void init(Dengine::AssetManager *const assetManager);
|
||||
void init();
|
||||
|
||||
void processInput(const f32 dt);
|
||||
void update(const f32 dt);
|
||||
void render();
|
||||
private:
|
||||
const Dengine::Shader *shader;
|
||||
Dengine::Sprite player;
|
||||
Dengine::Shader *shader;
|
||||
Dengine::Renderer *renderer;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -14,23 +14,18 @@ namespace Dengine
|
||||
class AssetManager
|
||||
{
|
||||
public:
|
||||
AssetManager();
|
||||
// TODO(doyle): Unload all resources in memory
|
||||
~AssetManager();
|
||||
static std::map<std::string, Texture> textures;
|
||||
static std::map<std::string, Shader> shaders;
|
||||
|
||||
/* Texture */
|
||||
const Texture *getTexture(const std::string name);
|
||||
const i32 loadTextureImage(const std::string path, const std::string name);
|
||||
static Texture *getTexture(const std::string name);
|
||||
static const i32 loadTextureImage(const std::string path, const std::string name);
|
||||
|
||||
/* Shaders */
|
||||
const Shader *getShader(const std::string name);
|
||||
const i32 loadShaderFiles(const std::string vertexPath,
|
||||
static Shader *getShader(const std::string name);
|
||||
static const i32 loadShaderFiles(const std::string vertexPath,
|
||||
const std::string fragmentPath,
|
||||
const std::string name);
|
||||
|
||||
private:
|
||||
std::map<std::string, Texture> mTextures;
|
||||
std::map<std::string, Shader> mShaders;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -5,4 +5,43 @@
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#endif
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
inline GLenum glCheckError_(const char *file, int line)
|
||||
{
|
||||
GLenum errorCode;
|
||||
while ((errorCode = glGetError()) != GL_NO_ERROR)
|
||||
{
|
||||
std::string error;
|
||||
switch (errorCode)
|
||||
{
|
||||
case GL_INVALID_ENUM:
|
||||
error = "INVALID_ENUM";
|
||||
break;
|
||||
case GL_INVALID_VALUE:
|
||||
error = "INVALID_VALUE";
|
||||
break;
|
||||
case GL_INVALID_OPERATION:
|
||||
error = "INVALID_OPERATION";
|
||||
break;
|
||||
case GL_STACK_OVERFLOW:
|
||||
error = "STACK_OVERFLOW";
|
||||
break;
|
||||
case GL_STACK_UNDERFLOW:
|
||||
error = "STACK_UNDERFLOW";
|
||||
break;
|
||||
case GL_OUT_OF_MEMORY:
|
||||
error = "OUT_OF_MEMORY";
|
||||
break;
|
||||
case GL_INVALID_FRAMEBUFFER_OPERATION:
|
||||
error = "INVALID_FRAMEBUFFER_OPERATION";
|
||||
break;
|
||||
}
|
||||
std::cout << error << " | " << file << " (" << line << ")" << std::endl;
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
#define glCheckError() glCheckError_(__FILE__, __LINE__)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef DENGINE_RENDERER_H
|
||||
#define DENGINE_RENDERER_H
|
||||
|
||||
#include <Dengine/Common.h>
|
||||
#include <Dengine/Texture.h>
|
||||
#include <Dengine/Shader.h>
|
||||
#include <GLM/glm.hpp>
|
||||
|
||||
namespace Dengine
|
||||
{
|
||||
class Renderer
|
||||
{
|
||||
public:
|
||||
Renderer(Shader *shader);
|
||||
~Renderer();
|
||||
|
||||
void drawSprite(const Texture *texture, glm::vec2 position,
|
||||
glm::vec2 size = glm::vec2(10, 10), GLfloat rotate = 0.0f,
|
||||
glm::vec3 color = glm::vec3(1.0f));
|
||||
|
||||
private:
|
||||
Shader *shader;
|
||||
GLuint quadVAO;
|
||||
|
||||
void initRenderData();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
#include <Dengine/Common.h>
|
||||
#include <Dengine/OpenGL.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Dengine
|
||||
@@ -10,12 +13,16 @@ namespace Dengine
|
||||
class Shader
|
||||
{
|
||||
public:
|
||||
GLuint program;
|
||||
GLuint id;
|
||||
|
||||
Shader();
|
||||
~Shader();
|
||||
|
||||
i32 loadProgram(GLuint vertexShader, GLuint fragmentShader);
|
||||
const i32 loadProgram(const GLuint vertexShader,
|
||||
const GLuint fragmentShader);
|
||||
|
||||
void uniformSet1i(const GLchar *name, const GLuint data);
|
||||
void uniformSetMat4fv(const GLchar *name, const glm::mat4 data);
|
||||
|
||||
void use() const;
|
||||
};
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
#ifndef DENGINE_SPRITE_H
|
||||
#define DENGINE_SPRITE_H
|
||||
|
||||
#include <Dengine\Common.h>
|
||||
#include <Dengine\Texture.h>
|
||||
#include <Dengine\Shader.h>
|
||||
#include <GLM\glm.hpp>
|
||||
|
||||
namespace Dengine {
|
||||
class Sprite
|
||||
{
|
||||
public:
|
||||
Sprite();
|
||||
~Sprite();
|
||||
|
||||
const b32 loadSprite(const Texture *tex, const glm::vec2 pos);
|
||||
|
||||
void render(const Shader *shader) const;
|
||||
private:
|
||||
glm::vec2 pos;
|
||||
const Texture *tex;
|
||||
GLuint vbo;
|
||||
GLuint vao;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef DENGINE_TEXTURE_H
|
||||
#define DENGINE_TEXTURE_H
|
||||
|
||||
#include <Dengine\OpenGL.h>
|
||||
#include <Dengine\Common.h>
|
||||
#include <Dengine/OpenGL.h>
|
||||
#include <Dengine/Common.h>
|
||||
|
||||
namespace Dengine
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user