2021-12-07 03:44:47 +00:00
|
|
|
#include "simpleengine/camera.h"
|
2022-09-22 02:52:06 +00:00
|
|
|
#include "simpleengine/ecs/component/mesh_component.h"
|
|
|
|
#include <simpleengine/ecs/component/model_component.h>
|
2022-09-23 04:44:07 +00:00
|
|
|
#include "simpleengine/ecs/component/transform_component.h"
|
2022-09-23 04:54:18 +00:00
|
|
|
#include <simpleengine/ecs/component/rotating_component.h>
|
2022-08-30 23:39:24 +00:00
|
|
|
#include "simpleengine/ecs/entity.h"
|
2021-12-09 04:14:45 +00:00
|
|
|
#include "simpleengine/gfx/light.h"
|
2022-08-19 04:20:53 +00:00
|
|
|
#include "simpleengine/gfx/material.h"
|
2022-09-22 02:52:06 +00:00
|
|
|
#include "simpleengine/gfx/mesh.h"
|
2021-12-07 19:51:12 +00:00
|
|
|
#include "simpleengine/gfx/model.h"
|
2022-08-19 02:40:34 +00:00
|
|
|
#include "simpleengine/gfx/renderer.h"
|
2021-11-27 18:52:48 +00:00
|
|
|
#include "simpleengine/gfx/texture.h"
|
2021-11-28 18:21:25 +00:00
|
|
|
#include "simpleengine/vector.h"
|
2021-11-27 18:52:48 +00:00
|
|
|
#include <simpleengine/gfx/shader.h>
|
2021-11-21 06:23:53 +00:00
|
|
|
#include <simpleengine/renderable.h>
|
|
|
|
#include <simpleengine/event/event.h>
|
|
|
|
#include <simpleengine/shader_program.h>
|
2021-11-20 05:48:47 +00:00
|
|
|
#include <simpleengine/game.h>
|
2021-11-25 21:15:24 +00:00
|
|
|
#include <simpleengine/vertex.h>
|
2021-12-13 03:21:10 +00:00
|
|
|
#include <simpleengine/gfx/shaders/core_3d_shader.h>
|
2022-09-22 02:52:06 +00:00
|
|
|
#include <simpleengine/gfx/model.h>
|
2022-09-23 04:44:07 +00:00
|
|
|
#include <simpleengine/scene.h>
|
|
|
|
|
2022-08-19 04:20:53 +00:00
|
|
|
#include <glm/ext/matrix_clip_space.hpp>
|
|
|
|
#include <glm/fwd.hpp>
|
2022-09-22 04:11:12 +00:00
|
|
|
#include <assimp/material.h>
|
2022-08-19 04:20:53 +00:00
|
|
|
|
|
|
|
#include <memory>
|
2021-11-20 05:48:47 +00:00
|
|
|
#include <chrono>
|
|
|
|
#include <iostream>
|
2021-11-21 06:23:53 +00:00
|
|
|
#include <sstream>
|
2021-11-25 21:15:24 +00:00
|
|
|
#include <stdint.h>
|
2021-11-21 06:23:53 +00:00
|
|
|
|
|
|
|
#include <cmrc/cmrc.hpp>
|
|
|
|
CMRC_DECLARE(resource_shaders);
|
|
|
|
|
2021-12-13 03:21:10 +00:00
|
|
|
namespace se = simpleengine;
|
|
|
|
|
2022-09-16 15:14:38 +00:00
|
|
|
class FPSCounterEvent : public se::Event {
|
|
|
|
public:
|
|
|
|
double last_frame_time;
|
|
|
|
int frame_count;
|
|
|
|
|
|
|
|
FPSCounterEvent() : se::Event() {
|
|
|
|
this->last_frame_time = glfwGetTime();
|
|
|
|
frame_count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void update(const float& delta_time) {
|
|
|
|
double current_time = glfwGetTime();
|
|
|
|
frame_count++;
|
|
|
|
|
|
|
|
// Check if the last print was 1 second ago.
|
|
|
|
if (current_time - last_frame_time >= 1.0) {
|
|
|
|
double ms_per_frame = 1000 / (double) frame_count;
|
|
|
|
|
|
|
|
printf("%d fps, %f ms/frame\n", frame_count, ms_per_frame);
|
|
|
|
frame_count = 0;
|
|
|
|
last_frame_time += 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-11-21 06:23:53 +00:00
|
|
|
std::string read_resource_shader(const std::string& path) {
|
|
|
|
auto fs = cmrc::resource_shaders::get_filesystem();
|
|
|
|
cmrc::file vertex_file = fs.open(path);
|
|
|
|
|
|
|
|
return std::string(vertex_file.begin());
|
|
|
|
}
|
2021-11-20 05:48:47 +00:00
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2021-12-13 03:21:10 +00:00
|
|
|
se::Game game(640, 480, "SimpleEngine 3D OpenGL - Developer Testing", GLFW_OPENGL_CORE_PROFILE, 4, 4, false);
|
2021-11-21 06:23:53 +00:00
|
|
|
|
2021-12-13 03:21:10 +00:00
|
|
|
/* se::gfx::Texture wall_texture("resources/wall.jpg");
|
|
|
|
se::gfx::Texture crate_texture("resources/container.jpg", true, true); */
|
2021-11-27 18:52:48 +00:00
|
|
|
|
2022-08-18 15:34:05 +00:00
|
|
|
// Load core shaders from SimpleEngine resources
|
2021-12-13 03:21:10 +00:00
|
|
|
se::gfx::shaders::Core3dShader core_shader;
|
2021-12-07 05:17:04 +00:00
|
|
|
|
2022-08-18 15:34:05 +00:00
|
|
|
auto light = std::make_shared<se::gfx::Light>(core_shader, glm::vec3(0.f, 1.f, -10.f), glm::vec3(1.f, 1.f, 1.f));
|
2021-12-09 04:14:45 +00:00
|
|
|
game.add_event(light);
|
|
|
|
|
2022-09-22 04:11:12 +00:00
|
|
|
auto white_texture = se::gfx::Texture::white_texture();
|
2022-08-18 15:34:05 +00:00
|
|
|
// white_texture.shine_damper = 10;
|
|
|
|
//white_texture.reflectivity = 1;
|
|
|
|
/* auto dragon = std::make_shared<se::objects_3d::Mesh>(game.get_window(), core_shader, white_texture, "examples/dev_testing/resources/dragon.obj");
|
|
|
|
dragon->translate(0.f, -5.f, -15.f);
|
|
|
|
game.add_event(dragon); */
|
|
|
|
|
|
|
|
/* auto cube = std::make_shared<se::objects_3d::Mesh>(game.get_window(), core_shader, white_texture, "examples/dev_testing/resources/cube.obj");
|
|
|
|
cube->translate(0.f, -5.f, -15.f);
|
|
|
|
game.add_event(cube);
|
|
|
|
|
|
|
|
se::gfx::Texture grass("examples/dev_testing/resources/grass.png");
|
|
|
|
auto terrain = std::make_shared<se::objects_3d::Terrain>(game.get_window(), core_shader, grass, 0, 0);
|
|
|
|
terrain->translate(0.f, -5.f, -15.f);
|
|
|
|
game.add_event(terrain); */
|
|
|
|
|
2022-08-18 20:03:51 +00:00
|
|
|
/* se::gfx::Texture stall_texture("examples/dev_testing/resources/stallTextureb.png");
|
2022-08-18 15:34:05 +00:00
|
|
|
auto stall = std::make_shared<se::objects_3d::Mesh>(game.get_window(), core_shader, stall_texture, "examples/dev_testing/resources/stall.obj");
|
|
|
|
stall->translate(10.f, -5.f, 0.f);
|
|
|
|
stall->rotate_y(90.f);
|
2022-08-18 20:03:51 +00:00
|
|
|
game.add_event(stall); */
|
2021-12-07 05:17:04 +00:00
|
|
|
|
2021-12-13 03:21:10 +00:00
|
|
|
/* std::vector<se::Vertex> square_vertices = {
|
|
|
|
{ se::Vectorf(0.5f, 0.5f, -1.f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(0.f, 0.f) }, // top right
|
|
|
|
{ se::Vectorf(0.5f, -0.5f, -1.f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, // bottom right
|
|
|
|
{ se::Vectorf(-0.5f, -0.5f, -1.f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.5f, 1.0f) }, // bottom left
|
|
|
|
{ se::Vectorf(-0.5f, 0.5f, -1.f), glm::vec3(.5f, 0.5f, 0.f), glm::vec2(0.5f, 1.0f) }, // top left
|
2021-12-07 19:51:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<GLuint> indicies = {
|
|
|
|
0, 1, 3,
|
|
|
|
1, 2, 3
|
|
|
|
};
|
|
|
|
|
2021-12-13 03:21:10 +00:00
|
|
|
auto square = std::make_shared<se::gfx::Model>(game.get_window(), core_shader, square_vertices, indicies);
|
2021-12-07 19:51:12 +00:00
|
|
|
square->translate(1.25f, 0.f, -1.f);
|
2022-08-18 15:34:05 +00:00
|
|
|
//square->rotate_y(90.f);
|
|
|
|
//square->scale(.75f);
|
|
|
|
game.add_event(square); */
|
|
|
|
|
|
|
|
/* se::gfx::Texture white_texture("examples/dev_testing/resources/white_texture.png");
|
|
|
|
auto cube = std::make_shared<se::objects_3d::Mesh>(game.get_window(), core_shader, white_texture, "examples/dev_testing/resources/cube.obj");
|
|
|
|
cube->translate(-1.25f, 0.f, -1.f);
|
|
|
|
game.add_event(cube); */
|
2021-12-07 19:51:12 +00:00
|
|
|
|
2022-08-18 15:34:05 +00:00
|
|
|
/* std::vector<se::Vertex> tri_vertices = {
|
2021-12-13 03:21:10 +00:00
|
|
|
{ se::Vectorf(-0.5f, -0.5f, -1.f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(0.f, 0.f) }, // top right
|
|
|
|
{ se::Vectorf(0.5f, -0.5f, -1.f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, // bottom right
|
|
|
|
{ se::Vectorf(0.f, 0.5f, -1.f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.5f, 1.0f) }, // bottom left
|
2021-11-25 21:15:24 +00:00
|
|
|
};
|
|
|
|
|
2021-12-13 03:21:10 +00:00
|
|
|
auto tri = std::make_shared<se::gfx::Model>(game.get_window(), core_shader, tri_vertices);
|
2021-12-07 19:51:12 +00:00
|
|
|
tri->translate(-1.25f, 0.f, -1.f);
|
|
|
|
tri->scale(.75f);
|
2021-12-07 05:17:04 +00:00
|
|
|
game.add_event(tri); */
|
2021-11-25 21:15:24 +00:00
|
|
|
|
2022-08-18 20:03:51 +00:00
|
|
|
std::vector<se::LitVertex> cube_vertices = {
|
2022-08-18 15:34:05 +00:00
|
|
|
{ se::Vectorf(-1.f, -1.f, -1.f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(0.f, 0.f) },
|
|
|
|
{ se::Vectorf(1.f, -1.f, -1.f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
|
|
|
{ se::Vectorf(1.f, 1.f, -1.f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(2.f, 0.f) },
|
|
|
|
{ se::Vectorf(-1.f, 1.f, -1.f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(3.f, 0.f) },
|
|
|
|
{ se::Vectorf(-1, -1, -1), glm::vec3(1.f, 1.f, 0.f), glm::vec2(4.f, 0.f) },
|
|
|
|
|
|
|
|
{ se::Vectorf(-1, -1, 1), glm::vec3(1.f, 0.f, 0.f), glm::vec2(0.f, 1.f) },
|
|
|
|
{ se::Vectorf(1, -1, 1), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 1.f) },
|
|
|
|
{ se::Vectorf(1, 1, 1), glm::vec3(0.f, 0.f, 1.f), glm::vec2(2.f, 1.f) },
|
|
|
|
{ se::Vectorf(-1, 1, 1), glm::vec3(1.f, 1.f, 0.f), glm::vec2(3.f, 1.f) },
|
|
|
|
{ se::Vectorf(-1, -1, 1), glm::vec3(1.f, 1.f, 0.f), glm::vec2(4.f, 1.f) },
|
|
|
|
|
|
|
|
{ se::Vectorf(-1, 1, -1), glm::vec3(1.f, 0.f, 0.f), glm::vec2(0.f, -1.f) },
|
|
|
|
{ se::Vectorf(1, 1, -1), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, -1.f) },
|
|
|
|
|
|
|
|
{ se::Vectorf(-1, 1, 1), glm::vec3(1.f, 0.f, 0.f), glm::vec2(0.f, 2.f) },
|
|
|
|
{ se::Vectorf(1, 1, 1), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 2.f) },
|
2021-11-25 21:15:24 +00:00
|
|
|
};
|
|
|
|
|
2021-12-07 20:19:40 +00:00
|
|
|
std::vector<GLuint> cube_indicies = {
|
2022-08-18 15:34:05 +00:00
|
|
|
0, 1, 5, 5, 1, 6,
|
|
|
|
1, 2, 6, 6, 2, 7,
|
|
|
|
2, 3, 7, 7, 3, 8,
|
|
|
|
3, 4, 8, 8, 4, 9,
|
|
|
|
10, 11, 0, 0, 11, 1,
|
|
|
|
5, 6, 12, 12, 6, 13
|
2021-11-25 21:15:24 +00:00
|
|
|
};
|
|
|
|
|
2022-09-27 03:43:08 +00:00
|
|
|
std::unordered_map<aiTextureType, std::vector<std::shared_ptr<se::gfx::Texture>>> textures;
|
|
|
|
textures.emplace(white_texture.type, std::vector<std::shared_ptr<se::gfx::Texture>>{ std::make_shared<se::gfx::Texture>(white_texture) });
|
2022-09-22 04:11:12 +00:00
|
|
|
se::gfx::Material white_material(textures, 1.f, 0.f, 0.f, 0.f, 0.f);
|
2022-08-19 04:20:53 +00:00
|
|
|
|
2022-09-23 04:44:07 +00:00
|
|
|
// Create a renderer
|
|
|
|
auto renderer = std::make_shared<se::gfx::Renderer>(game.get_window(), core_shader);
|
|
|
|
game.add_renderable(renderer);
|
|
|
|
|
|
|
|
// Create a Scene and give it the renderer
|
|
|
|
auto scene = std::make_shared<se::Scene>(renderer);
|
|
|
|
game.add_event(scene);
|
|
|
|
|
|
|
|
// Create an Entity in the Scene and add components to it.
|
|
|
|
se::ecs::Entity entity = scene->create_entity();
|
2022-09-27 03:43:08 +00:00
|
|
|
//entity.add_component<se::ModelComponent>("examples/dev_testing/resources/dragon.obj");
|
|
|
|
//entity.add_component<se::ModelComponent>("examples/dev_testing/resources/stall.obj");
|
|
|
|
entity.add_component<se::ModelComponent>("examples/dev_testing/resources/backpack/backpack.obj");
|
|
|
|
//entity.add_component<se::ModelComponent>("examples/dev_testing/resources/scientist/scientist.fbx");
|
|
|
|
//entity.add_component<se::ModelComponent>("examples/dev_testing/resources/paradigm/paradigm.fbx");
|
|
|
|
//entity.add_component<se::RotatingComponent>();
|
2022-09-23 04:44:07 +00:00
|
|
|
auto& transform_comp = entity.add_component<se::TransformComponent>();
|
2022-09-27 03:43:08 +00:00
|
|
|
transform_comp.translate(15.f, -8.f, 0.f);
|
|
|
|
/* transform_comp.scale(0.1f);
|
|
|
|
transform_comp.rotate_z(-90.f);*/
|
|
|
|
transform_comp.rotate_x(-90.f);
|
2022-09-23 04:44:07 +00:00
|
|
|
|
|
|
|
|
2022-09-16 15:50:33 +00:00
|
|
|
// Create the entity and add the model component to it.
|
2022-09-16 21:39:24 +00:00
|
|
|
/* auto entity = std::make_shared<simpleengine::Entity>();
|
2022-09-22 04:11:12 +00:00
|
|
|
entity->add_component<se::MeshComponent>(cube_vertices, cube_indicies, white_material, true);
|
2022-09-16 21:39:24 +00:00
|
|
|
entity->translate(3.5f, 0.f, 0.f); */
|
|
|
|
|
2022-09-23 04:44:07 +00:00
|
|
|
/* auto entity = std::make_shared<simpleengine::Entity>();
|
2022-09-22 02:52:06 +00:00
|
|
|
entity->add_component<se::ModelComponent>("examples/dev_testing/resources/dragon.obj");
|
2022-09-23 04:44:07 +00:00
|
|
|
entity->translate(12.f, -4.f, 0.f); */
|
2021-11-20 05:48:47 +00:00
|
|
|
|
2022-08-18 15:34:05 +00:00
|
|
|
auto camera = std::make_shared<se::Camera>(game.get_window(), core_shader, 70, glm::vec3(0, 0, 0));
|
2021-12-07 03:44:47 +00:00
|
|
|
game.add_event(camera);
|
|
|
|
|
2022-09-16 15:14:38 +00:00
|
|
|
auto fps_counter = std::make_shared<FPSCounterEvent>();
|
|
|
|
game.add_event(fps_counter);
|
|
|
|
|
|
|
|
game.set_enable_vsync(true);
|
|
|
|
//game.set_fps_limit(120);
|
2022-08-30 23:39:24 +00:00
|
|
|
int res = game.run();
|
|
|
|
|
|
|
|
renderer->destroy();
|
|
|
|
|
|
|
|
return res;
|
2021-11-20 05:48:47 +00:00
|
|
|
}
|