1
0
Fork 0

Split code into separate headers

This commit is contained in:
Meoweg 2015-11-07 13:56:06 +00:00
parent fa26f3b61c
commit eb861952a4
8 changed files with 135 additions and 84 deletions

7
src/gl.hpp Normal file
View File

@ -0,0 +1,7 @@
#ifndef _GL_HPP_
#define _GL_HPP_
#include <GL/glew.h>
#include <GL/glfw.h>
#endif // _GL_HPP_

View File

@ -1,3 +1,6 @@
#include "program.hpp"
#include "object.hpp"
#include <cstdlib>
#include <vector>
#include <fstream>
@ -9,93 +12,9 @@
#include <SDL_image.h>
#include <GL/glew.h>
#include <GL/glfw.h>
#include <emscripten/emscripten.h>
#include <emscripten/html5.h>
class Shader
{
public:
Shader(GLenum type, const char *filename);
inline GLuint id() const { return _id; };
private:
GLuint _id;
};
class Program
{
public:
Program();
void attach_shader(const Shader &shader);
void bind_attrib_location(GLuint index, const GLchar *name);
void link();
void use() const;
GLuint get_uniform_location(const GLchar *name) const;
private:
GLuint _id;
};
class Texture
{
public:
Texture(const char *filename);
void use() const;
private:
GLuint _id;
};
class Material
{
public:
Material(const char *filename);
void use() const;
private:
Texture *_texture;
};
class Model
{
public:
Model(const char *filename);
void draw() const;
private:
std::vector<glm::vec3> positions;
GLuint positions_id;
std::vector<glm::vec2> tex_coords;
GLuint tex_coords_id;
std::vector<glm::vec3> normals;
GLuint normals_id;
std::vector<GLushort> elements;
GLuint id;
Material *_material;
static GLuint create_array_buffer(GLenum type, GLsizeiptr size, const GLvoid *data);
};
class Object
{
public:
Object(const Model &model) : _model(model) {};
void draw(const glm::mat4 &mvp) const;
glm::vec3 position;
glm::vec3 rotation;
private:
const Model &_model;
};
static Program build_program();
static void iterate();

16
src/material.hpp Normal file
View File

@ -0,0 +1,16 @@
#ifndef _MATERIAL_HPP_
#define _MATERIAL_HPP_
#include "texture.hpp"
class Material
{
public:
Material(const char *filename);
void use() const;
private:
Texture *_texture;
};
#endif // _MATERIAL_HPP_

35
src/model.hpp Normal file
View File

@ -0,0 +1,35 @@
#ifndef _MODEL_HPP_
#define _MODEL_HPP_
#include "gl.hpp"
#include "material.hpp"
#include <vector>
#include <glm/glm.hpp>
class Model
{
public:
Model(const char *filename);
void draw() const;
private:
std::vector<glm::vec3> positions;
GLuint positions_id;
std::vector<glm::vec2> tex_coords;
GLuint tex_coords_id;
std::vector<glm::vec3> normals;
GLuint normals_id;
std::vector<GLushort> elements;
GLuint id;
Material *_material;
static GLuint create_array_buffer(GLenum type, GLsizeiptr size, const GLvoid *data);
};
#endif // _MODEL_HPP_

21
src/object.hpp Normal file
View File

@ -0,0 +1,21 @@
#ifndef _OBJECT_HPP_
#define _OBJECT_HPP_
#include "model.hpp"
#include <glm/glm.hpp>
class Object
{
public:
Object(const Model &model) : _model(model) {};
void draw(const glm::mat4 &mvp) const;
glm::vec3 position;
glm::vec3 rotation;
private:
const Model &_model;
};
#endif // _OBJECT_HPP_

21
src/program.hpp Normal file
View File

@ -0,0 +1,21 @@
#ifndef _PROGRAM_HPP_
#define _PROGRAM_HPP_
#include "gl.hpp"
#include "shader.hpp"
class Program
{
public:
Program();
void attach_shader(const Shader &shader);
void bind_attrib_location(GLuint index, const GLchar *name);
void link();
void use() const;
GLuint get_uniform_location(const GLchar *name) const;
private:
GLuint _id;
};
#endif // _PROGRAM_HPP_

16
src/shader.hpp Normal file
View File

@ -0,0 +1,16 @@
#ifndef _SHADER_HPP_
#define _SHADER_HPP_
#include "gl.hpp"
class Shader
{
public:
Shader(GLenum type, const char *filename);
inline GLuint id() const { return _id; };
private:
GLuint _id;
};
#endif // _SHADER_HPP_

16
src/texture.hpp Normal file
View File

@ -0,0 +1,16 @@
#ifndef _TEXTURE_HPP_
#define _TEXTURE_HPP_
#include "gl.hpp"
class Texture
{
public:
Texture(const char *filename);
void use() const;
private:
GLuint _id;
};
#endif // _TEXTURE_HPP_