initial commit

This commit is contained in:
Andrey Zimin
2024-05-15 09:09:36 +03:00
commit a0b5e810f7
130 changed files with 4925 additions and 0 deletions

26
bin/layers/meson.build Executable file
View File

@@ -0,0 +1,26 @@
inc += include_directories('.')
headers = [
'test_panel/test_panel.hpp',
'test_panel_2/test_panel_2.hpp',
'opengl_panel/opengl_panel.hpp',
]
sources = [
'test_panel/test_panel.cpp',
'test_panel_2/test_panel_2.cpp',
'opengl_panel/opengl_panel.cpp',
]
lib = library(
'vertex_engine_sandbox',
include_directories : inc,
sources: [headers, sources],
dependencies : deps,
cpp_args: args
)
deps += declare_dependency(
include_directories: inc,
link_with: lib,
)

View File

@@ -0,0 +1,107 @@
#include "opengl_panel.hpp"
#include "utils.hpp"
namespace sandbox
{
cube::cube()
{
hack::log()("create cube");
const std::filesystem::path vsp { "/mnt/raid/projects/vertex_engine/bin/layers/opengl_panel/shaders/vertes.shader" };
const std::filesystem::path fsp { "/mnt/raid/projects/vertex_engine/bin/layers/opengl_panel/shaders/frag.shader" };
add_shader(GL_VERTEX_SHADER, vsp);
add_shader(GL_FRAGMENT_SHADER, fsp);
shader_program::link();
m_vertices =
{
-0.1f, 0.0f, 0.7f,
0.1f, 0.0f, 0.7f,
0.1f, 0.0f, -0.7f,
-0.1f, 0.0f, -0.7f,
0.0f, 0.3f, 0.0f
};
m_indices =
{
0, 1, 1, 4, 4, 0,
0, 3, 3, 4, 4, 2,
2, 1, 3, 2
};
buffer::link();
}
void cube::use() { shader_program::use(); }
void cube::set_scale(float val) { set("scale", val); }
void cube::set_position(glm::vec3 val) { set("position", val); }
void cube::set_color(glm::vec4 val) { set("color", val); }
void cube::render() { buffer::render(); }
void opengl_panel::on_attach()
{
hack::log()("on_attach");
}
void opengl_panel::on_detach()
{
hack::log()("on_attach");
}
void opengl_panel::render()
{
// glm::mat4 view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp);
// glm::mat4 projection = glm::perspective(glm::radians(45.0f), 800.0f / 600.0f, 0.1f, 100.0f);
cb_1.use();
// unsigned int viewLoc = glGetUniformLocation(cb_1.get_id(), "view");
// glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
// unsigned int projLoc = glGetUniformLocation(cb_1.get_id(), "projection");
// glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projection));
float r = std::sin(glfwGetTime());
float g = std::cos(glfwGetTime());
cb_1.set_color(glm::vec4{ 0.85f, 0.45f, 0.95f, 0.f }); // розовый
cb_1.set_scale(1.0f + std::sin(glfwGetTime()) * 0.2f);
cb_1.set_position(glm::vec3{ 0.f, 0.5, 0.f });
cb_1.render();
r = std::cos(glfwGetTime());
g = std::sin(glfwGetTime());
cb_2.use();
// unsigned int viewLoc_1 = glGetUniformLocation(cb_2.get_id(), "view");
// glUniformMatrix4fv(viewLoc_1, 1, GL_FALSE, glm::value_ptr(view));
// unsigned int projLoc_1 = glGetUniformLocation(cb_2.get_id(), "projection");
// glUniformMatrix4fv(projLoc_1, 1, GL_FALSE, glm::value_ptr(projection));
cb_2.set_color(glm::vec4{ 0.66f, 0.66f, 0.66f, 0.f }); // серый/белый
cb_2.set_scale(1.0f - std::cos(glfwGetTime()) * 0.2f);
cb_2.set_position(glm::vec3{ r, g, 0.f });
cb_2.render();
}
void opengl_panel::on_event(VE::event e)
{
// для событий от перефирии
// if (e.m_type.type() == typeid(VE::event_type))
// {
// auto t = std::any_cast<VE::event_type>(e.m_type);
// if (t != VE::event_type::MOUSE_CURSOR_POSITION)
// hack::log()((int)t);
// }
if (e.m_type.type() == typeid(test_event))
{
auto t = std::any_cast<test_event>(e.m_type);
if (t == test_event::TEST_EVEN)
hack::log()(std::any_cast<std::string>(e.m_data));
}
}
}

View File

@@ -0,0 +1,30 @@
#pragma once
#include "VE.hpp"
namespace sandbox
{
class cube : public VE::opengl
{
public:
cube();
~cube() = default;
public:
void set_scale(float val);
void set_position(glm::vec3 val);
void set_color(glm::vec4 val);
void use();
void render();
};
class opengl_panel : public VE::layer
{
VE_FN_OVERIDE();
cube cb_1;
cube cb_2;
};
}

