From 022a4bdd81332ce67d799be6a06afb42ae45ac2e Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Mon, 25 Dec 2017 12:27:32 +0000 Subject: [Build] Added examples and improved build for them. --- examples/shooter/main.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 examples/shooter/main.cpp (limited to 'examples/shooter/main.cpp') diff --git a/examples/shooter/main.cpp b/examples/shooter/main.cpp new file mode 100644 index 00000000..d28af83e --- /dev/null +++ b/examples/shooter/main.cpp @@ -0,0 +1,22 @@ +#include + +#include + +using std::cout; + +int main(int argc, char** argv) +{ + cout << "Starting Shooter example...\n"; + + yage::Window window; + window.create("Shooter example", 1920, 1080); + + while(!window.shouldClose()) { + window.pollEvents(); + window.clearBuffer(); + + + + window.swapBuffer(); + } +} -- cgit From 354d7df4d2779ed7391701d1ef4344e959b64582 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Wed, 27 Dec 2017 19:21:12 +0000 Subject: [Broken] Texture is black. --- examples/shooter/main.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'examples/shooter/main.cpp') diff --git a/examples/shooter/main.cpp b/examples/shooter/main.cpp index d28af83e..fe98f300 100644 --- a/examples/shooter/main.cpp +++ b/examples/shooter/main.cpp @@ -1,22 +1,60 @@ #include +#include "glad/glad.h" + #include using std::cout; -int main(int argc, char** argv) +int main(int argc, char **argv) { cout << "Starting Shooter example...\n"; yage::Window window; - window.create("Shooter example", 1920, 1080); + window.create("Shooter example", 800, 600); + + yage::Shader shader("examples/resources/colourshader.vert", + "examples/resources/colourshader.frag"); + + GLfloat vertices[] = { + 0.0f, 0.5f, 1.f, 0.f, 0.f, // Vertex 1 (X, Y, R, G, B) + 0.5f, -0.5f, 0.f, 1.f, 0.f, // Vertex 2 (X, Y, R, G, B) + -0.5f, -0.5f, 0.f, 0.f, 1.f, // Vertex 3 (X, Y, R, G, B) + }; + + // create vertex array + GLuint rect_vao, rect_vbo; + + // bind vertex array object + glGenVertexArrays(1, &rect_vao); + glBindVertexArray(rect_vao); + + // bind vertex buffer object + glGenBuffers(1, &rect_vbo); + glBindBuffer(GL_ARRAY_BUFFER, rect_vbo); - while(!window.shouldClose()) { + glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); + shader.use(); + + // enable vertex attribute arrays + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + + // set the vertex attribute pointers + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), + (void *)(2 * sizeof(GLfloat))); + + while (!window.shouldClose()) { window.pollEvents(); window.clearBuffer(); - + glDrawArrays(GL_TRIANGLES, 0, 3); window.swapBuffer(); } + + glDeleteBuffers(1, &rect_vbo); + + glDeleteVertexArrays(1, &rect_vao); } -- cgit From 5c1a57b3672ec1e0777d8d0878c6a7ae93ebfdca Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sat, 30 Dec 2017 16:07:41 +0000 Subject: [Code] Fixed spritebatch and optimised it. --- examples/shooter/main.cpp | 43 ++----------------------------------------- 1 file changed, 2 insertions(+), 41 deletions(-) (limited to 'examples/shooter/main.cpp') diff --git a/examples/shooter/main.cpp b/examples/shooter/main.cpp index fe98f300..12cf218d 100644 --- a/examples/shooter/main.cpp +++ b/examples/shooter/main.cpp @@ -2,59 +2,20 @@ #include "glad/glad.h" -#include - using std::cout; int main(int argc, char **argv) { - cout << "Starting Shooter example...\n"; - yage::Window window; window.create("Shooter example", 800, 600); - yage::Shader shader("examples/resources/colourshader.vert", - "examples/resources/colourshader.frag"); - - GLfloat vertices[] = { - 0.0f, 0.5f, 1.f, 0.f, 0.f, // Vertex 1 (X, Y, R, G, B) - 0.5f, -0.5f, 0.f, 1.f, 0.f, // Vertex 2 (X, Y, R, G, B) - -0.5f, -0.5f, 0.f, 0.f, 1.f, // Vertex 3 (X, Y, R, G, B) - }; - - // create vertex array - GLuint rect_vao, rect_vbo; - - // bind vertex array object - glGenVertexArrays(1, &rect_vao); - glBindVertexArray(rect_vao); - - // bind vertex buffer object - glGenBuffers(1, &rect_vbo); - glBindBuffer(GL_ARRAY_BUFFER, rect_vbo); - - glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); - shader.use(); - - // enable vertex attribute arrays - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); - - // set the vertex attribute pointers - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0); - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), - (void *)(2 * sizeof(GLfloat))); + yage::Shader shader("examples/resources/textureshader.vert", + "examples/resources/textureshader.frag"); while (!window.shouldClose()) { window.pollEvents(); window.clearBuffer(); - glDrawArrays(GL_TRIANGLES, 0, 3); - window.swapBuffer(); } - - glDeleteBuffers(1, &rect_vbo); - - glDeleteVertexArrays(1, &rect_vao); } -- cgit From 34908f108ad7c2ee6cff96491a0bc40381477424 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sun, 31 Dec 2017 18:00:01 +0000 Subject: [Test] Benchmarking the engine and trying to optimize. --- examples/shooter/main.cpp | 108 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) (limited to 'examples/shooter/main.cpp') diff --git a/examples/shooter/main.cpp b/examples/shooter/main.cpp index 12cf218d..d2727877 100644 --- a/examples/shooter/main.cpp +++ b/examples/shooter/main.cpp @@ -1,6 +1,6 @@ #include -#include "glad/glad.h" +#include "player.h" using std::cout; @@ -12,9 +12,115 @@ int main(int argc, char **argv) yage::Shader shader("examples/resources/textureshader.vert", "examples/resources/textureshader.frag"); + std::vector male_l = { + yage::ResourceManager::getTexture("examples/resources/fighter_ml.png", + 3, 4), + yage::ResourceManager::getTexture("examples/resources/ranger_ml.png", 3, + 4), + yage::ResourceManager::getTexture("examples/resources/mage_ml.png", 3, + 4), + yage::ResourceManager::getTexture("examples/resources/healer_ml.png", 3, + 4)}; + std::vector female_l = { + yage::ResourceManager::getTexture("examples/resources/fighter_fl.png", + 3, 4), + yage::ResourceManager::getTexture("examples/resources/ranger_fl.png", 3, + 4), + yage::ResourceManager::getTexture("examples/resources/mage_fl.png", 3, + 4), + yage::ResourceManager::getTexture("examples/resources/healer_fl.png", 3, + 4)}; + std::vector male_d = { + yage::ResourceManager::getTexture("examples/resources/fighter_md.png", + 3, 4), + yage::ResourceManager::getTexture("examples/resources/ranger_md.png", 3, + 4), + yage::ResourceManager::getTexture("examples/resources/mage_md.png", 3, + 4), + yage::ResourceManager::getTexture("examples/resources/healer_md.png", 3, + 4)}; + std::vector female_d = { + yage::ResourceManager::getTexture("examples/resources/fighter_fd.png", + 3, 4), + yage::ResourceManager::getTexture("examples/resources/ranger_fd.png", 3, + 4), + yage::ResourceManager::getTexture("examples/resources/mage_fd.png", 3, + 4), + yage::ResourceManager::getTexture("examples/resources/healer_fd.png", 3, + 4)}; + + yage::SpriteBatch sp; + yage::Camera camera(800, 600); + + int i = 0; + int j = 0; + bool space_pressed = false; + bool c_pressed = false; + + shader.use(); + shader.setUniform("texture_sampler", 0); + + auto textures = male_l; + + Player player({400, 300, 48 * 2, 64 * 2}, textures.front()); + while (!window.shouldClose()) { window.pollEvents(); + + if (window.keyPressed(yage::key::D)) { + player.move(Direction::RIGHT); + } + if (window.keyPressed(yage::key::S)) { + player.move(Direction::DOWN); + } + if (window.keyPressed(yage::key::A)) { + player.move(Direction::LEFT); + } + if (window.keyPressed(yage::key::W)) { + player.move(Direction::UP); + } + if (!window.keyPressed(yage::key::D) && + !window.keyPressed(yage::key::S) && + !window.keyPressed(yage::key::A) && + !window.keyPressed(yage::key::W)) { + player.idle(); + } + if (window.keyPressed(yage::key::SPACE) && !space_pressed) { + space_pressed = true; + i = (i + 1) % textures.size(); + } + if (!window.keyPressed(yage::key::SPACE)) { + space_pressed = false; + } + if (window.keyPressed(yage::key::C) && !c_pressed) { + c_pressed = true; + j = (j + 1) % 4; + switch (j) { + case 0: + textures = male_l; + break; + case 1: + textures = male_d; + break; + case 2: + textures = female_l; + break; + case 3: + textures = female_d; + break; + } + } + if (!window.keyPressed(yage::key::C)) { + c_pressed = false; + } + + player.setTexture(textures[i]); + + camera.update(shader); + window.clearBuffer(); + player.draw(sp); + sp.render(); window.swapBuffer(); } -- cgit From 86e4aa6265ade205aba94494a7a31a83b5686387 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Wed, 3 Jan 2018 13:26:37 +0000 Subject: [Engine] [Example] Reenabled vsync and working on example. --- examples/shooter/main.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'examples/shooter/main.cpp') diff --git a/examples/shooter/main.cpp b/examples/shooter/main.cpp index d2727877..9a8d22d0 100644 --- a/examples/shooter/main.cpp +++ b/examples/shooter/main.cpp @@ -1,6 +1,7 @@ #include #include "player.h" +#include "bullet.h" using std::cout; @@ -63,6 +64,7 @@ int main(int argc, char **argv) auto textures = male_l; Player player({400, 300, 48 * 2, 64 * 2}, textures.front()); + Bullet bullet({400, 300, 25, 25}); while (!window.shouldClose()) { window.pollEvents(); @@ -120,6 +122,7 @@ int main(int argc, char **argv) window.clearBuffer(); player.draw(sp); + bullet.draw(sp); sp.render(); window.swapBuffer(); -- cgit From a47649786fb94684c415b230669fbf5343cb7c5d Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Wed, 3 Jan 2018 13:57:51 +0000 Subject: [Engine] [Example] Added simple bullets that don't move --- examples/shooter/main.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'examples/shooter/main.cpp') diff --git a/examples/shooter/main.cpp b/examples/shooter/main.cpp index 9a8d22d0..c63c0cab 100644 --- a/examples/shooter/main.cpp +++ b/examples/shooter/main.cpp @@ -1,7 +1,10 @@ #include -#include "player.h" #include "bullet.h" +#include "player.h" + +#include +#include using std::cout; @@ -10,6 +13,8 @@ int main(int argc, char **argv) yage::Window window; window.create("Shooter example", 800, 600); + std::vector> objects; + yage::Shader shader("examples/resources/textureshader.vert", "examples/resources/textureshader.frag"); @@ -64,7 +69,7 @@ int main(int argc, char **argv) auto textures = male_l; Player player({400, 300, 48 * 2, 64 * 2}, textures.front()); - Bullet bullet({400, 300, 25, 25}); + objects.push_back(std::make_unique(glm::vec4(400, 300, 25, 25))); while (!window.shouldClose()) { window.pollEvents(); @@ -116,13 +121,25 @@ int main(int argc, char **argv) c_pressed = false; } + if (window.keyPressed(yage::key::RIGHT)) { + objects.push_back(std::make_unique(glm::vec4(player.position().x, player.position().y, 25, 25))); + } else if (window.keyPressed(yage::key::DOWN)) { + + } else if (window.keyPressed(yage::key::LEFT)) { + } else if (window.keyPressed(yage::key::UP)) { + } + player.setTexture(textures[i]); camera.update(shader); window.clearBuffer(); player.draw(sp); - bullet.draw(sp); + + for(auto &&object : objects) { + object->draw(sp); + } + sp.render(); window.swapBuffer(); -- cgit From 7b95e3a9eacf296f215c73e5d8ad9090a24adb20 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Thu, 4 Jan 2018 21:36:30 +0000 Subject: [Engine] Now using stb_image to laod all kinds of textures. --- examples/shooter/main.cpp | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'examples/shooter/main.cpp') diff --git a/examples/shooter/main.cpp b/examples/shooter/main.cpp index c63c0cab..e38bf53b 100644 --- a/examples/shooter/main.cpp +++ b/examples/shooter/main.cpp @@ -1,10 +1,11 @@ #include #include "bullet.h" +#include "direction.h" #include "player.h" -#include #include +#include using std::cout; @@ -13,7 +14,7 @@ int main(int argc, char **argv) yage::Window window; window.create("Shooter example", 800, 600); - std::vector> objects; + std::vector> bullets; yage::Shader shader("examples/resources/textureshader.vert", "examples/resources/textureshader.frag"); @@ -69,7 +70,6 @@ int main(int argc, char **argv) auto textures = male_l; Player player({400, 300, 48 * 2, 64 * 2}, textures.front()); - objects.push_back(std::make_unique(glm::vec4(400, 300, 25, 25))); while (!window.shouldClose()) { window.pollEvents(); @@ -122,11 +122,33 @@ int main(int argc, char **argv) } if (window.keyPressed(yage::key::RIGHT)) { - objects.push_back(std::make_unique(glm::vec4(player.position().x, player.position().y, 25, 25))); + bullets.push_back(std::make_unique( + glm::vec4(player.position().x + player.position().z / 2.f, + player.position().y + player.position().w / 2.f, 25, + 25), + Direction::RIGHT, 10.f)); + player.look(Direction::RIGHT); } else if (window.keyPressed(yage::key::DOWN)) { - + bullets.push_back(std::make_unique( + glm::vec4(player.position().x + player.position().z / 2.f, + player.position().y + player.position().w / 2.f, 25, + 25), + Direction::DOWN, 10.f, 2)); + player.look(Direction::DOWN); } else if (window.keyPressed(yage::key::LEFT)) { + bullets.push_back(std::make_unique( + glm::vec4(player.position().x + player.position().z / 2.f, + player.position().y + player.position().w / 2.f, 25, + 25), + Direction::LEFT, 10.f, 2)); + player.look(Direction::LEFT); } else if (window.keyPressed(yage::key::UP)) { + bullets.push_back(std::make_unique( + glm::vec4(player.position().x + player.position().z / 2.f, + player.position().y + player.position().w / 2.f, 25, + 25), + Direction::UP, 10.f)); + player.look(Direction::UP); } player.setTexture(textures[i]); @@ -136,8 +158,8 @@ int main(int argc, char **argv) window.clearBuffer(); player.draw(sp); - for(auto &&object : objects) { - object->draw(sp); + for (auto &&bullet : bullets) { + bullet->draw(sp); } sp.render(); -- cgit