Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • LayeredRendering
  • NewGraphicSystem
  • main
3 results

Target

Select target project
  • b20017738/fig-project
1 result
Select Git revision
  • LayeredRendering
  • NewGraphicSystem
  • main
3 results
Show changes
Showing
with 423 additions and 16 deletions
#include "QuadGraphicModule.hpp"
#include <engine/graphics/front/object/Image.hpp>
#include <engine/graphics/front/object/Sprite.hpp>
#include <iostream>
namespace megu {
void QuadGraphicModule::draw(Image &, const Window &, const Camera &, const TextureArray &) const {
std::cout << "Image !" << std::endl;
}
void QuadGraphicModule::draw(Sprite &, const Window &, const Camera &, const TextureArray &) const {
std::cout << "Sprite !" << std::endl;
}
}
\ No newline at end of file
#pragma once
#include "Module.hpp"
namespace megu {
class Image;
class Sprite;
class QuadGraphicModule : public Module<Image>, public Module<Sprite> {
public:
void draw(Image &, const Window &, const Camera &, const TextureArray &) const override;
void draw(Sprite &, const Window &, const Camera &, const TextureArray &) const override;
};
}
\ No newline at end of file
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include <engine/graphics/back/geometry/Transformable.hpp> #include <engine/graphics/back/geometry/Transformable.hpp>
#include <engine/graphics/back/textures/Texture.hpp> #include <engine/graphics/back/textures/Texture.hpp>
#include <engine/graphics/front/geometry/Quads.hpp> #include <engine/graphics/front/geometry/Quads.hpp>
#include <engine/graphics/utility/type.hpp> #include <engine/graphics/utility/type.hpp>
......
#pragma once
#include <memory>
#include <iostream>
#include <engine/graphics/front/module/Module.hpp>
namespace megu {
class Renderable {
public:
Renderable() = delete;
template <class T, class M>
Renderable(T & object, M & module)
: _pimpl(std::make_unique<RenderableModel<T, M>>(object, module)) {}
Renderable(const Renderable & src) {
this->_pimpl = src._pimpl->clone();
}
Renderable & operator=(const Renderable & src) {
this->_pimpl = src._pimpl->clone();
return *this;
}
Renderable(Renderable &&) = default;
Renderable & operator=(Renderable &&) = default;
private:
struct RenderableConcept {
virtual ~RenderableConcept() {};
virtual void render(const Window &, const Camera &, const TextureArray &) const = 0;
virtual std::unique_ptr<RenderableConcept> clone() const = 0;
};
template <class T, class M>
struct RenderableModel : public RenderableConcept {
RenderableModel(T & v, M & m)
: _object{ v }, _module{ m } {}
void render(const Window & window, const Camera & camera, const TextureArray & array) const override {
this->_module.draw(this->_object, window, camera, array);
}
std::unique_ptr<RenderableConcept> clone() const override {
return std::make_unique<RenderableModel>(*this);
}
T & _object;
M & _module;
};
friend void render_ext(Renderable & renderable, const Window & window, const Camera & camera, const TextureArray & array) {
renderable._pimpl->render(window, camera, array);
}
std::unique_ptr<RenderableConcept> _pimpl;
};
}
\ No newline at end of file
#include "Sprite.hpp"
namespace megu {
Sprite::Sprite(const Texture & texture)
: _frame(0, 0, texture.width(), texture.height()), _texture(texture) {
this->_transformation.scale(static_cast<float>(texture.width()), static_cast<float>(texture.height()));
}
Sprite::Sprite(const Texture & texture, const glm::vec4 & frame)
: _frame(frame), _texture(texture) {
this->_transformation.move(frame.x, frame.y);
this->_transformation.scale(frame.z, frame.w);
}
}
\ No newline at end of file
#pragma once
#include <engine/graphics/back/geometry/Transformable.hpp>
#include <engine/graphics/back/textures/Texture.hpp>
#include <engine/graphics/front/geometry/Quads.hpp>
namespace megu {
class Sprite {
public:
Sprite(const Texture &);
Sprite(const Texture &, const glm::vec4 &);
inline void setFrame(const glm::vec4 & frame) {this->_frame = frame;}
inline const glm::vec4 & frame() const {return this->_frame;}
inline const Texture & texture() const {return this->_texture;}
inline const Quads & geometry() const {return this->_geometry;}
inline const Transformable & transformation() const {return this->_transformation;}
private:
glm::vec4 _frame;
Texture _texture;
Quads _geometry;
Transformable _transformation;
};
}
\ No newline at end of file
#include "VerticesArray.hpp"
namespace megu {
VerticesArray::VerticesArray(Primitive_t primitive, size_t size)
: _primitive(primitive), _vertices(size) {}
VerticesArray::VerticesArray(const VerticesArray & src)
: _transformation(src._transformation), _primitive(src._primitive), _vertices(src._vertices) {}
VerticesArray VerticesArray::operator=(const VerticesArray & src) {
this->_transformation = src._transformation;
this->_primitive = src._primitive;
this->_vertices = src._vertices;
return *this;
}
void VerticesArray::append(const Vertex & vertex) {
this->_vertices.push_back(vertex);
}
}
\ No newline at end of file
#pragma once
#include <array>
#include <engine/graphics/back/geometry/Transformable.hpp>
#include <engine/graphics/back/textures/Texture.hpp>
#include <engine/graphics/front/geometry/Quads.hpp>
#include <engine/graphics/front/geometry/Vertex.hpp>
namespace megu {
class VerticesArray {
public:
VerticesArray(Primitive_t, size_t);
VerticesArray(const VerticesArray &);
VerticesArray operator=(const VerticesArray &);
~VerticesArray() = default;
inline size_t size() const {return this->_vertices.size();}
void scale(float x, float y) {this->_transformation.scale(x, y);}
void append(const Vertex &);
const Transformable & transformation() const {return this->_transformation;}
const Primitive_t & primitive() const {return this->_primitive;}
const std::vector<Vertex> & vertices() const {return this->_vertices;}
Vertex & operator[](size_t index) {return this->_vertices[index];}
const Vertex & operator[](size_t index) const {return this->_vertices[index];}
private:
Transformable _transformation;
Primitive_t _primitive;
std::vector<Vertex> _vertices;
};
}
\ No newline at end of file
#include "isometric_sorter.hpp" #include "isometric_sorter.hpp"
#include <engine/graphics/front/object/Image.hpp> #include <engine/graphics/front/object/Image.hpp>
#include <engine/graphics/front/object/Sprite.hpp>
namespace megu { namespace megu {
bool isometric_sorter::operator()(const Image & img1, const Image & img2) const { bool isometric_sorter::operator()(const Image & img1, const Image & img2) const {
...@@ -18,4 +19,20 @@ namespace megu { ...@@ -18,4 +19,20 @@ namespace megu {
return &img1 > &img2; return &img1 > &img2;
} }
bool isometric_sorter_sprite::operator()(const Sprite & img1, const Sprite & img2) const {
if(img1.transformation().z() != img2.transformation().z()) {
return img1.transformation().z() > img2.transformation().z();
}
if(img1.transformation().y() != img2.transformation().y()) {
return img1.transformation().y() > img2.transformation().y();
}
if(img1.transformation().x() != img2.transformation().x()) {
return img1.transformation().x() > img2.transformation().x();
}
return &img1 > &img2;
}
} }
\ No newline at end of file
...@@ -2,9 +2,15 @@ ...@@ -2,9 +2,15 @@
namespace megu { namespace megu {
class Image; class Image;
class Sprite;
class isometric_sorter { class isometric_sorter {
public: public:
bool operator()(const Image & img1, const Image & img2) const; bool operator()(const Image & img1, const Image & img2) const;
}; };
class isometric_sorter_sprite {
public:
bool operator()(const Sprite & img1, const Sprite & img2) const;
};
} }
\ No newline at end of file
#pragma once
namespace megu {
template <class... Ts>
struct overloaded : Ts ... {
using Ts::operator()...;
};
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
}
\ No newline at end of file
#pragma once
#include <engine/graphics/back/textures/Texture.hpp>
namespace megu {
struct texture_comparator {
bool operator()(const Texture & t1, const Texture & t2) const {
return t1.identifier() > t2.identifier();
}
};
}
\ No newline at end of file
#include <iostream> #include <iostream>
#include <thread>
#include <GL/glew.h> #include <GL/glew.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
...@@ -13,7 +14,6 @@ ...@@ -13,7 +14,6 @@
#include <engine/io/Window.hpp> #include <engine/io/Window.hpp>
#include <engine/graphics/back/cameras/View.hpp> #include <engine/graphics/back/cameras/View.hpp>
#include <engine/graphics/front/object/Image.hpp> #include <engine/graphics/front/object/Image.hpp>
#include <engine/graphics/front/group/ImageGroup.hpp>
#include <engine/graphics/front/engine/Renderer.hpp> #include <engine/graphics/front/engine/Renderer.hpp>
#include <engine/graphics/front/engine/Engine.hpp> #include <engine/graphics/front/engine/Engine.hpp>
#include <engine/graphics/errors.hpp> #include <engine/graphics/errors.hpp>
...@@ -30,6 +30,14 @@ glm::vec2 to_screen_coordinate(const glm::vec2 & tile, float w, float h, float l ...@@ -30,6 +30,14 @@ glm::vec2 to_screen_coordinate(const glm::vec2 & tile, float w, float h, float l
}; };
} }
/*
megu::Vertex to_screen_coordinate(int x, int y, unsigned int u, unsigned int v, const megu::Texture & texture) {
return {{x, y}, {static_cast<float>(u) / static_cast<float>(texture.width()), static_cast<float>(v) / static_cast<float>(texture.height())}};
}
*/
//* Isometric :
int main(int argc, const char * argv[]) { int main(int argc, const char * argv[]) {
try { try {
//? Window //? Window
...@@ -39,10 +47,6 @@ int main(int argc, const char * argv[]) { ...@@ -39,10 +47,6 @@ int main(int argc, const char * argv[]) {
std::cout << "Window Inited" << std::endl; std::cout << "Window Inited" << std::endl;
//? Group
megu::ImageGroup group;
megu::ImageGroup group_2;
std::cout << "Group Inited" << std::endl; std::cout << "Group Inited" << std::endl;
//? Image 1 //? Image 1
...@@ -83,7 +87,6 @@ int main(int argc, const char * argv[]) { ...@@ -83,7 +87,6 @@ int main(int argc, const char * argv[]) {
++y; ++y;
} }
if(id != 0) { if(id != 0) {
switch (id % 4) { switch (id % 4) {
case 1: case 1:
...@@ -111,10 +114,10 @@ int main(int argc, const char * argv[]) { ...@@ -111,10 +114,10 @@ int main(int argc, const char * argv[]) {
++x; ++x;
} }
for(auto & i : images) { /*for(auto & i : images) {
group.add(*i); group.add(*i);
i.get()->setSize({32.f, 32.f}); i.get()->setSize({32.f, 32.f});
} }*/
std::cout << "Images 1 Inited" << std::endl; std::cout << "Images 1 Inited" << std::endl;
...@@ -153,13 +156,97 @@ int main(int argc, const char * argv[]) { ...@@ -153,13 +156,97 @@ int main(int argc, const char * argv[]) {
++x_2; ++x_2;
} }
for(auto & i : images_2) { /*for(auto & i : images_2) {
group_2.add(*i); group_2.add(*i);
i.get()->setSize({32.f, 32.f}); i.get()->setSize({32.f, 32.f});
} }*/
std::cout << "Images 2 Inited" << std::endl; std::cout << "Images 2 Inited" << std::endl;
//? Engines
megu::GraphicEngine engine(window);
megu::Renderer basic_renderer(360, 360);
engine.push(0, basic_renderer);
engine.push<megu::Image>(0, 0, *((images.front()).get()));
//? Render Loop
std::cout << "Render Loop Begin !" << std::endl;
glm::vec2 xy = {0, 0};
double previousTime = megu::Window::Time();
int frameCount = 0;
while(window.isOpen()) {
double currentTime = megu::Window::Time();
frameCount++;
if(currentTime - previousTime >= 1.0) {
window.setTitle(std::to_string(frameCount));
frameCount = 0;
previousTime = currentTime;
}
window.pollEvents();
engine.step();
}
std::cout << "Render Loop End !" << std::endl;
}
catch(std::exception & error) {
std::cerr << error.what() << std::endl;
}
return EXIT_SUCCESS;
}
//* Tilemap
/*
int main(int argc, const char * argv[]) {
try {
//? Window
megu::Window window;
window.open("Isometric Window", 360, 360);
megu::error::opengl_error::check();
std::cout << "Window Inited" << std::endl;
//? Group
megu::VertexArrayGroup group;
std::cout << "Group Inited" << std::endl;
//? Grids
megu::Texture texture_1;
texture_1.store(megu::TextureBuffer("assets/textures/Tile_Test_3.png"));
megu::VerticesArray grid_1(megu::Quads::Primitive(), 4);
//grid_1[0] = {{0.f, 0.f}, {0.0f, 0.0f}};
//grid_1[1] = {{16.f, 0.f}, {0.5f, 0.0f}};
//grid_1[2] = {{16.f, 16.f}, {0.5f, 0.5f}};
//grid_1[3] = {{0.f, 16.f}, {0.0f, 0.5f}};
grid_1[0] = to_screen_coordinate(0, 0, 0, 0, texture_1);
grid_1[1] = to_screen_coordinate(16, 0, 16, 0, texture_1);
grid_1[2] = to_screen_coordinate(16, 16, 16, 16, texture_1);
grid_1[3] = to_screen_coordinate(0, 16, 0, 16, texture_1);
grid_1.scale(1.f, 1.f);
group.add(texture_1, grid_1);
std::cout << "Grid created" << std::endl;
//? ImGui //? ImGui
//ImGui::CreateContext(); //ImGui::CreateContext();
//ImGui_ImplOpenGL3_Init(); //ImGui_ImplOpenGL3_Init();
...@@ -167,20 +254,104 @@ int main(int argc, const char * argv[]) { ...@@ -167,20 +254,104 @@ int main(int argc, const char * argv[]) {
//? Engines //? Engines
megu::GraphicEngine engine(window); megu::GraphicEngine engine(window);
megu::Renderer basic_renderer(360, 360); megu::Renderer basic_renderer(100, 100);
engine.push(0, basic_renderer); engine.push(0, basic_renderer);
engine.push(0, 0, group);
//? Render Loop
std::cout << "Render Loop Begin !" << std::endl;
double previousTime = megu::Window::Time();
int frameCount = 0;
while(window.isOpen()) {
double currentTime = megu::Window::Time();
frameCount++;
if(currentTime - previousTime >= 1.0) {
window.setTitle(std::to_string(frameCount));
frameCount = 0;
previousTime = currentTime;
}
window.pollEvents();
engine.step();
}
std::cout << "Render Loop End !" << std::endl;
}
catch(std::exception & error) {
std::cerr << error.what() << std::endl;
}
return EXIT_SUCCESS;
}*/
//* Sprite
/*
int main(int argc, const char * argv[]) {
try {
//? Window
megu::Window window;
window.open("Sprite Window", 360, 360);
megu::error::opengl_error::check();
std::cout << "Window Inited" << std::endl;
//? Group
megu::SpriteGroup group;
megu::ImageGroup group_2;
std::cout << "Group Inited" << std::endl;
//? Grids
megu::Texture texture_1;
texture_1.store(megu::TextureBuffer("assets/textures/Neera.png"));
std::vector<glm::vec4> frames;
frames.push_back({0, 0, 51, 98});
frames.push_back({51, 0, 51, 98});
frames.push_back({102, 0, 51, 98});
frames.push_back({0, 98, 51, 98});
frames.push_back({51, 98, 51, 98});
frames.push_back({102, 98, 51, 98});
megu::Sprite neera(texture_1, frames[0]);
megu::Image image(texture_1);
//neera.scale(1.f, 1.f);
group.add(neera);
group_2.add(image);
std::cout << "Sprite created" << std::endl;
//? Engines
megu::GraphicEngine engine(window);
megu::Renderer basic_renderer(128, 128);
engine.push(0, basic_renderer);
engine.push(0, 0, group); engine.push(0, 0, group);
//engine.push(0, 0, group_2);
//? Render Loop //? Render Loop
std::cout << "Render Loop Begin !" << std::endl; std::cout << "Render Loop Begin !" << std::endl;
glm::vec2 xy = {0, 0};
double previousTime = megu::Window::Time(); double previousTime = megu::Window::Time();
int frameCount = 0; int frameCount = 0;
std::thread t([&frames, &window, &neera](){
size_t i = 0;
while(window.isOpen()) {
std::this_thread::sleep_for(std::chrono::milliseconds(30));
neera.setFrame(frames[i%frames.size()]);
++i;
}
});
while(window.isOpen()) { while(window.isOpen()) {
double currentTime = megu::Window::Time(); double currentTime = megu::Window::Time();
frameCount++; frameCount++;
...@@ -195,6 +366,8 @@ int main(int argc, const char * argv[]) { ...@@ -195,6 +366,8 @@ int main(int argc, const char * argv[]) {
window.pollEvents(); window.pollEvents();
engine.step(); engine.step();
} }
t.join();
std::cout << "Render Loop End !" << std::endl; std::cout << "Render Loop End !" << std::endl;
} }
catch(std::exception & error) { catch(std::exception & error) {
...@@ -203,3 +376,5 @@ int main(int argc, const char * argv[]) { ...@@ -203,3 +376,5 @@ int main(int argc, const char * argv[]) {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
*/