YoggieEngine/SandboxApplication/Sandbox.cpp
Nigel Barink 9c92cc05b7 Added Gorrilla-Audio and Tinygltf Library
Started laying out a assetManager / ModelImporter
2022-05-04 11:11:57 +02:00

139 lines
3.6 KiB
C++

#include <MyGraphicsEngine/Shader.h>
#include <MyGraphicsEngine/Window.h>
#include <MyGraphicsEngine/Camera.h>
#include <MyGraphicsEngine/Mesh.h>
#include <string>
/*
* extern "C"
{
#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
}
*/
//#include <include/AssetManager/ModelImporter.h>
#include <gorilla/gau.h>
#include <gorilla/ga.h>
int main(int argc, char* argv[]) {
spdlog::info("Working directory: {}", argv[0]);
//ModelImporter::Test();
Mesh mesh;
mesh.vertices = {
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
};
mesh.elements = {
0,1,3,
1,2,3
};
Camera cam(glm::vec3(2.0f, 0.0f, 0.0f), glm::vec3(0.0f,0.0f,0.0f), 90.0f);
BarinkWindow GameWindow(800, 600);
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')");
luaL_dofile(L,"./script.lua");
*/
spdlog::info("Vertices: {}, {} bytes", mesh.vertices.size(), sizeof(glm::vec3));
spdlog::info("Elements: {}, {} bytes", mesh.elements.size(), sizeof(GLushort));
unsigned int VBO, VAO, EBO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, mesh.vertices.size() * sizeof(glm::vec3), &mesh.vertices[0], GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, mesh.elements.size() * sizeof(GLushort), &mesh.elements[0], GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
glm::vec3 rotation = glm::vec3(0.0f , 90.0f, 0.0f);
glm::mat4 tran = glm::translate(glm::mat4(),glm::vec3(0.0f, 0.0f, 0.0f));
glm::mat4 scale = glm::scale(glm::mat4(), glm::vec3(1.0f, 1.0f, 1.0f));
glm::mat4 rot =
glm::rotate(glm::mat4(), glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f)) *
glm::rotate(glm::mat4(), glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f)) *
glm::rotate(glm::mat4(), glm::radians(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);
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()) {
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());
glBindVertexArray(VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, NULL);
glBindVertexArray(0);
GameWindow.Poll();
}
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &EBO);
}