Basic rectangle drawing

This commit is contained in:
Nigel Barink 2022-04-30 20:20:07 +02:00
parent ddf7e14682
commit f547ff1b8f
8 changed files with 93 additions and 40 deletions

2
.gitmodules vendored
View File

@ -5,5 +5,5 @@
path = libs/glm path = libs/glm
url = https://github.com/nigelbarink/glm.git url = https://github.com/nigelbarink/glm.git
[submodule "spdlog"] [submodule "spdlog"]
path = libs\\spdlog path = libs/spdlog
url = https://github.com/nigelbarink/spdlog.git url = https://github.com/nigelbarink/spdlog.git

View File

@ -38,6 +38,19 @@ Shader::Shader(const std::string vertexShaderPath, const std::string fragmentSha
return; return;
} }
id = glCreateProgram();
glAttachShader(id, vertId);
glAttachShader(id, fragId);
glLinkProgram(id);
int success;
glGetProgramiv(id, GL_LINK_STATUS, &success);
if(!success) {
glGetProgramInfoLog(id, 512, NULL, infoLog);
printf("ERROR::SHADER_PROGRAM::LINKING_FAILED\n %s", infoLog);
}
delete[] vertexCode; delete[] vertexCode;
@ -90,5 +103,5 @@ char* Shader::readFile (const char* filePath){
void Shader::Use() void Shader::Use()
{ {
// glUseProgam(id); glUseProgram(id);
} }

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <glad/glad.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
@ -9,7 +10,7 @@ class BarinkWindow{
bool VulkanSupported; bool VulkanSupported;
int Width, Height; int Width, Height;
bool InitGLFW(); static bool InitGLFW();
public: public:

View File

@ -8,12 +8,15 @@ bool BarinkWindow::InitGLFW(){
spdlog::error("Failed to initialise GLFW!"); spdlog::error("Failed to initialise GLFW!");
return false; return false;
} }
return true; return true;
} }
BarinkWindow::BarinkWindow(const int width, const int height) : BarinkWindow::BarinkWindow(const int width, const int height) :
Width(width), Height(height), FullScreen(false){ Width(width), Height(height), FullScreen(false){
InitGLFW(); if (InitGLFW()==false) {
exit(-1);
}
window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL); window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL);
@ -25,6 +28,10 @@ Width(width), Height(height), FullScreen(false){
} }
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
printf("Failed to initialize GLAD!\n");
exit(-1);
}
VulkanSupported = glfwVulkanSupported(); VulkanSupported = glfwVulkanSupported();
@ -33,6 +40,9 @@ Width(width), Height(height), FullScreen(false){
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
} }

View File

@ -10,36 +10,74 @@ extern "C"
#include "lualib.h" #include "lualib.h"
} }
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
};
unsigned int indices[] = {
0,1,3,
1,2,3
};
int main (int argc, char *argv[] ){ int main (int argc, char *argv[] ){
BarinkWindow GameWindow(800, 600); BarinkWindow GameWindow(800, 600);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)){
printf("Failed to initialize GLAD!\n");
return -1;
}
std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs"; std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs";
std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs"; std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs";
//Shader shader (vertexShaderSource, fragmentShaderSource); Shader shader (vertexShaderSource, fragmentShaderSource);
spdlog::info("Working directory: {}", argv[0]);
lua_State* L = luaL_newstate(); lua_State* L = luaL_newstate();
luaL_openlibs(L); luaL_openlibs(L);
luaL_dostring(L, "print('BarinkEngine')"); luaL_dostring(L, "print('BarinkEngine')");
luaL_dofile(L,"script.lua"); 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);
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
while (!GameWindow.WindowShouldClose()) { while (!GameWindow.WindowShouldClose()) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT) ; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT) ;
shader.Use();
glBindVertexArray(VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
GameWindow.Poll(); GameWindow.Poll();
} }
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &EBO);
} }

View File

@ -0,0 +1 @@
print("Hello world!")

@ -1 +1 @@
Subproject commit 72a01d3432204128442b2198d3f595bb84f011bb Subproject commit cc98465e3508535ba8c7f6208df934c156a018dc

View File

@ -14,26 +14,21 @@ workspace "BarinkEngine"
includedirs { includedirs {
"./libs/glad/include", "./libs/glad/include",
"./MyGraphicsEngine/include", "./MyGraphicsEngine/include",
"./libs/lua-5.4.4/lua" "./libs/spdlog/include",
"./libs/lua/include",
"./libs/glfw/include",
} }
libdirs{ libdirs{
"./libs/spdlog-1.9.1/build", "./libs/spdlog/_builds/Release",
"./libs/lua-5.4.4/lua" "./libs/glfw/lib-vc2022",
"./libs/lua"
} }
links{ links{
"liblua", "liblua",
"spdlog", "spdlog",
"glfw3", "glfw3",
"X11",
"GL",
"GLU",
"pthread",
"dl",
"m",
"MyGraphicsEngine" "MyGraphicsEngine"
} }
@ -55,27 +50,22 @@ workspace "BarinkEngine"
includedirs { includedirs {
"./libs/glad/include", "./libs/glad/include",
"./libs/glfw-3.3.4/include", "./libs/glfw/include",
"./libs/glew-2.2.0/include", "./libs/glew/include",
"./libs/spdlog-1.9.1/include", "./libs/spdlog/include",
"./libs/glm/glm", "./libs/glm/glm",
"./MyGraphicsEngine/include" "./MyGraphicsEngine/include"
} }
libdirs{ libdirs{
"./libs/spdlog-1.9.1/build" "./libs/spdlog/_builds/Release",
"./libs/glfw/lib-vc2022"
} }
links { links {
"libspdlog", "spdlog",
"glfw3", "glfw3"
"X11",
"GL",
"GLU",
"pthread",
"dl",
"m"
} }
files { files {
@ -85,7 +75,7 @@ workspace "BarinkEngine"
} }
filter "configurations:Debug" filter "configurations:Debug"
defines {"DEBUG"} defines {"NDEBUG"}
symbols "On" symbols "On"
filter "configurations:Release" filter "configurations:Release"