From 2a93a78c4f16a06128a20866d94c42753f6bd242 Mon Sep 17 00:00:00 2001 From: Nigel Date: Wed, 29 Sep 2021 19:14:27 +0100 Subject: [PATCH] Cleanup workspace --- .gitignore | 393 +----------------- .gitmodules | 3 + .vscode/settings.json | 3 + .../Shader/fragment.shader | 0 MyGraphicsEngine/Shader/vertex.shader | 7 + MyGraphicsEngine/glWindow.c | 135 ++++++ SandboxApplication/hello.cpp | 69 +++ SandboxApplication/hello.lua | 14 + docs/TODO.md => TODO.md | 0 lib/.blank | 0 premake5.lua | 72 +++- scripts/load.env | 11 - scripts/run.sh | 8 - src/hello.c | 6 - 14 files changed, 293 insertions(+), 428 deletions(-) create mode 100644 .gitmodules create mode 100644 .vscode/settings.json rename images/.blank => MyGraphicsEngine/Shader/fragment.shader (100%) create mode 100644 MyGraphicsEngine/Shader/vertex.shader create mode 100644 MyGraphicsEngine/glWindow.c create mode 100644 SandboxApplication/hello.cpp create mode 100644 SandboxApplication/hello.lua rename docs/TODO.md => TODO.md (100%) delete mode 100644 lib/.blank delete mode 100644 scripts/load.env delete mode 100755 scripts/run.sh delete mode 100644 src/hello.c diff --git a/.gitignore b/.gitignore index 2161bb1..e64a995 100644 --- a/.gitignore +++ b/.gitignore @@ -1,394 +1,5 @@ -build -obj +artifacts/ *.make premake5 Makefile - -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -## -## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore - -# User-specific files -*.rsuser -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Mono auto generated files -mono_crash.* - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -[Ww][Ii][Nn]32/ -[Aa][Rr][Mm]/ -[Aa][Rr][Mm]64/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ -[Ll]ogs/ - -# Visual Studio 2015/2017 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# Visual Studio 2017 auto generated files -Generated\ Files/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUnit -*.VisualState.xml -TestResult.xml -nunit-*.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# Benchmark Results -BenchmarkDotNet.Artifacts/ - -# .NET Core -project.lock.json -project.fragment.lock.json -artifacts/ - -# ASP.NET Scaffolding -ScaffoldingReadMe.txt - -# StyleCop -StyleCopReport.xml - -# Files built by Visual Studio -*_i.c -*_p.c -*_h.h -*.ilk -*.meta -*.obj -*.iobj -*.pch -*.pdb -*.ipdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*_wpftmp.csproj -*.log -*.tlog -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# Visual Studio Trace Files -*.e2e - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# AxoCover is a Code Coverage Tool -.axoCover/* -!.axoCover/settings.json - -# Coverlet is a free, cross platform Code Coverage Tool -coverage*.json -coverage*.xml -coverage*.info - -# Visual Studio code coverage results -*.coverage -*.coveragexml - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# Note: Comment the next line if you want to checkin your web deploy settings, -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# NuGet Symbol Packages -*.snupkg -# The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* -# except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/[Pp]ackages/repositories.config -# NuGet v3's project.json files produces more ignorable files -*.nuget.props -*.nuget.targets - -# Nuget personal access tokens and Credentials -nuget.config - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt -*.appx -*.appxbundle -*.appxupload - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!?*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -orleans.codegen.cs - -# Including strong name files can present a security risk -# (https://github.com/github/gitignore/pull/2483#issue-259490424) -#*.snk - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm -ServiceFabricBackup/ -*.rptproj.bak - -# SQL Server files -*.mdf -*.ldf -*.ndf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings -*.rptproj.rsuser -*- [Bb]ackup.rdl -*- [Bb]ackup ([0-9]).rdl -*- [Bb]ackup ([0-9][0-9]).rdl - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat -node_modules/ - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# CodeRush personal settings -.cr/personal - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc - -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config - -# Tabs Studio -*.tss - -# Telerik's JustMock configuration file -*.jmconfig - -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs - -# OpenCover UI analysis results -OpenCover/ - -# Azure Stream Analytics local run output -ASALocalRun/ - -# MSBuild Binary and Structured Log -*.binlog - -# NVidia Nsight GPU debugger configuration file -*.nvuser - -# MFractors (Xamarin productivity tool) working folder -.mfractor/ - -# Local History for Visual Studio -.localhistory/ - -# BeatPulse healthcheck temp database -healthchecksdb - -# Backup folder for Package Reference Convert tool in Visual Studio 2017 -MigrationBackup/ - -# Ionide (cross platform F# VS Code tools) working folder -.ionide/ - -# Fody - auto-generated XML schema -FodyWeavers.xsd - -# VS Code files for those working on multiple tools -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -*.code-workspace - -# Local History for Visual Studio Code -.history/ - -# Windows Installer files from build outputs -*.cab -*.msi -*.msix -*.msm -*.msp - -# JetBrains Rider -.idea/ -*.sln.iml \ No newline at end of file +.vscode/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..cf6778e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "ogre"] + path = libs/ogre + url = https://github.com/OGRECave/ogre.git diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0db5873 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "cmake.configureOnOpen": true +} \ No newline at end of file diff --git a/images/.blank b/MyGraphicsEngine/Shader/fragment.shader similarity index 100% rename from images/.blank rename to MyGraphicsEngine/Shader/fragment.shader diff --git a/MyGraphicsEngine/Shader/vertex.shader b/MyGraphicsEngine/Shader/vertex.shader new file mode 100644 index 0000000..cdd6dd3 --- /dev/null +++ b/MyGraphicsEngine/Shader/vertex.shader @@ -0,0 +1,7 @@ +#version 330 core +layout (location = 0) in vec3 aPos; + +void main() +{ + gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0); +} \ No newline at end of file diff --git a/MyGraphicsEngine/glWindow.c b/MyGraphicsEngine/glWindow.c new file mode 100644 index 0000000..9d464af --- /dev/null +++ b/MyGraphicsEngine/glWindow.c @@ -0,0 +1,135 @@ +#include +#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; +} diff --git a/SandboxApplication/hello.cpp b/SandboxApplication/hello.cpp new file mode 100644 index 0000000..da4865c --- /dev/null +++ b/SandboxApplication/hello.cpp @@ -0,0 +1,69 @@ +#include +#include + +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); + + + +} + diff --git a/SandboxApplication/hello.lua b/SandboxApplication/hello.lua new file mode 100644 index 0000000..4a7be95 --- /dev/null +++ b/SandboxApplication/hello.lua @@ -0,0 +1,14 @@ +-- 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 + diff --git a/docs/TODO.md b/TODO.md similarity index 100% rename from docs/TODO.md rename to TODO.md diff --git a/lib/.blank b/lib/.blank deleted file mode 100644 index e69de29..0000000 diff --git a/premake5.lua b/premake5.lua index cb1db40..627e335 100644 --- a/premake5.lua +++ b/premake5.lua @@ -1,18 +1,66 @@ workspace "BarinkEngine" - configurations { "Debug", "Release" } + configurations { "Debug", "Test", "Release" } -project "Engine" - kind "ConsoleApp" - language "C" - targetdir "build/%{cfg.buildcfg}" + project "SandboxApplication" + kind "ConsoleApp" + language "C++" + cppdialect "C++17" + targetdir "./artifacts/build/%{cfg.buildcfg}" + objdir "./artifacts/obj/%{cfg.buildcfg}" - files { "src/*.c"} + includedirs { + "./libs/lua-5.4.3/", - filter "configurations:Debug" - defines {"DEBUG"} - symbols "On" + } - filter "configurations:Release" - defines {"NDEBUG"} - optimize "On" + libdirs { + os.findlib("lua") + } + + 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" + + includedirs { + "./libs/glfw-3.3.4/include/GLFW/", + "./libs/spdlog-1.9.1/include/spdlog/" + } + + libdirs{ + "./libs/spdlog-1.9.1/build/libspdlog.a", + os.findlib("glfw3"), + } + links { + -- "libspdlog", + "glfw3", + "X11", + "GL", + "GLU", + "pthread", + "dl", + "m" + } + + files {"MyGraphicsEngine/*.c"} + + filter "configurations:Debug" + defines {"DEBUG"} + symbols "On" + + filter "configurations:Release" + defines {"NDEBUG"} + optimize "On" diff --git a/scripts/load.env b/scripts/load.env deleted file mode 100644 index 131def3..0000000 --- a/scripts/load.env +++ /dev/null @@ -1,11 +0,0 @@ -# Sets up a comfortable terminal experience - -# Define aliases -alias gg="git status" -alias ga="git add" -alias gm="git commit" -alias gp="git push" -alias run=$(pwd)/scripts/run.sh - -# Define environment variables -export message="Hello environment!" \ No newline at end of file diff --git a/scripts/run.sh b/scripts/run.sh deleted file mode 100755 index 7fcd301..0000000 --- a/scripts/run.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -echo $0 - -if [ $0 -eq "Release" ]; then - echo "Run release" -else - echo "Run debug" -fi diff --git a/src/hello.c b/src/hello.c deleted file mode 100644 index ccd5f7a..0000000 --- a/src/hello.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main (void) { - puts("Hello, world!"); - return 0; -}