View File

@@ -0,0 +1,9 @@
#version 330 core
in vec4 v_color;
out vec4 f_color;
void main()
{
f_color = v_color;
}

View File

@@ -0,0 +1,22 @@
#version 330 core
layout (location = 0) in vec3 base_position;
uniform float scale;
uniform vec4 color;
uniform vec3 position;
uniform mat4 view;
uniform mat4 model;
uniform mat4 projection;
out vec4 v_color;
void main()
{
vec3 p = base_position + position * scale ;
// gl_Position = projection * view * vec4(p, 1.0);
gl_Position = vec4(p, 1.0);
v_color = color;
}

View File

@@ -0,0 +1,40 @@
#include "test_panel.hpp"
#include "utils.hpp"
namespace sandbox
{
void test_panel::on_attach()
{
hack::log()("on_attach");
// set layer params
// m_passport.m_name = "test_panel";
m_passport.m_size = mt::vec2{ 600.f, 100.f };
m_passport.m_pos = mt::vec2{ 100.f, 100.f };
// устанавливаем/убираем флаги отличные от установки по умолчанию
// в данном примере убираем флаг
m_window_flags &= ~ImGuiWindowFlags_NoTitleBar;
}
void test_panel::on_detach()
{
hack::log()("on_attach");
}
void test_panel::render()
{
begin();
if (ImGui::Button("RUN", ImVec2(28, 30)))
{
VE::event e { test_event::TEST_EVEN , std::string("test event message") };
execute(e);
}
end();
}
void test_panel::on_event(VE::event e)
{
}
}

View File

@@ -0,0 +1,12 @@
#pragma once
#include "VE.hpp"
namespace sandbox
{
class test_panel : public VE::layer
{
VE_FN_OVERIDE();
};
}

View File

@@ -0,0 +1,63 @@
#include "test_panel_2.hpp"
#include "utils.hpp"
namespace sandbox
{
void test_panel_2::on_attach()
{
hack::log()("on_attach");
// set layer params
// m_passport.m_name = "test_panel";
m_passport.m_size = mt::vec2{ 400.f, 400.f };
m_passport.m_pos = mt::vec2{ 400.f, 400.f };
}
void test_panel_2::on_detach()
{
hack::log()("on_attach");
}
void test_panel_2::render()
{
begin();
if (ImGui::Button("RUN", ImVec2(28, 30)))
{
VE::event e { test_event::TEST_EVEN , std::string("test event message") };
execute(e);
}
VE_PUSH_FONT(ICON, 18);
if (ImGui::Button(VE::style::icon::ICON_STOP, ImVec2(28, 30)))
{
VE::event e { test_event::TEST_EVEN , std::string("test icon button") };
execute(e);
}
ImGui::Text(VE::style::icon::ICON_PAINT_BRUSH, " Paint" );
ImGui::Text("\xef\x87\xbc");
VE_POP_FONT();
end();
}
void test_panel_2::on_event(VE::event e)
{
// для событий от перефирии
// if (e.m_type.type() == typeid(VE::event_type))
// {
// auto t = std::any_cast<VE::event_type>(e.m_type);
// if (t != VE::event_type::MOUSE_CURSOR_POSITION)
// hack::log()((int)t);
// }
if (e.m_type.type() == typeid(test_event))
{
auto t = std::any_cast<test_event>(e.m_type);
if (t == test_event::TEST_EVEN)
hack::log()(std::any_cast<std::string>(e.m_data));
}
}
}

View File

@@ -0,0 +1,12 @@
#pragma once
#include "VE.hpp"
namespace sandbox
{
class test_panel_2 : public VE::layer
{
VE_FN_OVERIDE();
};
}

11
bin/layers/utils.hpp Normal file
View File

@@ -0,0 +1,11 @@
#pragma once
#include <typeinfo>
namespace sandbox
{
enum class test_event
{
TEST_EVEN
};
}

42
bin/main.cpp Executable file
View File

@@ -0,0 +1,42 @@
#include "layers/test_panel/test_panel.hpp"
#include "layers/test_panel_2/test_panel_2.hpp"
#include "layers/opengl_panel/opengl_panel.hpp"
namespace sandbox
{
class test_app : public VE::application
{
public:
test_app(std::string app_name) : VE::application{ app_name } {};
~test_app() = default;
public:
template<typename... Args>
void push_layer(Args... args)
{
this->VE::application::push_layer(args...);
}
};
}
namespace VE
{
inline application& create()
{
static sandbox::test_app e{ "sandbox" };
e.push_layer(
new sandbox::test_panel{},
new sandbox::test_panel_2{},
new sandbox::opengl_panel{}
);
return e;
}
}
auto main(int argc, char* args[]) -> int
{
decltype(auto) app = VE::create();
app.run();
}

6
bin/meson.build Executable file
View File

@@ -0,0 +1,6 @@
executable(
meson.project_name(),
'main.cpp',
dependencies : deps,
cpp_args: args
)