2022-05-28 11:32:17 +00:00
|
|
|
#include "BarinkEngine.h"
|
|
|
|
|
|
|
|
|
2022-05-04 21:25:18 +00:00
|
|
|
|
2022-05-27 20:47:36 +00:00
|
|
|
void Start(int argc, char* argv[]) {
|
2022-05-04 12:39:27 +00:00
|
|
|
|
2022-05-27 20:47:36 +00:00
|
|
|
std::cout << "Hello start!" << std::endl;
|
|
|
|
std::cout << "h" << std::endl;
|
2022-05-28 11:32:17 +00:00
|
|
|
|
|
|
|
char cwd[256];
|
|
|
|
memset(cwd, '\0', 256);
|
|
|
|
// getcwd(cwd, 256);
|
|
|
|
//spdlog::info("Working directory: {}", cwd);
|
|
|
|
|
|
|
|
WARN("Hello warning");
|
|
|
|
|
|
|
|
// BarinkWindow GameWindow(800, 600);
|
2022-05-04 21:25:18 +00:00
|
|
|
|
2022-05-27 20:47:36 +00:00
|
|
|
}
|
2022-05-04 21:25:18 +00:00
|
|
|
|
2022-05-27 20:47:36 +00:00
|
|
|
void UpdateApplication()
|
|
|
|
{
|
2022-04-28 19:02:54 +00:00
|
|
|
}
|
2022-05-04 12:39:27 +00:00
|
|
|
|
2022-05-04 21:25:18 +00:00
|
|
|
/*
|
2022-05-04 09:10:26 +00:00
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
|
2022-05-04 21:25:18 +00:00
|
|
|
char cwd[256];
|
2022-05-13 19:59:19 +00:00
|
|
|
memset(cwd, '\0', 256);
|
2022-05-04 21:25:18 +00:00
|
|
|
getcwd(cwd, 256);
|
|
|
|
spdlog::info("Working directory: {}", cwd);
|
|
|
|
|
2022-04-30 18:20:07 +00:00
|
|
|
|
2022-05-04 12:39:27 +00:00
|
|
|
IMGUI_CHECKVERSION();
|
|
|
|
ImGui::CreateContext();
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
(void)io;
|
|
|
|
|
|
|
|
ImGui::StyleColorsDark();
|
|
|
|
ImGui_ImplGlfw_InitForOpenGL(GameWindow.windowptr(), true);
|
|
|
|
ImGui_ImplOpenGL3_Init("#version 440");
|
2022-05-04 21:25:18 +00:00
|
|
|
|
|
|
|
Camera cam(glm::vec3(0.0f, 1.5f, -10.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
|
|
|
|
Renderable Cube = Renderable::Load();
|
2022-05-04 12:39:27 +00:00
|
|
|
|
2022-05-04 21:25:18 +00:00
|
|
|
|
|
|
|
spdlog::info("==== Load Shader(s) ====");
|
2022-04-22 20:37:38 +00:00
|
|
|
std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs";
|
|
|
|
std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs";
|
2022-04-30 18:20:07 +00:00
|
|
|
Shader shader (vertexShaderSource, fragmentShaderSource);
|
|
|
|
|
2022-05-04 21:25:18 +00:00
|
|
|
lua_State* L = luaL_newstate();
|
2022-04-28 19:02:54 +00:00
|
|
|
luaL_openlibs(L);
|
|
|
|
luaL_dostring(L, "print('BarinkEngine')");
|
2022-05-04 21:25:18 +00:00
|
|
|
spdlog::info("==== Run script ====");
|
|
|
|
luaL_dofile(L,"build/SandboxApplication/Debug/script.lua");
|
|
|
|
|
2022-04-30 18:20:07 +00:00
|
|
|
|
2022-05-04 12:39:27 +00:00
|
|
|
|
2022-05-13 19:59:19 +00:00
|
|
|
char* lua_code = new char[255];
|
|
|
|
memset(lua_code, '\0', 255);
|
|
|
|
|
|
|
|
bool runCode = false;
|
|
|
|
|
2022-04-28 19:02:54 +00:00
|
|
|
|
|
|
|
while (!GameWindow.WindowShouldClose()) {
|
2022-05-13 19:59:19 +00:00
|
|
|
if (runCode == true) {
|
|
|
|
luaL_dostring(L,lua_code);
|
|
|
|
runCode = false;
|
|
|
|
}
|
|
|
|
|
2022-05-04 21:25:18 +00:00
|
|
|
glm::mat4 tran = glm::translate(glm::mat4(), Cube.transform.Position);
|
|
|
|
glm::mat4 scale = glm::scale(glm::mat4(), Cube.transform.Scale);
|
2022-05-04 13:27:42 +00:00
|
|
|
glm::mat4 rot =
|
2022-05-04 21:25:18 +00:00
|
|
|
glm::rotate(glm::mat4(), glm::radians(Cube.transform.Rotation.x), glm::vec3(1.0f, 0.0f, 0.0f)) *
|
|
|
|
glm::rotate(glm::mat4(), glm::radians(Cube.transform.Rotation.y), glm::vec3(0.0f, 1.0f, 0.0f)) *
|
|
|
|
glm::rotate(glm::mat4(), glm::radians(Cube.transform.Rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
2022-05-04 13:27:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
glm::mat4 model = tran * rot * scale;
|
|
|
|
|
2022-05-13 19:59:19 +00:00
|
|
|
glm::mat4 projection = glm::perspective(glm::radians(cam.Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
|
2022-05-04 13:27:42 +00:00
|
|
|
|
2022-05-04 12:39:27 +00:00
|
|
|
|
|
|
|
GameWindow.Poll();
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
|
|
|
|
2022-04-30 18:20:07 +00:00
|
|
|
shader.Use();
|
2022-05-04 09:10:26 +00:00
|
|
|
shader.setUniformMat4("P", projection);
|
|
|
|
shader.setUniformMat4("M", model);
|
|
|
|
shader.setUniformMat4("V", cam.GetViewMatrix());
|
2022-05-04 21:25:18 +00:00
|
|
|
|
|
|
|
Cube.Draw();
|
2022-05-04 12:39:27 +00:00
|
|
|
|
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
|
|
ImGui_ImplGlfw_NewFrame();
|
|
|
|
ImGui::NewFrame();
|
|
|
|
|
2022-05-13 19:59:19 +00:00
|
|
|
ImGui::Begin("Transform");
|
|
|
|
ImGui::Text("Cube");
|
|
|
|
ImGui::InputFloat3("Position:", (float*)&Cube.transform.Position);
|
|
|
|
ImGui::InputFloat3("Rotation:", (float*)&Cube.transform.Rotation);
|
|
|
|
ImGui::InputFloat3("Scale:", (float*)&Cube.transform.Scale);
|
2022-05-04 21:25:18 +00:00
|
|
|
|
2022-05-13 19:59:19 +00:00
|
|
|
ImGui::End();
|
2022-05-04 13:27:42 +00:00
|
|
|
|
2022-05-13 19:59:19 +00:00
|
|
|
ImGui::Begin("Camera");
|
|
|
|
|
|
|
|
ImGui::SliderFloat("Zoom:", &cam.Zoom, 10, 190);
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::Begin("Scripting!!");
|
|
|
|
|
|
|
|
ImGui::InputTextMultiline("Lua Script", lua_code, 255);
|
|
|
|
runCode = ImGui::Button("Run");
|
2022-05-04 12:39:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
|
|
|
|
|
2022-05-13 19:59:19 +00:00
|
|
|
ImGui::ShowDemoWindow();
|
|
|
|
|
2022-05-04 12:39:27 +00:00
|
|
|
|
|
|
|
ImGui::Render();
|
|
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
2022-05-04 09:10:26 +00:00
|
|
|
|
|
|
|
|
2022-05-04 12:39:27 +00:00
|
|
|
GameWindow.SwapBuffers();
|
2022-04-28 19:02:54 +00:00
|
|
|
}
|
2022-04-30 18:20:07 +00:00
|
|
|
|
2022-05-04 12:39:27 +00:00
|
|
|
// Cleanup
|
|
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
|
|
ImGui_ImplGlfw_Shutdown();
|
|
|
|
ImGui::DestroyContext();
|
2022-04-30 18:20:07 +00:00
|
|
|
|
2022-05-04 21:25:18 +00:00
|
|
|
Cube.VAO.Delete();
|
|
|
|
Cube.elementBuffer.Delete();
|
2022-04-30 18:20:07 +00:00
|
|
|
|
|
|
|
|
2022-04-20 19:40:35 +00:00
|
|
|
}
|
|
|
|
|
2022-05-27 20:47:36 +00:00
|
|
|
*/
|