Initial setup.

Correctly linking glfw and spdlog...
Linking could be improved by not needing the sandbox
application to also be linked with glfw
This commit is contained in:
Nigel Barink 2022-04-20 21:40:35 +02:00
parent 2a93a78c4f
commit dab01f1541
13 changed files with 132 additions and 254 deletions

6
.gitignore vendored
View File

@ -1,5 +1,7 @@
artifacts/
build/
intermediates/
tools/
*.make
premake5
Makefile
.vscode/
libs/

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "ogre"]
path = libs/ogre
url = https://github.com/OGRECave/ogre.git

View File

@ -1,135 +0,0 @@
#include <stdio.h>
#include "glfw3.h"
//#include "spdlog.h"
GLFWwindow * window;
int main (void) {
// spdlog::info("Welcome to spdlog!");
if ( !glfwInit()){
puts("Failed to initialize GLFW!");
return -1;
}
window = glfwCreateWindow( 640 , 480, "BarinkEngine", NULL, NULL);
if( !window){
puts("Failed to create the window");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
if(glfwVulkanSupported())
{
puts("Vulkan is supported!");
}
int width,height;
glfwGetFramebufferSize(window, &width, &height);
glViewport(0,0, width, height);
// SOURCE: https://learnopengl.com/Getting-started/Hello-Triangle
float vertices[] = {
-0.5, -0.5f, 0.0f,
0.5, -0.5f, 0.0f,
0.5, 0.5f, 0.0f,
};
unsigned int VBO;
glGenBuffers(1,&VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
// Load the vertex shader program
const char *vertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
"}\0";
unsigned int vertexShader;
vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
glCompileShader(vertexShader);
const char *fragmentShaderSource = "#version 330 core\n"
"out vec4 FragColor;\n"
"void main ()\n {\n"
"FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f); \n"
"}\n";
unsigned int fragmentShader ;
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
glCompileShader(fragmentShader);
unsigned int shaderProgram;
shaderProgram = glCreateProgram();
glAttachShader (shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glLinkProgram(shaderProgram);
glUseProgram(shaderProgram);
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,3*sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
// Copy our vertices array in a buffer for OpenGL to use
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
// then set the vertex attributes pointers
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,3*sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
unsigned int VAO;
glGenVertexArrays(1,&VAO);
glBindVertexArray(VAO);
// use our hader program when we want to render an object
glUseProgram(shaderProgram);
glBindVertexArray(VAO);
while(!glfwWindowShouldClose(window)){
/* Start rendering here */
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 3);
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
glfwTerminate();
return 0;
}

View File

@ -0,0 +1,9 @@
#pragma once
#include <spdlog/spdlog.h>
#include "MyGraphicsEngine/window.h"
inline void test (){
spdlog::info("Linked correctly!");
}

View File

@ -0,0 +1,22 @@
#pragma once
#include <GLFW/glfw3.h>
class BarinkWindow{
private:
GLFWwindow* window;
bool FullScreen;
bool VulkanSupported;
int Width, Height;
bool InitGLFW();
public:
BarinkWindow(const int width, const int height);
~BarinkWindow();
void EnterLoop();
};

View File

@ -0,0 +1,47 @@
#include "MyGraphicsEngine/window.h"
bool BarinkWindow::InitGLFW(){
if(!glfwInit()){
return false;
}
return true;
}
BarinkWindow::BarinkWindow(const int width, const int height) :
Width(width), Height(height), FullScreen(false){
InitGLFW();
window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL);
if( !window){
glfwTerminate();
return;
}
glfwMakeContextCurrent(window);
VulkanSupported = glfwVulkanSupported();
glfwGetFramebufferSize(window, &Width, &Height);
glViewport(0,0, Width, Height);
}
BarinkWindow::~BarinkWindow(){
glfwTerminate();
}
void BarinkWindow::EnterLoop(){
while(!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
}

View File

@ -0,0 +1,11 @@
#include <MyGraphicsEngine/Graphics.h>
int main (int argc, char *argv[] ){
test();
BarinkWindow GameWindow(800, 600);
GameWindow.EnterLoop();
}

View File

@ -1,69 +0,0 @@
#include <stdio.h>
#include <lua.h>
extern "c" {
static int l_cppfunction(lua_State *L) {
double arg = luaL_checknumber(L,1);
lua_pushnumber(L, arg * 0.5);
return 1;
}
}
int main (int argc, char *argv[] ){
printf("Test lua embedding");
printf("init lua");
lua_State *L;
L = luaL_newState();
printf("Load the (optional) standard libraries, to have to print function");
luaL_openLibs(L);
printf("Load chenk. without executing it.");
if( luaL_loadfile(L, "hello.lua")){
printf("Something went wrong loading the check (syntax error?)");
printf(lua_tostring(L, -1));
lua_pop(L,1);
}
printf("Make a insert a global var into lua from C++");
lua_pushnumber(L, 1.1);
lua_setglobal(L, "cppvar");
printf("Execute the Lua chunk");
if(lua_pcall(L, 0, LUA_MULTRET, 0)){
printf("Something went wrong during execution");
printf(lua_tostring(L, -1));
lua_pop(L,1);
}
printf("read a global var from lua into C++");
lua_getglobal(L, "luavar");
double luavar = lua_tonumber(L, -1);
lua_pop(L,1);
printf("c++ can read the value set from lua luavar = %s", luavar );
printf("execute a lua function from cpp");
lua_getglobal(L, "myluafunction");
lua_pushnumber(L, 5);
lua_pcall(L,1,1,0);
printf("the return value of the function was %s", lua_tostring(L, -1));
lua_pop(L,1);
printf("execute a cpp function from lua");
printf("first register the function in lua");
lua_pushcfunction(L , l_cppfunction);
lua_setglobal(L, "cppfunction");
printf("Call a lua function that uses the cpp function");
lua_setglobal(L, "myFunction");
lua_pushnumber(L, 5);
lua_pcall(L,1,1,0);
printf("the return value of the function was %s", lua_tonumber(L,-1));
lua_pop(L,1);
printf("Release the lua environment");
lua_close(L);
}

View File

@ -1,14 +0,0 @@
-- Pack this into object file with ld: ld -r -b binary -o hello.o hello.lua
print ("Hello from lua")
print ("Lua code is capable of reading value set from C++", cppvar)
luavar = cppvar * 3
function myluafunction (times)
return string.rep("(-)", times)
end
function myfunction(arg)
return cppfunction(arg)
end

View File

@ -1,4 +0,0 @@
#!/bin/bash
echo "BarinkEngine Terminal"
echo "Loading environment..."
source ./scripts/load.env

View File

@ -1,51 +1,63 @@
workspace "BarinkEngine"
configurations { "Debug", "Test", "Release" }
language "C++"
cppdialect "C++17"
targetdir "./build/%{prj.name}/%{cfg.buildcfg}"
objdir "./intermediates/%{prj.name}/%{cfg.buildcfg}"
project "SandboxApplication"
kind "ConsoleApp"
language "C++"
cppdialect "C++17"
targetdir "./artifacts/build/%{cfg.buildcfg}"
objdir "./artifacts/obj/%{cfg.buildcfg}"
buildmessage "Building BarinkEngineSandbox ..."
includedirs {
"./libs/lua-5.4.3/",
"./MyGraphicsEngine/include"
}
libdirs {
os.findlib("lua")
libdirs{
"./libs/spdlog-1.9.1/build"
}
links{
"spdlog",
"glfw3",
"X11",
"GL",
"GLU",
"pthread",
"dl",
"m",
"MyGraphicsEngine"
}
files {
"SandboxApplication/*.cpp"
}
files {
"SandboxApplication/*.c"
}
links{
"lua"
}
project "MyGraphicsEngine"
kind "ConsoleApp"
language "C++"
cppdialect "c++17"
targetdir "./artifacts/build/%{cfg.buildcfg}"
objdir "./artifacts/obj/%{cfg.buildcfg}"
buildmessage "Building MyGraphicsEngine"
kind "StaticLib"
buildmessage "Building MyGraphicsEngine ..."
includedirs {
"./libs/glfw-3.3.4/include/GLFW/",
"./libs/spdlog-1.9.1/include/spdlog/"
"./libs/glfw-3.3.4/include",
"./libs/spdlog-1.9.1/include",
"./MyGraphicsEngine/include"
}
libdirs{
"./libs/spdlog-1.9.1/build/libspdlog.a",
os.findlib("glfw3"),
"./libs/spdlog-1.9.1/build"
}
links {
-- "libspdlog",
"libspdlog",
"glfw3",
"X11",
"GL",
@ -55,7 +67,7 @@ workspace "BarinkEngine"
"m"
}
files {"MyGraphicsEngine/*.c"}
files {"MyGraphicsEngine/*.cpp"}
filter "configurations:Debug"
defines {"DEBUG"}