Select Git revision
GameController.java
Forked from
TRAVERS Corentin / flooding-template
Source project has a limited visibility.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
main.cpp 4.18 KiB
#include <iostream>
#include <thread>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
//#include <imgui.h>
//#include <imgui_impl_glfw.h>
//#include <imgui_impl_opengl3.h>
#define WINDOW_WIDTH 1280
#define WINDOW_HEIGHT 720
#include <engine/io/Window.hpp>
#include <engine/graphics/back/cameras/View.hpp>
#include <engine/graphics/front/object/Image.hpp>
#include <engine/graphics/front/object/Sprite.hpp>
#include <engine/graphics/front/object/Text.hpp>
#include <engine/graphics/front/object/TileArray.hpp>
#include <engine/graphics/front/module/Quad_Module.hpp>
#include <engine/graphics/front/engine/Renderer.hpp>
#include <engine/graphics/front/engine/Engine.hpp>
#include <engine/graphics/errors.hpp>
const float i_x = 1.f;
const float i_y = 0.5f;
const float j_x = -1.f;
const float j_y = 0.5f;
megu::Vec2 to_screen_coordinate(const megu::Vec2 & tile, float w, float h, float layer = 0.0f) {
return {
(tile.x + layer) * i_x * 0.5f * w + (tile.y + layer) * j_x * 0.5f * w,
(tile.x + layer) * i_y * 0.5f * h + (tile.y + layer) * j_y * 0.5f * h
};
}
/*
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())}};
}
*/
int main(int argc, const char * argv[]) {
try {
megu::Window window;
window.open("Isometric Window", 360, 360);
std::cout << "Window Inited" << std::endl;
megu::Image image("assets/textures/Image_Test.png");
megu::Sprite sprite("assets/textures/Neera.png");
sprite.setSize({25, 49});
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});
sprite.setFrame(frames[0]);
sprite.move({32, 0});
megu::Text text("Hello World !");
text.loadFont("assets/textures/letters.png");
char chars[36] = {
' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
float x = 0;
for(auto c : chars) {
text.addGlyph(c, {x, 0, 9, 11});
x += 9;
}
std::cout << "Using " << text.characters().size() << " characters !" << std::endl;
text.scale({200, 200});
megu::TileArray tiles("assets/textures/Tile_Test_4.png", 3, 3, 32.f);
megu::GraphicEngine engine(window);
megu::Renderer basic_renderer(128, 128);
megu::ref_set<megu::Image> images_set;
images_set.insert(image);
megu::ref_set<megu::Sprite> sprites_set;
sprites_set.insert(sprite);
megu::Quad_Module modul;
engine.push(0, basic_renderer);
engine.push(0, 1, images_set, &modul);
engine.push(0, 3, sprites_set, &modul);
engine.push(0, 2, text, &modul);
engine.push(0, 0, tiles, &modul);
double previousTime = megu::Window::Time();
int frameCount = 0;
std::thread t([&frames, &sprite, &window](){
size_t i = 0;
while(window.isOpen()) {
std::this_thread::sleep_for(std::chrono::milliseconds(30));
sprite.setFrame(frames[i%frames.size()]);
++i;
}
});
std::cout << "Render Loop Start !" << std::endl;
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();
}
t.join();
std::cout << "Render Loop End !" << std::endl;
}
catch(std::exception & error) {
std::cerr << error.what() << std::endl;
}
return EXIT_SUCCESS;
}