2022-04-22 20:37:38 +00:00
|
|
|
#include <MyGraphicsEngine/Shader.h>
|
|
|
|
#include <MyGraphicsEngine/Window.h>
|
2022-05-04 09:10:26 +00:00
|
|
|
#include <MyGraphicsEngine/Camera.h>
|
2022-04-30 20:51:50 +00:00
|
|
|
#include <MyGraphicsEngine/Mesh.h>
|
2022-05-04 13:27:42 +00:00
|
|
|
#include <MyGraphicsEngine/Transform.h>
|
|
|
|
#include <MyGraphicsEngine/Buffer.h>
|
|
|
|
|
2022-04-22 20:37:38 +00:00
|
|
|
#include <string>
|
2022-04-20 19:40:35 +00:00
|
|
|
|
2022-05-04 12:39:27 +00:00
|
|
|
#include "imgui.h"
|
|
|
|
#include "backends/imgui_impl_glfw.h"
|
|
|
|
#include "backends/imgui_impl_opengl3.h"
|
|
|
|
|
2022-04-30 20:51:50 +00:00
|
|
|
/*
|
|
|
|
* extern "C"
|
2022-04-28 19:02:54 +00:00
|
|
|
{
|
|
|
|
#include "lauxlib.h"
|
|
|
|
#include "lua.h"
|
|
|
|
#include "lualib.h"
|
|
|
|
}
|
2022-05-04 12:39:27 +00:00
|
|
|
|
|
|
|
#include <include/AssetManager/ModelImporter.h>
|
2022-05-04 09:10:26 +00:00
|
|
|
|
|
|
|
#include <gorilla/gau.h>
|
|
|
|
#include <gorilla/ga.h>
|
2022-05-04 12:39:27 +00:00
|
|
|
*/
|
2022-05-04 09:10:26 +00:00
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
|
|
|
|
spdlog::info("Working directory: {}", argv[0]);
|
|
|
|
|
|
|
|
//ModelImporter::Test();
|
|
|
|
|
2022-04-30 20:51:50 +00:00
|
|
|
|
2022-05-04 13:27:42 +00:00
|
|
|
Transform t;
|
|
|
|
t.Scale.x = 1.0f;
|
|
|
|
t.Scale.y = 1.0f;
|
|
|
|
t.Rotation.y = 90.0f;
|
2022-04-28 19:02:54 +00:00
|
|
|
|
2022-04-30 20:51:50 +00:00
|
|
|
Mesh mesh;
|
2022-04-28 19:02:54 +00:00
|
|
|
|
2022-04-30 20:51:50 +00:00
|
|
|
mesh.vertices = {
|
2022-05-04 09:10:26 +00:00
|
|
|
glm::vec3( 0.5f, 0.5f, 0.0f), // top, right
|
|
|
|
glm::vec3( 0.5f, -0.5f, 0.0f), // bottom right
|
|
|
|
glm::vec3(-0.5f, -0.5f, 0.0f), // bottom left
|
|
|
|
glm::vec3(-0.5f, 0.5f, 0.0f) // top left
|
2022-04-30 20:51:50 +00:00
|
|
|
};
|
2022-04-28 19:02:54 +00:00
|
|
|
|
2022-04-30 20:51:50 +00:00
|
|
|
|
|
|
|
mesh.elements = {
|
|
|
|
0,1,3,
|
|
|
|
1,2,3
|
|
|
|
};
|
2022-05-04 13:27:42 +00:00
|
|
|
|
|
|
|
|
2022-05-04 09:10:26 +00:00
|
|
|
Camera cam(glm::vec3(2.0f, 0.0f, 0.0f), glm::vec3(0.0f,0.0f,0.0f), 90.0f);
|
2022-04-20 19:40:35 +00:00
|
|
|
|
2022-05-04 09:10:26 +00:00
|
|
|
|
2022-04-20 19:40:35 +00:00
|
|
|
BarinkWindow GameWindow(800, 600);
|
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-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-04-30 20:51:50 +00:00
|
|
|
/*
|
|
|
|
* lua_State* L = luaL_newstate();
|
2022-04-28 19:02:54 +00:00
|
|
|
luaL_openlibs(L);
|
|
|
|
luaL_dostring(L, "print('BarinkEngine')");
|
2022-04-30 18:20:07 +00:00
|
|
|
luaL_dofile(L,"./script.lua");
|
2022-04-30 20:51:50 +00:00
|
|
|
*/
|
|
|
|
|
2022-05-04 09:10:26 +00:00
|
|
|
spdlog::info("Vertices: {}, {} bytes", mesh.vertices.size(), sizeof(glm::vec3));
|
|
|
|
spdlog::info("Elements: {}, {} bytes", mesh.elements.size(), sizeof(GLushort));
|
2022-04-30 18:20:07 +00:00
|
|
|
|
|
|
|
|
2022-05-04 13:27:42 +00:00
|
|
|
Buffer VertexBuffer;
|
|
|
|
Buffer ElementBuffer;
|
|
|
|
|
|
|
|
unsigned int VAO;
|
2022-04-30 18:20:07 +00:00
|
|
|
|
2022-05-04 13:27:42 +00:00
|
|
|
glGenVertexArrays(1, &VAO);
|
2022-04-30 18:20:07 +00:00
|
|
|
glBindVertexArray(VAO);
|
|
|
|
|
2022-05-04 13:27:42 +00:00
|
|
|
VertexBuffer.createBuffer();
|
|
|
|
VertexBuffer.Bind(false);
|
|
|
|
VertexBuffer.setBufferData(&mesh.vertices[0], mesh.vertices.size() * sizeof(glm::vec3),false);
|
2022-04-30 18:20:07 +00:00
|
|
|
|
2022-05-04 13:27:42 +00:00
|
|
|
ElementBuffer.createBuffer();
|
|
|
|
ElementBuffer.Bind(true);
|
|
|
|
ElementBuffer.setBufferData(&mesh.elements[0], mesh.elements.size() * sizeof(GLushort), true);
|
2022-04-30 18:20:07 +00:00
|
|
|
|
2022-05-04 13:27:42 +00:00
|
|
|
|
2022-05-04 09:10:26 +00:00
|
|
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
2022-04-30 18:20:07 +00:00
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
|
2022-05-04 13:27:42 +00:00
|
|
|
VertexBuffer.Unbind(false);
|
2022-04-30 18:20:07 +00:00
|
|
|
glBindVertexArray(0);
|
|
|
|
|
2022-05-04 12:39:27 +00:00
|
|
|
/*
|
|
|
|
* gau_Manager* mgr;
|
2022-05-04 09:10:26 +00:00
|
|
|
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);
|
2022-05-04 12:39:27 +00:00
|
|
|
*/
|
|
|
|
|
2022-05-04 09:10:26 +00:00
|
|
|
|
2022-04-22 20:37:38 +00:00
|
|
|
|
|
|
|
|
2022-04-28 19:02:54 +00:00
|
|
|
|
|
|
|
while (!GameWindow.WindowShouldClose()) {
|
2022-05-04 13:27:42 +00:00
|
|
|
glm::mat4 tran = glm::translate(glm::mat4(), t.Position);
|
|
|
|
glm::mat4 scale = glm::scale(glm::mat4(), t.Scale);
|
|
|
|
glm::mat4 rot =
|
|
|
|
glm::rotate(glm::mat4(), glm::radians(t.Rotation.x), glm::vec3(1.0f, 0.0f, 0.0f)) *
|
|
|
|
glm::rotate(glm::mat4(), glm::radians(t.Rotation.y), glm::vec3(0.0f, 1.0f, 0.0f)) *
|
|
|
|
glm::rotate(glm::mat4(), glm::radians(t.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);
|
|
|
|
|
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-04-30 18:20:07 +00:00
|
|
|
glBindVertexArray(VAO);
|
2022-05-04 13:27:42 +00:00
|
|
|
ElementBuffer.Bind(true);
|
2022-05-04 09:10:26 +00:00
|
|
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, NULL);
|
2022-04-30 18:20:07 +00:00
|
|
|
glBindVertexArray(0);
|
2022-04-28 19:02:54 +00:00
|
|
|
|
2022-05-04 12:39:27 +00:00
|
|
|
|
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
|
|
ImGui_ImplGlfw_NewFrame();
|
|
|
|
ImGui::NewFrame();
|
|
|
|
|
2022-05-04 13:27:42 +00:00
|
|
|
ImGui::Begin("Transform Test Tool");
|
|
|
|
|
|
|
|
ImGui::SliderFloat("Scale Y:", (float*)&t.Scale.y, 1, 4);
|
|
|
|
ImGui::SliderFloat("Scale X:", (float*)&t.Scale.x, 1, 4);
|
|
|
|
|
|
|
|
ImGui::SliderFloat("Position X:", (float*)&t.Position.z, -5, 5);
|
2022-05-04 12:39:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
glDeleteVertexArrays(1, &VAO);
|
2022-05-04 13:27:42 +00:00
|
|
|
ElementBuffer.Delete();
|
2022-04-30 18:20:07 +00:00
|
|
|
|
|
|
|
|
2022-04-20 19:40:35 +00:00
|
|
|
}
|
|
|
|
|