├── README.md ├── build.bat └── vendor └── premake5.exe /README.md: -------------------------------------------------------------------------------- 1 | # Generating Projects 2 | 3 | First we will clone this repository. Create a new directory where you would like your project to live. For example I'll create a directory called `MyCoolProject`. Open a command prompt in this directory and execute: 4 | 5 | ```bat 6 | git clone https://github.com/ambrosiogabe/opengl-template-cpp ./ 7 | ``` 8 | 9 | Then we will pull all our dependencies and create the file structure for our project. Type in: 10 | 11 | ```bat 12 | build.bat create MyCoolProject 13 | ``` 14 | 15 | where `MyCoolProject` is the name of your project. Finally we will build the actual project files using premake. Type in: 16 | 17 | ```bat 18 | build.bat vs2019 19 | ``` 20 | 21 | You can use vs2015, vs2017, codelite, xcode, etc. To see all options just type in `build.bat` and hit enter. Once you have a generated project file click onto the project file then compile and run your project and you should be greeted with a window and a console window printing out 'Hello OpenGL'. 22 | 23 | ## Requirements 24 | 25 | In order to use this build script you must have python and git installed. This means you should be able to run: 26 | 27 | ```bat 28 | python --version 29 | git --version 30 | ``` 31 | 32 | and not encounter any errors. If this works then you should be able to follow the instructions above and generate an OpenGL project. 33 | -------------------------------------------------------------------------------- /build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | IF "%~1" == "" GOTO PrintHelp 4 | IF "%~1" == "help" GOTO PrintHelp 5 | IF "%~1" == "h" GOTO PrintHelp 6 | IF "%~1" == "create" GOTO Create 7 | 8 | REM Build the project files 9 | vendor\premake5.exe %1 10 | GOTO Done 11 | 12 | :PrintHelp 13 | 14 | echo. 15 | echo Enter 'build.bat action' where action is one of the following: 16 | echo. 17 | echo codelite Generate CodeLite project files 18 | echo gmake Generate GNU makefiles for Linux 19 | echo vs2005 Generate Visual Studio 2005 project files 20 | echo vs2008 Generate Visual Studio 2008 project files 21 | echo vs2010 Generate Visual Studio 2010 project files 22 | echo vs2012 Generate Visual Studio 2012 project files 23 | echo vs2013 Generate Visual Studio 2013 project files 24 | echo vs2015 Generate Visual Studio 2015 project files 25 | echo vs2017 Generate Visual Studio 2017 project files 26 | echo vs2019 Generate Visual Studio 2019 project files 27 | echo xcode4 Generate Apple Xcode 4 project files 28 | GOTO Done 29 | 30 | :Create 31 | 32 | if "%~2" == "" GOTO PrintCreateHelp 33 | 34 | mkdir %2% 35 | mkdir %2%\vendor 36 | mkdir %2%\src 37 | mkdir %2%\include 38 | mkdir %2%\vendor\GLFW 39 | mkdir %2%\vendor\glad 40 | 41 | pushd %2%\vendor\GLFW 42 | 43 | git init 44 | git pull https://github.com/glfw/glfw 45 | 46 | popd 47 | 48 | mkdir tmp 49 | pushd tmp 50 | 51 | git init 52 | git pull https://github.com/Dav1dde/glad 53 | python -m glad --generator c --profile core --api gl=3.3 --out-path ../%2%/vendor/glad 54 | 55 | popd 56 | 57 | rmdir tmp /s /q 58 | 59 | REM Create premake file to generate solution 60 | ( 61 | echo workspace "%~2" 62 | echo architecture "x64" 63 | echo. 64 | echo configurations { 65 | echo "Debug", 66 | echo "Release", 67 | echo "Dist" 68 | echo } 69 | echo. 70 | echo startproject "%~2" 71 | echo. 72 | echo -- This is a helper variable, to concatenate the sys-arch 73 | echo outputdir = "%%{cfg.buildcfg}-%%{cfg.system}-%%{cfg.architecture}" 74 | echo. 75 | echo project "%~2" 76 | echo kind "ConsoleApp" 77 | echo language "C++" 78 | echo cppdialect "C++17" 79 | echo staticruntime "on" 80 | echo. 81 | echo targetdir("bin/" .. outputdir .. "/%{prj.name}"^) 82 | echo objdir("bin-int/" .. outputdir .. "/%{prj.name}"^) 83 | echo. 84 | echo files { 85 | echo "%~2/src/**.cpp", 86 | echo "%~2/include/**.h", 87 | echo "%~2/vendor/GLFW/include/GLFW/glfw3.h", 88 | echo "%~2/vendor/GLFW/include/GLFW/glfw3native.h", 89 | echo "%~2/vendor/GLFW/src/glfw_config.h", 90 | echo "%~2/vendor/GLFW/src/context.c", 91 | echo "%~2/vendor/GLFW/src/init.c", 92 | echo "%~2/vendor/GLFW/src/input.c", 93 | echo "%~2/vendor/GLFW/src/monitor.c", 94 | echo "%~2/vendor/GLFW/src/vulkan.c", 95 | echo "%~2/vendor/GLFW/src/window.c", 96 | echo "%~2/vendor/GLFW/src/platform.c", 97 | echo "%~2/vendor/GLFW/src/null**.c", 98 | echo "%~2/vendor/glad/include/glad/glad.h", 99 | echo "%~2/vendor/glad/include/glad/KHR/khrplatform.h", 100 | echo "%~2/vendor/glad/src/glad.c" 101 | echo } 102 | echo. 103 | echo includedirs { 104 | echo "%~2/include", 105 | echo "%~2/vendor/GLFW/include", 106 | echo "%~2/vendor/glad/include" 107 | echo } 108 | echo. 109 | echo filter "system:windows" 110 | echo buildoptions { "-lgdi32" } 111 | echo systemversion "latest" 112 | echo. 113 | echo files { 114 | echo "%~2/vendor/GLFW/src/win32_init.c", 115 | echo "%~2/vendor/GLFW/src/win32_joystick.c", 116 | echo "%~2/vendor/GLFW/src/win32_monitor.c", 117 | echo "%~2/vendor/GLFW/src/win32_time.c", 118 | echo "%~2/vendor/GLFW/src/win32_thread.c", 119 | echo "%~2/vendor/GLFW/src/win32_window.c", 120 | echo "%~2/vendor/GLFW/src/wgl_context.c", 121 | echo "%~2/vendor/GLFW/src/egl_context.c", 122 | echo "%~2/vendor/GLFW/src/osmesa_context.c", 123 | echo "%~2/vendor/GLFW/src/win32_module.c", 124 | echo "%~2/vendor/GLFW/src/win32_platform.h" 125 | echo } 126 | echo. 127 | echo defines { 128 | echo "_GLFW_WIN32", 129 | echo "_CRT_SECURE_NO_WARNINGS" 130 | echo } 131 | echo. 132 | echo filter { "configurations:Debug" } 133 | echo buildoptions "/MTd" 134 | echo runtime "Debug" 135 | echo symbols "on" 136 | echo. 137 | echo filter { "configurations:Release" } 138 | echo buildoptions "/MT" 139 | echo runtime "Release" 140 | echo optimize "on" 141 | echo. 142 | ) > premake5.lua 143 | 144 | REM Create temporary header 145 | SET hFile=%2%\include\main.h 146 | ( 147 | echo #include ^ 148 | echo #include ^ 149 | echo #include ^ 150 | echo. 151 | echo int main(^) 152 | echo { 153 | echo printf("Hello OpenGL\n"^); 154 | echo. 155 | echo glfwInit(^); 156 | echo glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3^); 157 | echo glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3^); 158 | echo glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE^); 159 | echo. 160 | echo const int windowWidth = 1920; 161 | echo const int windowHeight = 1080; 162 | echo const char* windowTitle = "OpenGL Template"; 163 | echo GLFWwindow* window = glfwCreateWindow(windowWidth, windowHeight, windowTitle, nullptr, nullptr^); 164 | echo if (window == nullptr^) 165 | echo { 166 | echo printf("Failed to create GLFW window\n"^); 167 | echo glfwTerminate(^); 168 | echo return -1; 169 | echo } 170 | echo glfwMakeContextCurrent(window^); 171 | echo. 172 | echo if (!gladLoadGLLoader((GLADloadproc^)glfwGetProcAddress^)^) 173 | echo { 174 | echo printf("Failed to initialize GLAD.\n"^); 175 | echo return -1; 176 | echo } 177 | echo. 178 | echo glViewport(0, 0, windowWidth, windowHeight^); 179 | echo while (!glfwWindowShouldClose(window^)^) 180 | echo { 181 | echo glClearColor(250.0f / 255.0f, 119.0f / 255.0f, 110.0f / 255.0f, 1.0f^); 182 | echo glClear(GL_COLOR_BUFFER_BIT^); 183 | echo. 184 | echo glfwSwapBuffers(window^); 185 | echo glfwPollEvents(^); 186 | echo } 187 | echo. 188 | echo glfwTerminate(^); 189 | echo return 0; 190 | echo } 191 | echo. 192 | ) > %hFile% 193 | 194 | REM Create small OpenGL application 195 | SET cppFile=%2%\src\main.cpp 196 | ( 197 | echo #include "main.h" 198 | echo. 199 | ) > %cppFile% 200 | 201 | GOTO Done 202 | 203 | :PrintCreateHelp 204 | 205 | echo. 206 | echo To create a new OpenGL project, make sure to have git installed and available on the command line. 207 | echo Then open a command prompt in this directory and type: 208 | echo. 209 | echo build.bat create myProject 210 | echo. 211 | echo Where 'myProject' is the name of the project you would like to create. 212 | echo. 213 | 214 | :Done -------------------------------------------------------------------------------- /vendor/premake5.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosiogabe/opengl-template-cpp/cf6a77663aed56608a6b1368875138e0e1ac0f42/vendor/premake5.exe --------------------------------------------------------------------------------