diff --git a/README.MD b/README.MD index a2221c1..c71dc7b 100644 --- a/README.MD +++ b/README.MD @@ -1,10 +1,10 @@ -# VELAGE -### the VEry LArge Game Engine +### VELAGE +# the VEry LArge Game Engine it's a game engine for big s#1t -### building +# building it's easy just type `make` to build and run ./build/main diff --git a/build/main b/build/main new file mode 100755 index 0000000..c56ea6f Binary files /dev/null and b/build/main differ diff --git a/build/test b/build/test new file mode 100755 index 0000000..51688c1 Binary files /dev/null and b/build/test differ diff --git a/engine/object.cpp b/engine/object.cpp index ddc4a19..306eaa3 100644 --- a/engine/object.cpp +++ b/engine/object.cpp @@ -1,26 +1,7 @@ #include "object.hpp" #include "shader.hpp" -#include -#include void gameobject::render() { - GLint current; - // check if vbo is correct - glGetIntegerv(GL_VERTEX_ARRAY_BUFFER_BINDING, ¤t); - if (current != vbo) - glBindBuffer(GL_ARRAY_BUFFER, vbo); - - // check if ebo is correct - glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, ¤t); - if (current != ebo) - glBindBuffer(GL_ARRAY_BUFFER, ebo); - - // check if vao is correct - glGetIntegerv(GL_VERTEX_ARRAY_BUFFER_BINDING, ¤t); - if (current != ebo) - glBindBuffer(GL_ARRAY_BUFFER, vao); - - // draw glDrawElements(GL_TRIANGLES, element_number, GL_UNSIGNED_INT, elements); } @@ -30,37 +11,19 @@ gameobject::gameobject(shader *render_shader) { glGenVertexArrays(1, &vao); } -void gameobject::genEbo(GLuint elements[], GLuint size) { - - this->elements = elements; - element_number = size; - +void gameobject::genEbo() { glGenBuffers(1, &ebo); // Generate 1 buffer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * element_number, - elements, GL_STATIC_DRAW); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint)*element_number, elements, + GL_STATIC_DRAW); } void gameobject::genVbo(GLfloat vertices[], GLuint size) { - - this->vertices = vertices; - vertice_number = size; - glGenBuffers(1, &vbo); // Generate 1 buffer glBindBuffer(GL_ARRAY_BUFFER, vbo); - glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * size, vertices, - GL_STATIC_DRAW); -} - -void gameobject::setVertexAtribPointer(std::string param, int size, - bool normalise, int stride, - const void *pointer) { - GLint posAttrib = rend_shader->getInputId(param); - glEnableVertexAttribArray(posAttrib); - glVertexAttribPointer(posAttrib, size, GL_FLOAT, GL_FALSE, - stride * sizeof(GLfloat), pointer); + glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * size, vertices, GL_STATIC_DRAW); } \ No newline at end of file diff --git a/engine/object.hpp b/engine/object.hpp index 5045fa5..c5edd61 100644 --- a/engine/object.hpp +++ b/engine/object.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include "shader.hpp" /* @@ -16,23 +15,17 @@ class gameobject{ public: shader *rend_shader; + GLuint vbo; GLuint vao; - + GLuint element_number; GLuint ebo; GLuint *elements; - GLuint vertice_number; - GLuint vbo; - GLfloat *vertices; - void render(); void genVbo(GLfloat vertices[], GLuint size); - - void setVertexAtribPointer(std::string param, int size, bool normalise, int stride, const void * pointer); - //void genVbo(std::vector vertices); - void genEbo(GLuint elements[], GLuint size); + void genEbo(); gameobject(shader *render_shader); private: diff --git a/engine/rendering.cpp b/engine/rendering.cpp index 83836d2..9661270 100644 --- a/engine/rendering.cpp +++ b/engine/rendering.cpp @@ -172,6 +172,6 @@ bool rendering::Shaderinit() { void rendering::render(){ for (int i=0; i #include #include -#include #include #include #include @@ -33,7 +32,7 @@ public: std::vector vertex_shaders; std::vector fragment_shaders; std::vector shaders; - std::vector< std::reference_wrapper > objects; + std::vector objects; //temporary void render(); diff --git a/test.cpp b/test.cpp index 6a6431b..57e5371 100644 --- a/test.cpp +++ b/test.cpp @@ -2,7 +2,6 @@ #include "engine/rendering.hpp" #include "engine/shader.hpp" #include -#include int main(int argc, char *argv[]) { rendering renderer; @@ -22,29 +21,36 @@ int main(int argc, char *argv[]) { GLuint elements[] = {0, 2, 3, 1, 2, 3}; - gameobject test(&renderer.shaders.at(0)); - renderer.objects.push_back(test); - test.genVbo(vertices, 20); - test.genEbo(elements, 2); - glBindVertexArray(test.vao); - test.rend_shader->use(); - test.setVertexAtribPointer("position",2, false, 5, 0); - test.setVertexAtribPointer("color",3, false, 5, (void *)(2 * sizeof(GLfloat))); - gameobject test2(&renderer.shaders.at(0)); - renderer.objects.push_back(test2); - test2.genVbo(vertices, 20); - test2.genEbo(elements, 2); - glBindVertexArray(test2.vao); - test2.rend_shader->use(); - test2.setVertexAtribPointer("position",2, false, 5, 0); - test2.setVertexAtribPointer("color",2, false, 5, (void *)(2 * sizeof(GLfloat))); + gameobject test(&renderer.shaders.at(0)); + // renderer.objects.push_back(test); + + test.element_number = 6; + test.elements = elements; + + test.genVbo(vertices, 20); + test.genEbo(); + + glBindVertexArray(test.vao); + + test.rend_shader->use(); + + GLint posAttrib = test.rend_shader->getInputId("position"); + glEnableVertexAttribArray(posAttrib); + glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), + 0); + + GLint colAttrib = test.rend_shader->getInputId("color"); + glEnableVertexAttribArray(colAttrib); + glVertexAttribPointer(colAttrib, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), + (void *)(2 * sizeof(GLfloat))); + + /*GLint uniColor = + glGetUniformLocation(test.rend_shader->shaderProgram, "triangleColor"); + glUniform3f(uniColor, 1.0f, 0.0f, 0.0f);*/ SDL_Event windowEvent; - //std::cout<