Skip to content

Commit 13698c2

Browse files
authored
Initial commit
0 parents  commit 13698c2

29 files changed

+1510
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
raylib-master
2+
_build
3+
_bin
4+
.vs

LICENSE

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Copyright (c) 2020-2021 Jeffery Myers
2+
3+
This software is provided "as-is", without any express or implied warranty. In no event
4+
will the authors be held liable for any damages arising from the use of this software.
5+
6+
Permission is granted to anyone to use this software for any purpose, including commercial
7+
applications, and to alter it and redistribute it freely, subject to the following restrictions:
8+
9+
1. The origin of this software must not be misrepresented; you must not claim that you
10+
wrote the original software. If you use this software in a product, an acknowledgment
11+
in the product documentation would be appreciated but is not required.
12+
13+
2. Altered source versions must be plainly marked as such, and must not be misrepresented
14+
as being the original software.
15+
16+
3. This notice may not be removed or altered from any source distribution.

README.md

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Raylib Setup using Premake5
2+
This is a simplified set of instructions for how to setup a project using premake.
3+
4+
## Video Tutorial
5+
A video covering this process is here
6+
https://youtu.be/--gI9083QnU
7+
8+
# Download this repository
9+
Download the game premake repository from
10+
https://github.com/raylib-extras/game-premake/
11+
You can either download the zip file, or clone the repository.
12+
If you clone the repository, you may want to remove the stored history. Simply delete the .git directory to do this.
13+
14+
Rename the directory whatever you want. This will be the name of your game.
15+
16+
#(OPTIONAL) Get Raylib
17+
If you wish to use a specific version of raylib, follow the instructions below. If you want the current development version, skip this section and premake will download raylib for you.
18+
19+
## Download Raylib
20+
Get the raylib sources from
21+
https://github.com/raysan5/raylib
22+
Download the zip file, or clone the repository. It doesn't matter what one you use.
23+
Put the raylib sources in a folder called raylib inside your game folder (The same folder this file is in). The folder must be named raylib, it can not be raylib-master. The raylib folder should contain all the sources from raylib (including the 'src' folder)
24+
25+
# Example app
26+
This repository is pre-populated wit the raylib game template. It is a great starting point for your game.
27+
https://github.com/raysan5/raylib-game-template
28+
29+
If you want to have a different starting point, simply replace the files in the game folder with your own files.
30+
31+
## Using C++
32+
By default this process is setup to build a project using C. If you want to use C++, you can replace your files with you own cpp files. There is is a simple C++ file in the _app dir. The raylib template is designed for C, not C++, but the version in this repository has been modified to work as C++ if you choose to rename the files.
33+
34+
# Generate Projects
35+
For windows users, there are two batch files you can use depending on what compiler you are using. For linux users you can simply use a terminal.
36+
Only do ONE of these options depending on your compiler and platform.
37+
## Windows Users
38+
Visual Studio users should run
39+
40+
premake-VisualStudio.bat
41+
42+
This will generate a Visual Studio project.
43+
44+
## MinGW-w64 Users
45+
Please make sure you have a recent version of MinGW-W64. The older versons from mingw.org will not work.
46+
We recomend the W64Devkit. I thas everything needed to build raylib. I can be downloaded from here https://github.com/skeeto/w64devkit/releases
47+
48+
Once you have MinGW-W64
49+
Run the batch file.
50+
51+
premake-mingw.bat
52+
53+
This will generate a makefile for you
54+
55+
## Linux users
56+
cd to the game folder and run
57+
58+
./premake5 gmake2
59+
60+
This will generate a makefile for you.
61+
62+
## macOS users
63+
cd to the game folder and run
64+
65+
./premake5.osx gmake2
66+
67+
This will generate a makefile for you.
68+
69+
# Build your game
70+
Only do ONE of these options depending on your compiler and platform.
71+
## Windows Users
72+
Double click the .sln file that was generated in the folder. From here you can use the project as normal.
73+
74+
## MinGW-w64 Users
75+
Open your compiler terminal (w64devkit if you are using it), change to the game folder and type
76+
77+
make
78+
79+
This will build your game
80+
81+
## Linux/macOS users
82+
Open your terminal, change to the game folder and type.
83+
84+
make
85+
86+
This will build your starting game template
87+
88+
89+
# Building for other OpenGL targets
90+
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
91+
92+
## For OpenGL 1.1
93+
--graphics=opengl11
94+
95+
## For OpenGL 2.1
96+
--graphics=opengl21
97+
98+
## For OpenGL 4.3
99+
--graphics=opengl43
100+
101+
# Building extra libs
102+
If you need to add a separate library to your game you can do that very easily.
103+
Simply copy the _lib folder and rename it to what you want your lib to be called.
104+
Replace lib.c with the sources for your library (just copy them in the folder).
105+
If you library has an include folder, copy that too.
106+
Then go to the premake5.lua file in the game folder, and link your library by calling link_to with the folder name for the library.
107+
108+
link_to("LIB_FOLDER_NAME")
109+
110+
Rerun premake and it will build your library for you.
111+
Note that by default link_to will add include dirs for your library folder and library/include. If you have other include needs you will have to add those to your premake file manually.

