Files
raylib/examples/examples_template.c

128 lines
5.7 KiB
C
Raw Permalink Normal View History

2019-05-03 17:56:58 +02:00
/*
WELCOME raylib EXAMPLES CONTRIBUTOR!
2021-04-22 18:55:24 +02:00
This is a basic template to anyone ready to contribute with some code example for the library,
2019-05-03 17:56:58 +02:00
here there are some guidelines on how to create an example to be included in raylib
1. File naming: <module>_<description> - Lower case filename, words separated by underscore,
no more than 3-4 words in total to describe the example. <module> referes to the primary
raylib module the example is more related with (code, shapes, textures, models, shaders, raudio)
2019-05-03 17:56:58 +02:00
i.e: core_input_multitouch, shapes_lines_bezier, shaders_palette_switch
2021-04-22 18:55:24 +02:00
2019-05-03 17:56:58 +02:00
2. Follow below template structure, example info should list the module, the short description
and the author of the example, twitter or github info could be also provided for the author
Short description should also be used on the title of the window
2021-04-22 18:55:24 +02:00
2019-05-03 17:56:58 +02:00
3. Code should be organized by sections:[Initialization]- [Update] - [Draw] - [De-Initialization]
Place your code between the dotted lines for every section, please don't mix update logic with drawing
and remember to unload all loaded resources
2021-04-22 18:55:24 +02:00
2019-05-03 17:56:58 +02:00
4. Code should follow raylib conventions: https://github.com/raysan5/raylib/wiki/raylib-coding-conventions
Try to be very organized, using line-breaks appropiately
2021-04-22 18:55:24 +02:00
5. Add comments to the specific parts of code the example is focus on
Don't abuse with comments, try to be clear and impersonal on the comments
2021-04-22 18:55:24 +02:00
6. Try to keep the example simple, under 300 code lines if possible. Try to avoid external dependencies
Try to avoid defining functions outside the main(). Example should be as self-contained as possible
2021-04-22 18:55:24 +02:00
2019-05-03 17:56:58 +02:00
7. About external resources, they should be placed in a [resources] folder and those resources
should be open and free for use and distribution. Avoid propietary content
2021-04-22 18:55:24 +02:00
8. Try to keep the example simple but with a creative touch
2019-05-03 17:56:58 +02:00
Simple but beautiful examples are more appealing to users!
2021-04-22 18:55:24 +02:00
2019-05-03 17:56:58 +02:00
9. In case of additional information is required, just come to raylib Discord channel: example-contributions
2021-04-22 18:55:24 +02:00
2019-05-03 17:56:58 +02:00
10. Have fun!
2023-09-23 11:13:11 +02:00
2025-10-26 18:22:23 +01:00
The following files must be updated when adding a new example,
2025-09-14 10:22:56 +02:00
but it can be automatically done using the raylib provided tool: rexm
So, no worries if just the .c/.png are provided when adding the example.
2023-09-23 11:13:11 +02:00
- raylib/examples/<category>/<category>_example_name.c
- raylib/examples/<category>/<category>_example_name.png
2025-07-31 23:55:46 +02:00
- raylib/examples/<category>/resources/..
2023-09-23 11:13:11 +02:00
- raylib/examples/Makefile
- raylib/examples/Makefile.Web
- raylib/examples/README.md
- raylib/projects/VS2022/examples/<category>_example_name.vcxproj
- raylib/projects/VS2022/raylib.sln
- raylib.com/common/examples.js
- raylib.com/examples/<category>/<category>_example_name.html
- raylib.com/examples/<category>/<category>_example_name.data
- raylib.com/examples/<category>/<category>_example_name.wasm
- raylib.com/examples/<category>/<category>_example_name.js
2019-05-03 17:56:58 +02:00
*/
/*******************************************************************************************
*
2025-08-07 17:05:57 +02:00
* raylib [<module>] example - <name/short description>
*
2025-08-05 09:40:01 +02:00
* Example complexity rating: [] 1/4
2019-05-03 17:56:58 +02:00
*
2025-08-05 09:40:01 +02:00
* Example originally created with raylib 5.5, last time updated with raylib 5.6
2019-05-03 17:56:58 +02:00
*
2025-08-05 10:04:54 +02:00
* Example contributed by <author_name> (@<user_github>) and reviewed by Ramon Santamaria (@raysan5)
2021-06-16 14:09:28 +02:00
*
2022-07-20 01:28:37 +02:00
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
2025-08-05 10:04:54 +02:00
* Copyright (c) <year_created>-<year_updated> <author_name> (@<user_github>)
2019-05-03 17:56:58 +02:00
*
********************************************************************************************/
#include "raylib.h"
2022-06-21 19:53:18 +02:00
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
2021-06-16 14:09:28 +02:00
int main(void)
2019-05-03 17:56:58 +02:00
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [<module>] example - <name>");
2021-04-22 18:55:24 +02:00
// TODO: Load resources / Initialize variables at this point
2019-05-03 17:56:58 +02:00
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update variables / Implement example logic at this point
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
2025-07-31 23:55:46 +02:00
// TODO: Draw everything that requires to be drawn at this point
2021-04-22 18:55:24 +02:00
2025-07-31 23:55:46 +02:00
DrawLineEx((Vector2){ 0, 0 }, (Vector2){ screenWidth, screenHeight }, 2.0f, RED);
DrawLineEx((Vector2){ 0, screenHeight }, (Vector2){ screenWidth, 0 }, 2.0f, RED);
DrawText("example base code template", 260, 400, 20, LIGHTGRAY);
2019-05-03 17:56:58 +02:00
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
2021-04-22 18:55:24 +02:00
2019-05-03 17:56:58 +02:00
// TODO: Unload all loaded resources at this point
2021-04-22 18:55:24 +02:00
2019-05-03 17:56:58 +02:00
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}