inital code drop.

This commit is contained in:
Jeff Myers 2024-08-14 17:09:43 -07:00
parent fe934db383
commit 3f023baa2f
14 changed files with 571 additions and 2 deletions

63
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,63 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/Debug/${workspaceFolderBasename}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"windows": {
"miDebuggerPath": "gdb.exe",
},
"osx": {
"MIMode": "lldb"
},
"linux": {
"program": "${workspaceFolder}/bin/Debug/${workspaceFolderBasename}",
"miDebuggerPath": "/usr/bin/gdb",
},
"preLaunchTask": "build debug"
},
{
"name": "Run",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"program": "${workspaceFolder}/bin/Release/${workspaceFolderBasename}.exe",
"MIMode": "gdb",
"windows": {
"program": "${workspaceFolder}/bin/Release/${workspaceFolderBasename}.exe",
"miDebuggerPath": "gdb.exe"
},
"osx": {
"program": "${workspaceFolder}/bin/Release/${workspaceFolderBasename}",
"MIMode": "lldb"
},
"linux": {
"program": "${workspaceFolder}/bin/Release/${workspaceFolderBasename}",
"miDebuggerPath": "/usr/bin/gdb"
},
"preLaunchTask": "build release",
}
]
}

11
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,11 @@
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/*.o": true,
"**/*.exe": true,
}
}

70
.vscode/tasks.json vendored Normal file
View file

@ -0,0 +1,70 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build debug",
"type": "process",
"command": "make",
"windows": {
"command": "mingw32-make.exe",
"args": [
"SHELL=cmd"
],
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
],
"dependsOn":["UpdateMake"]
},
{
"label": "build release",
"type": "process",
"command": "make",
"windows": {
"command": "mingw32-make.exe",
"args": [
"SHELL=cmd",
"config=release_x64"
],
},
"linux": {
"args": [
"config=release_x64"
],
},
"osx": {
"args": [
],
},
"group": "build",
"problemMatcher": [
"$gcc"
],
"dependsOn":["UpdateMake"]
},
{
"label": "UpdateMake",
"type": "process",
"command": "./build/premake5",
"args": [
"gmake2"
],
"windows": {
"command": "./build/premake5.exe"
},
"linux": {
"command": "./build/premake5"
},
"osx": {
"command": "./build/premake5.osx"
},
"group": "build"
}
]
}

View file

@ -1,2 +1,66 @@
# raylib-quickstart
A simple cross platform template for windows, linux, and MacOS
# Raylib-Quikstart
Work in process quickstart for raylib using premake
# VSCode Users
Download the quickstart, rename the folder to your game name, and open it in VSCode.
Press F5 to build, and you are good to go.
# Windows Users
There are two compiler toolchains avialble for windows, MinGW-W64 (a free compiler using GCC), and Microsoft Visual Studio
## Using MinGW-W64
Double click the premake-mingw.bat file.
cd into the folder in your terminal
run make
### Note on MinGW-64 versions
Make sure you have a modern version of MinGW-W64 (not mingw).
The best place to get it is from the W64devkit from
https://github.com/skeeto/w64devkit/releases
or the version installed with the raylib installer, just make sure to add the C:\raylib\w64devkit\bin to your path if you used the raylib installer
## Microsoft Visual Studio
Run the premake-VisualStudio.bat
double click the .sln file that is geneated.
develop your game, you are good to go.
# Linux and MacOS Users
CD into the folder
run ./build/premake5 gmake2
run make
you are good to go
# Building for other OpenGL targets
If you need to build for a different OpenGL version than the default (OpenGL 3.3) you can specify an openGL version in your premake command line. Just modify the bat file or add the following to your command line
## For OpenGL 1.1
--graphics=opengl11
## For OpenGL 2.1
--graphics=opengl21
## For OpenGL 4.3
--graphics=opengl43
## For OpenGLES 2.0
--graphics=opengles2
## For OpenGLES 3.0
--graphics=opengles3
# License
Copyright (c) 2020-2024 Jeffery Myers
This software is provided "as-is", without any express or implied warranty. In no event
will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you
wrote the original software. If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented
as being the original software.
3. This notice may not be removed or altered from any source distribution.

28
build/external/premake_external.lua vendored Normal file
View file

@ -0,0 +1,28 @@
function download_progress(total, current)
local ratio = current / total;
ratio = math.min(math.max(ratio, 0), 1);
local percent = math.floor(ratio * 100);
print("Download progress (" .. percent .. "%/100%)")
end
function check_raylib()
os.chdir("external")
if(os.isdir("raylib-master") == false) then
if(not os.isfile("raylib-master.zip")) then
print("Raylib not found, downloading from github")
local result_str, response_code = http.download("https://github.com/raysan5/raylib/archive/refs/heads/master.zip", "raylib-master.zip", {
progress = download_progress,
headers = { "From: Premake", "Referer: Premake" }
})
end
print("Unzipping to " .. os.getcwd())
zip.extract("raylib-master.zip", os.getcwd())
os.remove("raylib-master.zip")
end
os.chdir("../")
end
function build_externals()
print("calling externals")
check_raylib()
end