_app/main.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Raylib example file.
3+
This is an example main file for a simple raylib project.
4+
Use this as a starting point or replace it with your code.
5+
6+
For a C++ project simply rename the file to .cpp and run premake
7+
8+
*/
9+
10+
#include "raylib.h"
11+
12+
int main ()
13+
{
14+
// set up the window
15+
InitWindow(1280, 800, "Hello Raylib");
16+
17+
// game loop
18+
while (!WindowShouldClose())
19+
{
20+
// drawing
21+
BeginDrawing();
22+
ClearBackground(BLACK);
23+
24+
DrawText("Hello Raylib", 200,200,20,WHITE);
25+
26+
EndDrawing();
27+
}
28+
29+
// cleanup
30+
CloseWindow();
31+
return 0;
32+
}

_app/premake5.lua

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
baseName = path.getbasename(os.getcwd());
3+
4+
project (baseName)
5+
kind "ConsoleApp"
6+
location "../_build"
7+
targetdir "../_bin/%{cfg.buildcfg}"
8+
9+
filter "action:vs*"
10+
debugdir "$(SolutionDir)"
11+
12+
filter {"action:vs*", "configurations:Release"}
13+
kind "WindowedApp"
14+
entrypoint "mainCRTStartup"
15+
16+
filter{}
17+
18+
vpaths
19+
{
20+
["Header Files/*"] = { "include/**.h", "include/**.hpp", "src/**.h", "src/**.hpp", "**.h", "**.hpp"},
21+
["Source Files/*"] = {"src/**.c", "src/**.cpp","**.c", "**.cpp"},
22+
}
23+
files {"**.c", "**.cpp", "**.h", "**.hpp"}
24+
25+
includedirs { "./" }
26+
includedirs { "src" }
27+
includedirs { "include" }
28+
29+
link_raylib()
30+
31+
-- To link to a lib use link_to("LIB_FOLDER_NAME")

_lib/lib.c

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// C library
2+
3+
void LibFunction()
4+
{
5+
}

_lib/premake5.lua

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
baseName = path.getbasename(os.getcwd());
3+
4+
project (baseName)
5+
kind "StaticLib"
6+
location "../_build"
7+
targetdir "../_bin/%{cfg.buildcfg}"
8+
9+
vpaths
10+
{
11+
["Header Files/*"] = { "include/**.h", "include/**.hpp", "**.h", "**.hpp"},
12+
["Source Files/*"] = { "src/**.cpp", "src/**.c", "**.cpp","**.c"},
13+
}
14+
files {"**.hpp", "**.h", "**.cpp","**.c"}
15+
16+
includedirs { "./" }
17+
includedirs { "./include" }
18+
19+
include_raylib()

