YoggieEngine/SandboxApplication/Sandbox.cpp

96 lines
2.1 KiB
C++
Raw Normal View History

#include <glad/glad.h>
#include <MyGraphicsEngine/Shader.h>
#include <MyGraphicsEngine/Window.h>
2022-04-30 20:51:50 +00:00
#include <MyGraphicsEngine/Mesh.h>
#include <string>
2022-04-30 20:51:50 +00:00
/*
* extern "C"
{
#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
}
2022-04-30 20:51:50 +00:00
*/
int main (int argc, char *argv[] ){
2022-04-30 20:51:50 +00:00
Mesh mesh;
2022-04-30 20:51:50 +00:00
mesh.vertices = {
0.5f, 0.5f, 0.0f, // top, right
0.5f, -0.5f, 0.0f, // bottom right
-0.5f, -0.5f, 0.0f, // bottom left
-0.5f, 0.5f, 0.0f // top left
};
2022-04-30 20:51:50 +00:00
mesh.elements = {
0,1,3,
1,2,3
};
BarinkWindow GameWindow(800, 600);
2022-04-30 18:20:07 +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);
spdlog::info("Working directory: {}", argv[0]);
2022-04-30 20:51:50 +00:00
/*
* lua_State* L = luaL_newstate();
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-04-30 18:20:07 +00:00
unsigned int VBO, VAO, EBO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
2022-04-30 20:51:50 +00:00
spdlog::info("Vertices: {}", mesh.vertices.size());
2022-04-30 18:20:07 +00:00
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
2022-04-30 20:51:50 +00:00
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * mesh.vertices.size() , &mesh.vertices[0], GL_STATIC_DRAW);
2022-04-30 18:20:07 +00:00
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
2022-04-30 20:51:50 +00:00
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(int) * mesh.elements.size(), &mesh.elements[0], GL_STATIC_DRAW);
2022-04-30 18:20:07 +00:00
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
while (!GameWindow.WindowShouldClose()) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT) ;
2022-04-30 18:20:07 +00:00
shader.Use();
glBindVertexArray(VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
GameWindow.Poll();
}
2022-04-30 18:20:07 +00:00
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &EBO);
}