BIN
build/premake5 Normal file

Binary file not shown.

BIN
build/premake5.exe Normal file

Binary file not shown.

175
build/premake5.lua Normal file
View file

@ -0,0 +1,175 @@
newoption
{
trigger = "graphics",
value = "OPENGL_VERSION",
description = "version of OpenGL to build raylib against",
allowed = {
{ "opengl11", "OpenGL 1.1"},
{ "opengl21", "OpenGL 2.1"},
{ "opengl33", "OpenGL 3.3"},
{ "opengl43", "OpenGL 4.3"}
},
default = "opengl33"
}
function platform_defines()
defines{"PLATFORM_DESKTOP"}
filter {"options:graphics=opengl43"}
defines{"GRAPHICS_API_OPENGL_43"}
filter {"options:graphics=opengl33"}
defines{"GRAPHICS_API_OPENGL_33"}
filter {"options:graphics=opengl21"}
defines{"GRAPHICS_API_OPENGL_21"}
filter {"options:graphics=opengl11"}
defines{"GRAPHICS_API_OPENGL_11"}
filter {"options:graphics=openges3"}
defines{"GRAPHICS_API_OPENGL_ES3"}
filter {"options:graphics=openges2"}
defines{"GRAPHICS_API_OPENGL_ES2"}
filter {"system:macosx"}
disablewarnings {"deprecated-declarations"}
filter {"system:linux"}
defines {"_GLFW_X11"}
defines {"_GNU_SOURCE"}
-- This is necessary, otherwise compilation will fail since
-- there is no CLOCK_MONOTOMIC. raylib claims to have a workaround
-- to compile under c99 without -D_GNU_SOURCE, but it didn't seem
-- to work. raylib's Makefile also adds this flag, probably why it went
-- unnoticed for so long.
-- It compiles under c11 without -D_GNU_SOURCE, because c11 requires
-- to have CLOCK_MONOTOMIC
-- See: https://github.com/raysan5/raylib/issues/2729
filter{}
end
raylib_dir = "external/raylib-master"
workspaceName = 'MyGame'
baseName = path.getbasename(path.getdirectory(os.getcwd()));
if (baseName ~= 'raylib-quickstart') then
workspaceName = baseName
end
if (os.isdir('build_files') == false) then
os.mkdir('build_files')
end
workspace (workspaceName)
location "../"
configurations { "Debug", "Release"}
platforms { "x64", "x86", "ARM64"}
defaultplatform ("x64")
filter "configurations:Debug"
defines { "DEBUG" }
symbols "On"
filter "configurations:Release"
defines { "NDEBUG" }
optimize "On"
filter { "platforms:x64" }
architecture "x86_64"
filter { "platforms:Arm64" }
architecture "ARM64"
filter {}
targetdir "bin/%{cfg.buildcfg}/"
include ("external/premake_external.lua")
build_externals()
project (workspaceName)
kind "ConsoleApp"
location "build_files/"
targetdir "../bin/%{cfg.buildcfg}"
filter "action:vs*"
debugdir "$(SolutionDir)"
filter {"action:vs*", "configurations:Release"}
kind "WindowedApp"
entrypoint "mainCRTStartup"
filter{}
vpaths
{
["Header Files/*"] = { "../include/**.h", "../include/**.hpp", "../src/**.h", "../src/**.hpp"},
["Source Files/*"] = {"../src/**.c", "src/**.cpp"},
}
files {"../src/**.c", "../src/**.cpp", "../src/**.h", "../src/**.hpp", "../include/**.h", "../include/**.hpp"}
includedirs { "../src" }
includedirs { "../include" }
links {"raylib"}
includedirs {raylib_dir .. "/src" }
includedirs {raylib_dir .."/src/external" }
includedirs { raylib_dir .."/src/external/glfw/include" }
platform_defines()
filter "action:vs*"
defines{"_WINSOCK_DEPRECATED_NO_WARNINGS", "_CRT_SECURE_NO_WARNINGS"}
dependson {"raylib"}
links {"raylib.lib"}
characterset ("MBCS")
buildoptions { "/Zc:__cplusplus" }
filter "system:windows"
defines{"_WIN32"}
links {"winmm", "gdi32"}
libdirs {"../bin/%{cfg.buildcfg}"}
filter "system:linux"
links {"pthread", "m", "dl", "rt", "X11"}
filter "system:macosx"
links {"OpenGL.framework", "Cocoa.framework", "IOKit.framework", "CoreFoundation.framework", "CoreAudio.framework", "CoreVideo.framework", "AudioToolbox.framework"}
filter{}
project "raylib"
kind "StaticLib"
platform_defines()
location "build_files/"
language "C"
targetdir "../bin/%{cfg.buildcfg}"
filter "action:vs*"
defines{"_WINSOCK_DEPRECATED_NO_WARNINGS", "_CRT_SECURE_NO_WARNINGS"}
characterset ("MBCS")
buildoptions { "/Zc:__cplusplus" }
filter{}
includedirs {raylib_dir .. "/src", raylib_dir .. "/src/external/glfw/include" }
vpaths
{
["Header Files"] = { raylib_dir .. "/src/**.h"},
["Source Files/*"] = { raylib_dir .. "/src/**.c"},
}
files {raylib_dir .. "/src/*.h", raylib_dir .. "/src/*.c"}
removefiles {raylib_dir .. "/src/rcore_*.c"}
filter { "system:macosx", "files:" .. raylib_dir .. "/src/rglfw.c" }
compileas "Objective-C"
filter{}

