raylib/ports/models/models_geometric_shapes

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.
A screenshot of models_geometric_shapes

Code

models_geometric_shapes.odin ¶
89 linesSource

1/*******************************************************************************************
2*
3*   raylib [models] example - geometric shapes
4*
5*   Example complexity rating: [★☆☆☆] 1/4
6*
7*   Example originally created with raylib 1.0, last time updated with raylib 3.5
8*
9*   Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
10*   BSD-like license that allows static linking with closed source software
11*
12*   Copyright (c) 2014-2025 Ramon Santamaria (@raysan5)
13*
14********************************************************************************************/
15
16package raylib_examples
17
18import rl "vendor:raylib"
19
20//------------------------------------------------------------------------------------
21// Program main entry point
22//------------------------------------------------------------------------------------
23main :: proc() {
24	// Initialization
25	//--------------------------------------------------------------------------------------
26	SCREEN_WIDTH :: 800
27	SCREEN_HEIGHT :: 450
28
29	rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [models] example - geometric shapes")
30
31	// Define the camera to look into our 3d world
32	camera := rl.Camera {
33		position = {0, 10, 10},
34		//target = {0, 0, 0},
35		up = {0, 1, 0},
36		fovy = 45,
37		projection = .PERSPECTIVE,
38	}
39
40	rl.SetTargetFPS(60)               // Set our game to run at 60 frames-per-second
41	//--------------------------------------------------------------------------------------
42
43	// Main game loop
44	for !rl.WindowShouldClose() {    // Detect window close button or ESC key
45		// Update
46		//----------------------------------------------------------------------------------
47		// TODO: Update your variables here
48		//----------------------------------------------------------------------------------
49
50		// Draw
51		//----------------------------------------------------------------------------------
52		rl.BeginDrawing()
53
54			rl.ClearBackground(rl.RAYWHITE)
55
56			rl.BeginMode3D(camera)
57
58				rl.DrawCube({-4, 0, 2}, 2, 5, 2, rl.RED)
59				rl.DrawCubeWires({-4, 0, 2}, 2, 5, 2, rl.GOLD)
60				rl.DrawCubeWires({-4, 0, -2}, 3, 6, 2, rl.MAROON)
61
62				rl.DrawSphere({-1, 0, -2}, 1, rl.GREEN)
63				rl.DrawSphereWires({1, 0, 2}, 2, 16, 16, rl.LIME)
64
65				rl.DrawCylinder({4, 0, -2}, 1, 2, 3, 4, rl.SKYBLUE)
66				rl.DrawCylinderWires({4, 0, -2}, 1, 2, 3, 4, rl.DARKBLUE)
67				rl.DrawCylinderWires({4.5, -1, 2}, 1, 1, 2, 6, rl.BROWN)
68
69				rl.DrawCylinder({1, 0, -4}, 0, 1.5, 3, 8, rl.GOLD)
70				rl.DrawCylinderWires({1, 0, -4}, 0, 1.5, 3, 8, rl.PINK)
71
72				rl.DrawCapsule     ({-3, 1.5, -4}, {-4, -1, -4}, 1.2, 8, 8, rl.VIOLET)
73				rl.DrawCapsuleWires({-3, 1.5, -4}, {-4, -1, -4}, 1.2, 8, 8, rl.PURPLE)
74
75				rl.DrawGrid(10, 1)        // Draw a grid
76
77			rl.EndMode3D()
78
79			rl.DrawFPS(10, 10)
80
81		rl.EndDrawing()
82		//----------------------------------------------------------------------------------
83	}
84
85	// De-Initialization
86	//--------------------------------------------------------------------------------------
87	rl.CloseWindow()        // Close window and OpenGL context
88	//--------------------------------------------------------------------------------------
89}

Declarations Used 32