Nigel Barink
9165e30d0e
* Using import library assimp to incorrectly load a cube.obj * Using a temporary Renderable class as a placeholder for all data needed to render the mesh. * Vertex Array abstraction added
143 lines
3.7 KiB
C++
143 lines
3.7 KiB
C++
#include <string>
|
|
|
|
#include <MyGraphicsEngine/Shader.h>
|
|
#include <MyGraphicsEngine/Window.h>
|
|
#include <MyGraphicsEngine/Camera.h>
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
#include "imgui.h"
|
|
#include "backends/imgui_impl_glfw.h"
|
|
#include "backends/imgui_impl_opengl3.h"
|
|
#include "Renderable.h"
|
|
#include <filesystem>
|
|
|
|
|
|
|
|
extern "C"
|
|
{
|
|
#include "lauxlib.h"
|
|
#include "lua.h"
|
|
#include "lualib.h"
|
|
}
|
|
|
|
/*
|
|
#include <gorilla/gau.h>
|
|
#include <gorilla/ga.h>
|
|
*/
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
char cwd[256];
|
|
getcwd(cwd, 256);
|
|
spdlog::info("Working directory: {}", cwd);
|
|
|
|
|
|
BarinkWindow GameWindow(800, 600);
|
|
|
|
IMGUI_CHECKVERSION();
|
|
ImGui::CreateContext();
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
(void)io;
|
|
|
|
ImGui::StyleColorsDark();
|
|
ImGui_ImplGlfw_InitForOpenGL(GameWindow.windowptr(), true);
|
|
ImGui_ImplOpenGL3_Init("#version 440");
|
|
|
|
Camera cam(glm::vec3(0.0f, 1.5f, -10.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
|
|
Renderable Cube = Renderable::Load();
|
|
|
|
|
|
spdlog::info("==== Load Shader(s) ====");
|
|
std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs";
|
|
std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs";
|
|
Shader shader (vertexShaderSource, fragmentShaderSource);
|
|
|
|
lua_State* L = luaL_newstate();
|
|
luaL_openlibs(L);
|
|
luaL_dostring(L, "print('BarinkEngine')");
|
|
spdlog::info("==== Run script ====");
|
|
luaL_dofile(L,"build/SandboxApplication/Debug/script.lua");
|
|
|
|
|
|
/*
|
|
* gau_Manager* mgr;
|
|
ga_Mixer* mixer;
|
|
ga_Sound sound;
|
|
ga_Handle handle;
|
|
gau_SampleSourceLoop* loopSrc = 0;
|
|
gau_SampleSourceLoop** pLoopSrc = &loopSrc;
|
|
gc_int32 loop = 0;
|
|
gc_int32 quit = 0;
|
|
|
|
|
|
gc_initialize(0);
|
|
mgr = gau_manager_create();
|
|
mixer = gau_manager_mixer(mgr);
|
|
*/
|
|
|
|
|
|
|
|
while (!GameWindow.WindowShouldClose()) {
|
|
glm::mat4 tran = glm::translate(glm::mat4(), Cube.transform.Position);
|
|
glm::mat4 scale = glm::scale(glm::mat4(), Cube.transform.Scale);
|
|
glm::mat4 rot =
|
|
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));
|
|
|
|
|
|
glm::mat4 model = tran * rot * scale;
|
|
|
|
glm::mat4 projection = glm::perspective(cam.Zoom, (800.0f / 600.0f), 0.001f, 100.0f);
|
|
|
|
|
|
GameWindow.Poll();
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
|
|
|
shader.Use();
|
|
shader.setUniformMat4("P", projection);
|
|
shader.setUniformMat4("M", model);
|
|
shader.setUniformMat4("V", cam.GetViewMatrix());
|
|
|
|
Cube.Draw();
|
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
ImGui_ImplGlfw_NewFrame();
|
|
ImGui::NewFrame();
|
|
|
|
ImGui::Begin("Test");
|
|
|
|
ImGui::SliderFloat("Scale Y:", (float*)&Cube.transform.Scale.y, 1, 4);
|
|
ImGui::SliderFloat("Scale X:", (float*)&Cube.transform.Scale.x, 1, 4);
|
|
|
|
ImGui::SliderFloat("Camera Zoom:", &cam.Zoom, 40, 190);
|
|
ImGui::SliderFloat("Position X:", (float*)&Cube.transform.Position.x, -9, -60);
|
|
|
|
ImGui::SliderFloat("Rotate Y:", (float*)&Cube.transform.Rotation.y, 0, 180);
|
|
ImGui::SliderFloat("Rotate Z:", (float*)&Cube.transform.Rotation.z, 0, 180);
|
|
|
|
ImGui::End();
|
|
|
|
|
|
|
|
ImGui::Render();
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
|
|
|
|
GameWindow.SwapBuffers();
|
|
}
|
|
|
|
// Cleanup
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
ImGui_ImplGlfw_Shutdown();
|
|
ImGui::DestroyContext();
|
|
|
|
Cube.VAO.Delete();
|
|
Cube.elementBuffer.Delete();
|
|
|
|
|
|
}
|
|
|