game/CONVENTIONS.md

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
## C Coding Style Conventions
2+
3+
Code element | Convention | Example
4+
--- | :---: | ---
5+
Defines | ALL_CAPS | `#define PLATFORM_DESKTOP`
6+
Macros | ALL_CAPS | `#define MIN(a,b) (((a)<(b))?(a):(b))`
7+
Variables | lowerCase | `int screenWidth = 0;`, `float targetFrameTime = 0.016f;`
8+
Local variables | lowerCase | `Vector2 playerPosition = { 0 };`
9+
Global variables | lowerCase | `bool fullscreen = false;`
10+
Constants | lowerCase | `const int maxValue = 8;`
11+
Pointers | MyType *pointer | `Texture2D *array = NULL;`
12+
float values | always x.xf | `float gravity = 10.0f`
13+
Operators | value1*value2 | `int product = value*6;`
14+
Operators | value1/value2 | `int division = value/4;`
15+
Operators | value1 + value2 | `int sum = value + 10;`
16+
Operators | value1 - value2 | `int res = value - 5;`
17+
Enum | TitleCase | `enum TextureFormat`
18+
Enum members | ALL_CAPS | `PIXELFORMAT_UNCOMPRESSED_R8G8B8`
19+
Struct | TitleCase | `struct Texture2D`, `struct Material`
20+
Struct typedef | TitleCase | `typedef struct Texture { ... } Texture;`
21+
Struct members | lowerCase | `texture.width`, `color.r`
22+
Functions | TitleCase | `InitWindow()`, `LoadImageFromMemory()`
23+
Functions params | lowerCase | `width`, `height`
24+
Ternary Operator | (condition)? result1 : result2 | `printf("Value is 0: %s", (value == 0)? "yes" : "no");`
25+
26+
Other conventions:
27+
- All defined variables are ALWAYS initialized
28+
- Four spaces are used, instead of TABS
29+
- Trailing spaces are always avoided
30+
- Control flow statements are followed **by a space**:
31+
```c
32+
if (condition) value = 0;
33+
34+
while (!WindowShouldClose())
35+
{
36+
37+
}
38+
39+
for (int i = 0; i < NUM_VALUES; i++) printf("%i", i);
40+
41+
switch (value)
42+
{
43+
case 0:
44+
{
45+
46+
} break;
47+
case 2: break;
48+
default: break;
49+
}
50+
```
51+
- All conditions are always between parenthesis, but not boolean values:
52+
```c
53+
if ((value > 1) && (value < 50) && valueActive)
54+
{
55+
56+
}
57+
```
58+
- Braces and curly brackets always open-close in aligned mode:
59+
```c
60+
void SomeFunction()
61+
{
62+
// TODO: Do something here!
63+
}
64+
```
65+
66+
## Files and Directories Naming Conventions
67+
68+
- Directories are named using `snake_case`: `resources/models`, `resources/fonts`
69+
- Files are named using `snake_case`: `main_title.png`, `cubicmap.png`, `sound.wav`
70+
71+
_NOTE: Spaces and special characters are always avoided in the files/dir naming!_
72+
73+
## Games/Examples Directories Organization Conventions
74+
75+
- Resource files are organized by context and usage in the game. Loading requirements for data are also considered (grouping data when required).
76+
- Descriptive names are used for the files, just reading the name of the file it should be possible to know what is that file and where fits in the game.
77+
78+
```
79+
resources/audio/fx/long_jump.wav
80+
resources/audio/music/main_theme.ogg
81+
resources/screens/logo/logo.png
82+
resources/screens/title/title.png
83+
resources/screens/gameplay/background.png
84+
resources/characters/player.png
85+
resources/characters/enemy_slime.png
86+
resources/common/font_arial.ttf
87+
resources/common/gui.png
88+
```
89+
_NOTE: Some resources require to be loaded all at once while other require to be loaded only at initialization (gui, font)._

game/LICENSE

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Copyright (c) 2021-2022 Ramon Santamaria (@raysan5)
2+
3+
This software is provided "as-is", without any express or implied warranty. In no event
4+
will the authors be held liable for any damages arising from the use of this software.
5+
6+
Permission is granted to anyone to use this software for any purpose, including commercial
7+
applications, and to alter it and redistribute it freely, subject to the following restrictions:
8+
9+
1. The origin of this software must not be misrepresented; you must not claim that you
10+
wrote the original software. If you use this software in a product, an acknowledgment
11+
in the product documentation would be appreciated but is not required.
12+
13+
2. Altered source versions must be plainly marked as such, and must not be misrepresented
14+
as being the original software.
15+
16+
3. This notice may not be removed or altered from any source distribution.

game/README.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
-----------------------------------
2+
3+
_DISCLAIMER:_
4+
5+
Welcome to **raylib game template**!
6+
7+
This template provides a base structure to start developing a small raylib game in plain C. The repo is also pre-configured with a default `LICENSE` (zlib/libpng) and a `README.md` (this one) to be properly filled by users. Feel free to change the LICENSE as required.
8+
9+
All the sections defined by `$(Data to Fill)` are expected to be edited and filled properly. It's recommended to delete this disclaimer message after editing this `README.md` file.
10+
11+
This template has been created to be used with raylib (www.raylib.com) and it's licensed under an unmodified zlib/libpng license.
12+
13+
_Copyright (c) 2014-2022 Ramon Santamaria ([@raysan5](https://twitter.com/raysan5))_
14+
15+
-----------------------------------
16+
17+
## $(Game Title)
18+
19+
![$(Game Title)](screenshots/screenshot000.png "$(Game Title)")
20+
21+
### Description
22+
23+
$(Your Game Description)
24+
25+
### Features
26+
27+
- $(Game Feature 01)
28+
- $(Game Feature 02)
29+
- $(Game Feature 03)
30+
31+
### Controls
32+
33+
Keyboard:
34+
- $(Game Control 01)
35+
- $(Game Control 02)
36+
- $(Game Control 03)
37+
38+
### Screenshots
39+
40+
_TODO: Show your game to the world, animated GIFs recommended!._
41+
42+
### Developers
43+
44+
- $(Developer 01) - $(Role/Tasks Developed)
45+
- $(Developer 02) - $(Role/Tasks Developed)
46+
- $(Developer 03) - $(Role/Tasks Developed)
47+
48+
### Links
49+
50+
- YouTube Gameplay: $(YouTube Link)
51+
- itch.io Release: $(itch.io Game Page)
52+
- Steam Release: $(Steam Game Page)
53+
54+
### License
55+
56+
This game sources are licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check [LICENSE](LICENSE) for further details.
57+
58+
$(Additional Licenses)
59+
60+
*Copyright (c) $(Year) $(User Name) ($(User Twitter/GitHub Name))*

0 commit comments

Comments
 (0)