YoggieEngine/SandboxApplication/Sandbox.cpp

84 lines
1.9 KiB
C++
Raw Normal View History

#include <glad/glad.h>
#include <MyGraphicsEngine/Shader.h>
#include <MyGraphicsEngine/Window.h>
#include <string>
extern "C"
{
#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
}
2022-04-30 18:20:07 +00:00
float 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 18:20:07 +00:00
unsigned int indices[] = {
0,1,3,
1,2,3
};
int main (int argc, char *argv[] ){
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]);
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");
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, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
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);
}