2021-12-07 03:44:47 +00:00
|
|
|
#include "simpleengine/camera.h"
|
2021-12-09 04:14:45 +00:00
|
|
|
#include "simpleengine/gfx/light.h"
|
2021-12-07 19:51:12 +00:00
|
|
|
#include "simpleengine/gfx/model.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-12-07 03:44:47 +00:00
|
|
|
#include <glm/ext/matrix_clip_space.hpp>
|
2021-12-09 04:14:45 +00:00
|
|
|
#include <glm/fwd.hpp>
|
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-07 05:17:04 +00:00
|
|
|
#include <simpleengine/objects/3d/obj_model.h>
|
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-11-27 18:52:48 +00:00
|
|
|
#include <SOIL2/SOIL2.h>
|
|
|
|
|
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-11-25 21:15:24 +00:00
|
|
|
simpleengine::Game game(640, 480, "SimpleEngine 3D OpenGL - Developer Testing", GLFW_OPENGL_CORE_PROFILE, 4, 4, false);
|
2021-11-21 06:23:53 +00:00
|
|
|
|
|
|
|
// Load shaders
|
|
|
|
std::string vertex_core = read_resource_shader("shaders/vertex_core.glsl");
|
|
|
|
std::string fragment_core = read_resource_shader("shaders/fragment_core.glsl");
|
|
|
|
|
2021-12-08 01:49:25 +00:00
|
|
|
// Compile shader program
|
2021-11-21 06:23:53 +00:00
|
|
|
simpleengine::ShaderProgram shader_prog;
|
2021-11-27 18:52:48 +00:00
|
|
|
shader_prog.add_shader_from_source(simpleengine::gfx::ShaderType::ST_Vertex, vertex_core);
|
|
|
|
shader_prog.add_shader_from_source(simpleengine::gfx::ShaderType::ST_Fragment, fragment_core);
|
2021-11-21 06:23:53 +00:00
|
|
|
shader_prog.link();
|
2021-12-08 01:49:25 +00:00
|
|
|
simpleengine::gfx::Shader core_shader = shader_prog.shaders.front();
|
2021-11-21 06:23:53 +00:00
|
|
|
|
2021-12-07 03:44:47 +00:00
|
|
|
/* simpleengine::gfx::Texture wall_texture("resources/wall.jpg");
|
|
|
|
simpleengine::gfx::Texture crate_texture("resources/container.jpg", true, true); */
|
2021-11-27 18:52:48 +00:00
|
|
|
|
2021-12-07 05:17:04 +00:00
|
|
|
|
2021-12-09 04:14:45 +00:00
|
|
|
auto light = std::make_shared<simpleengine::gfx::Light>(core_shader, glm::vec3(0.f, 0.f, -20.f), glm::vec3(1.f, 1.f, 1.f));
|
|
|
|
game.add_event(light);
|
|
|
|
|
|
|
|
simpleengine::gfx::Texture white_texture("resources/white_texture.jpg");
|
|
|
|
auto dragon = std::make_shared<simpleengine::objects_3d::ObjModel>(game.get_window(), core_shader, white_texture, "resources/dragon.obj");
|
|
|
|
dragon->translate(0.f, -5.f, -25.f);
|
|
|
|
game.add_event(dragon);
|
|
|
|
|
|
|
|
/* simpleengine::gfx::Texture stall_texture("resources/stallTexture.png");
|
2021-12-08 01:49:25 +00:00
|
|
|
auto stall = std::make_shared<simpleengine::objects_3d::ObjModel>(game.get_window(), core_shader, stall_texture, "resources/stall.obj");
|
2021-12-09 04:14:45 +00:00
|
|
|
stall->translate(0.f, -4.f, -25.f);
|
|
|
|
game.add_event(stall); */
|
2021-12-07 05:17:04 +00:00
|
|
|
|
2021-12-07 19:51:12 +00:00
|
|
|
/* std::vector<simpleengine::Vertex> square_vertices = {
|
|
|
|
{ simpleengine::Vectorf(0.5f, 0.5f, -1.f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(0.f, 0.f) }, // top right
|
|
|
|
{ simpleengine::Vectorf(0.5f, -0.5f, -1.f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, // bottom right
|
|
|
|
{ simpleengine::Vectorf(-0.5f, -0.5f, -1.f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.5f, 1.0f) }, // bottom left
|
|
|
|
{ simpleengine::Vectorf(-0.5f, 0.5f, -1.f), glm::vec3(.5f, 0.5f, 0.f), glm::vec2(0.5f, 1.0f) }, // top left
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<GLuint> indicies = {
|
|
|
|
0, 1, 3,
|
|
|
|
1, 2, 3
|
|
|
|
};
|
|
|
|
|
2021-12-08 01:49:25 +00:00
|
|
|
auto square = std::make_shared<simpleengine::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);
|
|
|
|
square->scale(.75f);
|
|
|
|
game.add_event(square);
|
|
|
|
|
|
|
|
std::vector<simpleengine::Vertex> tri_vertices = {
|
|
|
|
{ simpleengine::Vectorf(-0.5f, -0.5f, -1.f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(0.f, 0.f) }, // top right
|
2021-12-07 03:44:47 +00:00
|
|
|
{ simpleengine::Vectorf(0.5f, -0.5f, -1.f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) }, // bottom right
|
2021-12-07 19:51:12 +00:00
|
|
|
{ simpleengine::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-08 01:49:25 +00:00
|
|
|
auto tri = std::make_shared<simpleengine::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
|
|
|
|
2021-12-07 20:19:40 +00:00
|
|
|
/* std::vector<simpleengine::Vertex> cube_vertices = {
|
2021-12-07 03:44:47 +00:00
|
|
|
{ simpleengine::Vectorf(-0.5f,0.5f,-0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
|
|
|
{ simpleengine::Vectorf(-0.5f,-0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
|
|
|
{ simpleengine::Vectorf(0.5f,-0.5f,-0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
|
|
|
{ simpleengine::Vectorf(0.5f,0.5f,-0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
|
|
|
|
|
|
|
{ simpleengine::Vectorf(-0.5f,0.5f,0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
|
|
|
{ simpleengine::Vectorf(-0.5f,-0.5f,0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
|
|
|
{ simpleengine::Vectorf(0.5f,-0.5f,0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
|
|
|
{ simpleengine::Vectorf(0.5f,0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
|
|
|
|
|
|
|
{ simpleengine::Vectorf(0.5f,0.5f,-0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
|
|
|
{ simpleengine::Vectorf(0.5f,-0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
|
|
|
{ simpleengine::Vectorf(0.5f,-0.5f,0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
|
|
|
{ simpleengine::Vectorf(0.5f,0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
|
|
|
|
|
|
|
{ simpleengine::Vectorf(-0.5f,0.5f,-0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
|
|
|
{ simpleengine::Vectorf(-0.5f,-0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
|
|
|
{ simpleengine::Vectorf(-0.5f,-0.5f,0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
|
|
|
{ simpleengine::Vectorf(-0.5f,0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
|
|
|
|
|
|
|
{ simpleengine::Vectorf(-0.5f,0.5f,0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
|
|
|
{ simpleengine::Vectorf(-0.5f,0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
|
|
|
{ simpleengine::Vectorf(0.5f,0.5f,-0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
|
|
|
{ simpleengine::Vectorf(0.5f,0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
|
|
|
|
|
|
|
{ simpleengine::Vectorf(-0.5f,-0.5f,0.5f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
|
|
|
{ simpleengine::Vectorf(-0.5f,-0.5f,-0.5f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
|
|
|
{ simpleengine::Vectorf(0.5f,-0.5f,-0.5f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
|
|
|
{ simpleengine::Vectorf(0.5f,-0.5f,0.5f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
2021-11-25 21:15:24 +00:00
|
|
|
};
|
|
|
|
|
2021-12-07 20:19:40 +00:00
|
|
|
std::vector<GLuint> cube_indicies = {
|
2021-12-07 03:44:47 +00:00
|
|
|
0,1,3,
|
|
|
|
3,1,2,
|
|
|
|
4,5,7,
|
|
|
|
7,5,6,
|
|
|
|
8,9,11,
|
|
|
|
11,9,10,
|
|
|
|
12,13,15,
|
|
|
|
15,13,14,
|
|
|
|
16,17,19,
|
|
|
|
19,17,18,
|
|
|
|
20,21,23,
|
|
|
|
23,21,22
|
2021-11-25 21:15:24 +00:00
|
|
|
};
|
|
|
|
|
2021-12-08 01:49:25 +00:00
|
|
|
auto cube = std::make_shared<simpleengine::gfx::Model>(game.get_window(), core_shader, cube_vertices, cube_indicies);
|
2021-12-07 20:19:40 +00:00
|
|
|
game.add_event(cube); */
|
2021-11-20 05:48:47 +00:00
|
|
|
|
2021-12-09 04:14:45 +00:00
|
|
|
auto camera = std::make_shared<simpleengine::Camera>(game.get_window(), core_shader, 70, glm::vec3(0, 0, -10));
|
2021-12-07 03:44:47 +00:00
|
|
|
game.add_event(camera);
|
|
|
|
|
2021-11-20 05:48:47 +00:00
|
|
|
return game.run();
|
|
|
|
}
|