raylib/ports
Licence This example has its own licence, rather than Odin's: raylib/ports/LICENSE
These are ported Raylib examples, and as such, they are subject to Raylib's license.
Copyright (c) 2013-2024 Ramon Santamaria (@raysan5)
The rest of the licence
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.
Overview
These are ports of the official Raylib examples found here.
Because we mirror the structure of the original examples, they need to be run with -file, and for correct resource loading they need to be run from the same directory that they are in.
For example, to run the shaders/shaders_mesh_instancing.odin example:
cd shadersodin run shaders_mesh_instancing.odin -file
Code
examples_template.odin ¶108 linesSource
1/*
2 WELCOME raylib EXAMPLES CONTRIBUTOR!
3
4 This is a basic template to anyone ready to contribute with some code example for the library,
5 here there are some guidelines on how to create an example to be included in raylib
6
7 1. File naming: <module>_<description> - Lower case filename, words separated by underscore,
8 no more than 3-4 words in total to describe the example. <module> referes to the primary
9 raylib module the example is more related with (code, shapes, textures, models, shaders, raudio)
10 i.e: core_input_multitouch, shapes_lines_bezier, shaders_palette_switch
11
12 2. Follow below template structure, example info should list the module, the short description
13 and the author of the example, twitter or github info could be also provided for the author
14 Short description should also be used on the title of the window
15
16 3. Code should be organized by sections:[Initialization]- [Update] - [Draw] - [De-Initialization]
17 Place your code between the dotted lines for every section, please don't mix update logic with drawing
18 and remember to unload all loaded resources
19
20 4. Code should follow raylib & example conventions: https://github.com/raysan5/raylib/wiki/raylib-coding-conventions
21 https://github.com/odin-lang/examples?tab=readme-ov-file#contributions
22 Try to be very organized, using line-breaks appropiately
23
24 5. Add comments to the specific parts of code the example is focus on
25 Don't abuse with comments, try to be clear and impersonal on the comments
26
27 6. Try to keep the example simple, under 300 code lines if possible. Try to avoid external dependencies
28 Try to avoid defining functions outside the main(). Example should be as self-contained as possible
29
30 7. About external resources, they should be placed in a [resources] folder and those resources
31 should be open and free for use and distribution. Avoid propietary content
32
33 8. Try to keep the example simple but with a creative touch
34 Simple but beautiful examples are more appealing to users!
35
36 9. In case of additional information is required, just come to raylib Discord channel: example-contributions
37
38 10. Have fun!
39*/
40
41/*******************************************************************************************
42*
43* raylib [<module>] example - <name/short description>
44*
45* Example complexity rating: [★☆☆☆] 1/4
46*
47* Example originally created with raylib 5.5, last time updated with raylib 5.6
48*
49* Example contributed by <author_name> (@<user_github>) and reviewed by Ramon Santamaria (@raysan5)
50*
51* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
52* BSD-like license that allows static linking with closed source software
53*
54* Copyright (c) <year_created>-<year_updated> <author_name> (@<user_github>)
55*
56********************************************************************************************/
57
58package raylib_examples
59
60import rl "vendor:raylib"
61
62//------------------------------------------------------------------------------------
63// Program main entry point
64//------------------------------------------------------------------------------------
65main :: proc() {
66 // Initialization
67 //--------------------------------------------------------------------------------------
68 SCREEN_WIDTH :: 800
69 SCREEN_HEIGHT :: 450
70
71 rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [<module>] example - <name>")
72
73 // TODO: Load resources / Initialize variables at this point
74
75 rl.SetTargetFPS(60)
76 //--------------------------------------------------------------------------------------
77
78 // Main game loop
79 for !rl.WindowShouldClose() { // Detect window close button or ESC key
80 // Update
81 //----------------------------------------------------------------------------------
82 // TODO: Update variables / Implement example logic at this point
83 //----------------------------------------------------------------------------------
84
85 // Draw
86 //----------------------------------------------------------------------------------
87 rl.BeginDrawing()
88
89 rl.ClearBackground(rl.RAYWHITE)
90
91 // TODO: Draw everything that requires to be drawn at this point
92
93 rl.DrawLineEx({0, 0}, {SCREEN_WIDTH, SCREEN_HEIGHT}, 2, rl.RED)
94 rl.DrawLineEx({0, SCREEN_HEIGHT}, {SCREEN_WIDTH, 0}, 2, rl.RED)
95 rl.DrawText("example base code template", 260, 400, 20, rl.LIGHTGRAY)
96
97 rl.EndDrawing()
98 //----------------------------------------------------------------------------------
99 }
100
101 // De-Initialization
102 //--------------------------------------------------------------------------------------
103
104 // TODO: Unload all loaded resources at this point
105
106 rl.CloseWindow() // Close window and OpenGL context
107 //--------------------------------------------------------------------------------------
108}