Port project over to C, some C++ left
This commit is contained in:
@@ -9,22 +9,30 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace Dengine
|
||||
enum Assets
|
||||
{
|
||||
class AssetManager
|
||||
{
|
||||
public:
|
||||
static std::map<std::string, Texture> textures;
|
||||
static std::map<std::string, Shader> shaders;
|
||||
|
||||
/* Texture */
|
||||
static Texture *getTexture(const std::string name);
|
||||
static const i32 loadTextureImage(const std::string path, const std::string name);
|
||||
|
||||
/* Shaders */
|
||||
static Shader *getShader(const std::string name);
|
||||
static const i32 loadShaderFiles(const std::string vertexPath, const std::string fragmentPath,
|
||||
const std::string name);
|
||||
asset_vertShader,
|
||||
asset_fragShader,
|
||||
asset_hero,
|
||||
};
|
||||
}
|
||||
|
||||
struct AssetManager
|
||||
{
|
||||
Textures textures[256];
|
||||
Shaders shaders[256];
|
||||
};
|
||||
extern std::map<std::string, Texture> textures;
|
||||
extern std::map<std::string, Shader> shaders;
|
||||
|
||||
/* Texture */
|
||||
Texture *asset_getTexture(const std::string name);
|
||||
const i32 asset_loadTextureImage(const std::string path,
|
||||
const std::string name);
|
||||
|
||||
/* Shaders */
|
||||
Shader *asset_getShader(const std::string name);
|
||||
const i32 asset_loadShaderFiles(const std::string vertexPath,
|
||||
const std::string fragmentPath,
|
||||
const std::string name);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#ifndef DENGINE_COMMON_H
|
||||
#define DENGINE_COMMON_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint32_t u32;
|
||||
@@ -20,4 +21,7 @@ typedef double f64;
|
||||
#define INTERNAL static
|
||||
#define LOCAL_PERSIST static
|
||||
|
||||
#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))
|
||||
#define CAST(type) (type)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,23 +6,12 @@
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace Dengine
|
||||
struct Entity
|
||||
{
|
||||
class Entity
|
||||
{
|
||||
public:
|
||||
Entity();
|
||||
Entity(const glm::vec2 pos, const Texture *tex);
|
||||
Entity(const glm::vec2 pos, const glm::vec2 size, const Texture *tex);
|
||||
Entity(const glm::vec2 pos, const std::string texName);
|
||||
~Entity();
|
||||
|
||||
|
||||
glm::vec2 pos; // Position
|
||||
glm::vec2 dPos; // Velocity
|
||||
|
||||
glm::vec2 size;
|
||||
const Texture *tex;
|
||||
Texture *tex;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,17 +3,10 @@
|
||||
|
||||
#include <Dengine/Common.h>
|
||||
|
||||
namespace Dengine
|
||||
inline f32 squared(const f32 a)
|
||||
{
|
||||
class Math
|
||||
{
|
||||
public:
|
||||
static inline f32 squared(const f32 a)
|
||||
{
|
||||
f32 result = a * a;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
f32 result = a * a;
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,40 +5,38 @@
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
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";
|
||||
printf("INVALID_ENUM | ");
|
||||
break;
|
||||
case GL_INVALID_VALUE:
|
||||
error = "INVALID_VALUE";
|
||||
printf("INVALID_VALUE | ");
|
||||
break;
|
||||
case GL_INVALID_OPERATION:
|
||||
error = "INVALID_OPERATION";
|
||||
printf("INVALID_OPERATION | ");
|
||||
break;
|
||||
case GL_STACK_OVERFLOW:
|
||||
error = "STACK_OVERFLOW";
|
||||
printf("STACK_OVERFLOW | ");
|
||||
break;
|
||||
case GL_STACK_UNDERFLOW:
|
||||
error = "STACK_UNDERFLOW";
|
||||
printf("STACK_UNDERFLOW | ");
|
||||
break;
|
||||
case GL_OUT_OF_MEMORY:
|
||||
error = "OUT_OF_MEMORY";
|
||||
printf("OUT_OF_MEMORY | ");
|
||||
break;
|
||||
case GL_INVALID_FRAMEBUFFER_OPERATION:
|
||||
error = "INVALID_FRAMEBUFFER_OPERATION";
|
||||
printf("INVALID_FRAMEBUFFER_OPERATION | ");
|
||||
break;
|
||||
}
|
||||
std::cout << error << " | " << file << " (" << line << ")" << std::endl;
|
||||
printf("%s (%d)\n", file, line);
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
@@ -8,22 +8,13 @@
|
||||
|
||||
#include <GLM/glm.hpp>
|
||||
|
||||
namespace Dengine
|
||||
struct Renderer
|
||||
{
|
||||
class Renderer
|
||||
{
|
||||
public:
|
||||
Renderer(Shader *shader);
|
||||
~Renderer();
|
||||
|
||||
void drawEntity(Entity *entity, GLfloat rotate = 0.0f, glm::vec3 color = glm::vec3(1.0f));
|
||||
|
||||
private:
|
||||
Shader *shader;
|
||||
GLuint quadVAO;
|
||||
|
||||
void initRenderData();
|
||||
};
|
||||
}
|
||||
|
||||
void renderer_entity(Renderer *renderer, Entity *entity, GLfloat rotate = 0.0f,
|
||||
glm::vec3 color = glm::vec3(1.0f));
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,25 +6,20 @@
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Dengine
|
||||
struct Shader
|
||||
{
|
||||
class Shader
|
||||
{
|
||||
public:
|
||||
GLuint id;
|
||||
|
||||
Shader();
|
||||
~Shader();
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
const i32 shader_loadProgram(Shader *const shader,
|
||||
const GLuint vertexShader,
|
||||
const GLuint fragmentShader);
|
||||
|
||||
void shader_uniformSet1i(Shader *const shader, const GLchar *name,
|
||||
const GLuint data);
|
||||
void shader_uniformSetMat4fv(Shader *const shader, const GLchar *name,
|
||||
const glm::mat4 data);
|
||||
|
||||
void shader_use(const Shader *const shader);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,26 +4,8 @@
|
||||
#include <Dengine/Common.h>
|
||||
#include <Dengine/OpenGL.h>
|
||||
|
||||
namespace Dengine
|
||||
struct Texture
|
||||
{
|
||||
class Texture
|
||||
{
|
||||
public:
|
||||
// Constructor (sets default texture modes)
|
||||
Texture();
|
||||
|
||||
// Generates texture from image data
|
||||
void generate(const GLuint width, const GLuint height, const GLint bytesPerPixel,
|
||||
const u8 *const image);
|
||||
|
||||
// Binds the texture as the current active GL_TEXTURE_2D texture object
|
||||
void bind() const;
|
||||
|
||||
inline const GLuint getWidth() const { return this->width; }
|
||||
inline const GLuint getHeight() const { return this->height; }
|
||||
inline const GLuint getID() const { return this->id; }
|
||||
|
||||
private:
|
||||
// Holds the ID of the texture object, used for all texture operations to
|
||||
// reference to this particlar texture
|
||||
GLuint id;
|
||||
@@ -45,5 +27,9 @@ private:
|
||||
// Filtering mode if texture pixels > screen pixels
|
||||
GLuint filterMagnification;
|
||||
};
|
||||
}
|
||||
|
||||
// Generates texture from image data
|
||||
Texture genTexture(const GLuint width, const GLuint height, const GLint bytesPerPixel,
|
||||
const u8 *const image);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -9,21 +9,8 @@
|
||||
#include <Dengine/Renderer.h>
|
||||
#include <Dengine/Shader.h>
|
||||
|
||||
namespace WorldTraveller
|
||||
{
|
||||
GLOBAL_VAR const i32 NUM_KEYS = 1024;
|
||||
GLOBAL_VAR const f32 METERS_TO_PIXEL = 100;
|
||||
|
||||
enum Cardinal
|
||||
{
|
||||
cardinal_north = 0,
|
||||
cardinal_west = 1,
|
||||
cardinal_south = 2,
|
||||
cardinal_east = 3,
|
||||
cardinal_num,
|
||||
cardinal_null
|
||||
|
||||
};
|
||||
#define NUM_KEYS 1024
|
||||
#define METERS_TO_PIXEL 100
|
||||
|
||||
enum State
|
||||
{
|
||||
@@ -32,25 +19,16 @@ enum State
|
||||
state_win
|
||||
};
|
||||
|
||||
class Game
|
||||
struct GameState
|
||||
{
|
||||
public:
|
||||
State state;
|
||||
GLboolean keys[NUM_KEYS];
|
||||
i32 width, height;
|
||||
|
||||
Game(i32 width, i32 height);
|
||||
~Game();
|
||||
|
||||
void init();
|
||||
|
||||
void update(const f32 dt);
|
||||
void render();
|
||||
private:
|
||||
Dengine::Shader *shader;
|
||||
Dengine::Renderer *renderer;
|
||||
Dengine::Entity hero;
|
||||
Renderer renderer;
|
||||
Entity hero;
|
||||
};
|
||||
}
|
||||
|
||||
void worldTraveller_gameInit(GameState *state);
|
||||
void worldTraveller_gameUpdateAndRender(GameState *state, const f32 dt);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user