BIN
build/premake5.osx Normal file

Binary file not shown.

95
include/resource_dir.h Normal file
View file

@ -0,0 +1,95 @@
/**********************************************************************************************
*
* raylibExtras * Utilities and Shared Components for Raylib
*
* Resource Dir * function to help find resource dir in common locations
*
* LICENSE: MIT
*
* Copyright (c) 2022 Jeffery Myers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
**********************************************************************************************/
#pragma once
#include "raylib.h"
#if defined(__cplusplus)
extern "C" { // Prevents name mangling of functions
#endif
/// <summary>
/// Looks for the specified resource dir in several common locations
/// The working dir
/// The app dir
/// Up to 3 levels above the app dir
/// When found the dir will be set as the working dir so that assets can be loaded relative to that.
/// </summary>
/// <param name="folderName">The name of the resources dir to look for</param>
/// <returns>True if a dir with the name was found, false if no change was made to the working dir</returns>
inline bool SearchAndSetResourceDir(const char* folderName)
{
// check the working dir
if (DirectoryExists(folderName))
{
ChangeDirectory(TextFormat("%s/%s", GetWorkingDirectory(), folderName));
return true;
}
const char* appDir = GetApplicationDirectory();
// check the applicationDir
const char* dir = TextFormat("%s%s", appDir, folderName);
if (DirectoryExists(dir))
{
ChangeDirectory(dir);
return true;
}
// check one up from the app dir
dir = TextFormat("%s../%s", appDir, folderName);
if (DirectoryExists(dir))
{
ChangeDirectory(dir);
return true;
}
// check two up from the app dir
dir = TextFormat("%s../../%s", appDir, folderName);
if (DirectoryExists(dir))
{
ChangeDirectory(dir);
return true;
}
// check three up from the app dir
dir = TextFormat("%s../../../%s", appDir, folderName);
if (DirectoryExists(dir))
{
ChangeDirectory(dir);
return true;
}
return false;
}
#if defined(__cplusplus)
}
#endif

3
premake-VisualStudio.bat Normal file
View file

@ -0,0 +1,3 @@
cd build
premake5.exe vs2022 || pause
cd ../

4
premake-mingw.bat Normal file
View file

@ -0,0 +1,4 @@
cd build
premake5.exe gmake2
pause
cd ..

BIN
resources/wabbit_alpha.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 496 B

56
src/main.c Normal file
View file

@ -0,0 +1,56 @@
/*
Raylib example file.
This is an example main file for a simple raylib project.
Use this as a starting point or replace it with your code.
For a C++ project simply rename the file to .cpp and run premake
-- Copyright (c) 2020-2024 Jeffery Myers
--
--This software is provided "as-is", without any express or implied warranty. In no event
--will the authors be held liable for any damages arising from the use of this software.
--Permission is granted to anyone to use this software for any purpose, including commercial
--applications, and to alter it and redistribute it freely, subject to the following restrictions:
-- 1. The origin of this software must not be misrepresented; you must not claim that you
-- wrote the original software. If you use this software in a product, an acknowledgment
-- in the product documentation would be appreciated but is not required.
--
-- 2. Altered source versions must be plainly marked as such, and must not be misrepresented
-- as being the original software.
--
-- 3. This notice may not be removed or altered from any source distribution.
*/
#include "raylib.h"
#include "resource_dir.h"
int main ()
{
// set up the window
InitWindow(1280, 800, "Hello Raylib");
SearchAndSetResourceDir("resources");
Texture wabbit = LoadTexture("wabbit_alpha.png");
// game loop
while (!WindowShouldClose())
{
// drawing
BeginDrawing();
ClearBackground(BLACK);
DrawText("Hello Raylib", 200,200,20,WHITE);
DrawTexture(wabbit, 400, 200, WHITE);
EndDrawing();
}
// cleanup
CloseWindow();
return 0;
}