2021-11-27 18:52:48 +00:00
|
|
|
#include "simpleengine/gfx/texture.h"
|
2021-11-25 21:15:24 +00:00
|
|
|
#include "simpleengine/shapes/2d/square.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-21 06:23:53 +00:00
|
|
|
#include <simpleengine/shapes/2d/triangle.h>
|
2021-11-25 21:15:24 +00:00
|
|
|
#include <simpleengine/vertex.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");
|
|
|
|
|
|
|
|
// Create shader program
|
|
|
|
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();
|
|
|
|
std::shared_ptr<GLuint> base_shader_program = shader_prog.program;
|
|
|
|
|
2021-11-27 19:11:07 +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-11-26 03:28:47 +00:00
|
|
|
std::vector<simpleengine::Vertex> vertices = {
|
2021-11-27 18:52:48 +00:00
|
|
|
{glm::vec3(-0.5f, -0.5f, 0.f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(0.f, 0.f)}, // bottom left
|
|
|
|
{glm::vec3(0.5f, -0.5f, 0.f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f)}, // bottom right
|
|
|
|
{glm::vec3(0.f, 0.5f, 0.f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.5f, 1.0f)}, // top
|
2021-11-25 21:15:24 +00:00
|
|
|
};
|
|
|
|
|
2021-11-27 19:06:51 +00:00
|
|
|
auto tri = std::make_shared<simpleengine::shapes_2d::Triangle>(base_shader_program, vertices);
|
|
|
|
tri->set_texture(wall_texture);
|
2021-11-25 22:02:08 +00:00
|
|
|
game.add_event(tri);
|
2021-11-25 21:15:24 +00:00
|
|
|
|
2021-11-26 03:28:47 +00:00
|
|
|
/* std::vector<simpleengine::Vertex> vertices = {
|
2021-11-27 18:52:48 +00:00
|
|
|
{ glm::vec3(0.5f, 0.5f, 0.f), glm::vec3(1.f, 0.f, 0.f), glm::vec2(1.f, 1.f) },
|
|
|
|
{ glm::vec3(0.5f, -0.5f, 0.f), glm::vec3(0.f, 1.f, 0.f), glm::vec2(1.f, 0.f) },
|
|
|
|
{ glm::vec3(-0.5f, -0.5f, 0.f), glm::vec3(0.f, 0.f, 1.f), glm::vec2(0.f, 0.f) },
|
|
|
|
{ glm::vec3(-0.5f, 0.5f, 0.f), glm::vec3(1.f, 1.f, 0.f), glm::vec2(0.f, 1.f) },
|
2021-11-25 21:15:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<GLuint> indicies = {
|
2021-11-26 03:28:47 +00:00
|
|
|
0, 1, 3,
|
|
|
|
1, 2, 3
|
2021-11-25 21:15:24 +00:00
|
|
|
};
|
|
|
|
|
2021-11-27 19:06:51 +00:00
|
|
|
auto square = std::make_shared<simpleengine::shapes_2d::Square>(base_shader_program, vertices, indicies);
|
|
|
|
//square->set_texture(crate_texture);
|
2021-11-25 22:02:08 +00:00
|
|
|
game.add_event(square); */
|
2021-11-20 05:48:47 +00:00
|
|
|
|
|
|
|
return game.run();
|
|
|
|
}
|