diff --git a/README.MD b/README.MD index c71dc7b..a2221c1 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 deleted file mode 100755 index c56ea6f..0000000 Binary files a/build/main and /dev/null differ diff --git a/build/test b/build/test deleted file mode 100755 index 51688c1..0000000 Binary files a/build/test and /dev/null differ diff --git a/engine/object.cpp b/engine/object.cpp index 306eaa3..ddc4a19 100644 --- a/engine/object.cpp +++ b/engine/object.cpp @@ -1,7 +1,26 @@ #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); } @@ -11,19 +30,37 @@ gameobject::gameobject(shader *render_shader) { glGenVertexArrays(1, &vao); } -void gameobject::genEbo() { +void gameobject::genEbo(GLuint elements[], GLuint size) { + + this->elements = elements; + element_number = size; + 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); + 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); } \ No newline at end of file diff --git a/engine/object.hpp b/engine/object.hpp index c5edd61..5045fa5 100644 --- a/engine/object.hpp +++ b/engine/object.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "shader.hpp" /* @@ -15,17 +16,23 @@ 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 genEbo(); + + 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); gameobject(shader *render_shader); private: diff --git a/engine/rendering.cpp b/engine/rendering.cpp index 9661270..83836d2 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 @@ -32,7 +33,7 @@ public: std::vector vertex_shaders; std::vector fragment_shaders; std::vector shaders; - std::vector objects; + std::vector< std::reference_wrapper > objects; //temporary void render(); diff --git a/test.cpp b/test.cpp index 57e5371..6a6431b 100644 --- a/test.cpp +++ b/test.cpp @@ -2,6 +2,7 @@ #include "engine/rendering.hpp" #include "engine/shader.hpp" #include +#include int main(int argc, char *argv[]) { rendering renderer; @@ -21,36 +22,29 @@ 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.element_number = 6; - test.elements = elements; - + renderer.objects.push_back(test); test.genVbo(vertices, 20); - test.genEbo(); - + 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))); - 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);*/ + 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))); SDL_Event windowEvent; + //std::cout<