raylib/ports/core/core_scissor_test

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 core_scissor_test

Code

core_scissor_test.odin ¶
82 linesSource

1/*******************************************************************************************
2*
3*   raylib [core] example - scissor test
4*
5*   Example complexity rating: [★☆☆☆] 1/4
6*
7*   Example originally created with raylib 2.5, last time updated with raylib 3.0
8*
9*   Example contributed by Chris Dill (@MysteriousSpace) and reviewed by Ramon Santamaria (@raysan5)
10*
11*   Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
12*   BSD-like license that allows static linking with closed source software
13*
14*   Copyright (c) 2019-2025 Chris Dill (@MysteriousSpace)
15*
16********************************************************************************************/
17
18package raylib_examples
19
20import rl "vendor:raylib"
21
22//------------------------------------------------------------------------------------
23// Program main entry point
24//------------------------------------------------------------------------------------
25main :: proc() {
26	// Initialization
27	//--------------------------------------------------------------------------------------
28	SCREEN_WIDTH :: 800
29	SCREEN_HEIGHT :: 450
30
31	rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [core] example - scissor test")
32
33	scissor_area := rl.Rectangle {0, 0, 300, 300}
34	scissor_mode: bool = true
35
36	rl.SetTargetFPS(60)               // Set our game to run at 60 frames-per-second
37	//--------------------------------------------------------------------------------------
38
39	// Main game loop
40	for !rl.WindowShouldClose() {    // Detect window close button or ESC key
41		// Update
42		//----------------------------------------------------------------------------------
43		if rl.IsKeyPressed(.S) {
44			scissor_mode = !scissor_mode
45		}
46
47		// Centre the scissor area around the mouse position
48		scissor_area.x = f32(rl.GetMouseX()) - scissor_area.width/2
49		scissor_area.y = f32(rl.GetMouseY()) - scissor_area.height/2
50		//----------------------------------------------------------------------------------
51
52		// Draw
53		//----------------------------------------------------------------------------------
54		rl.BeginDrawing()
55
56			rl.ClearBackground(rl.RAYWHITE)
57
58			if scissor_mode {
59				rl.BeginScissorMode(i32(scissor_area.x), i32(scissor_area.y), i32(scissor_area.width), i32(scissor_area.height))
60			}
61
62			// Draw full screen rectangle and some text
63			// NOTE: Only part defined by scissor area will be rendered
64			rl.DrawRectangle(0, 0, rl.GetScreenWidth(), rl.GetScreenHeight(), rl.RED)
65			rl.DrawText("Move the mouse around to reveal this text!", 190, 200, 20, rl.LIGHTGRAY)
66
67			if scissor_mode {
68				rl.EndScissorMode()
69			}
70
71			rl.DrawRectangleLinesEx(scissor_area, 1, rl.BLACK)
72			rl.DrawText("Press S to toggle scissor test", 10, 10, 20, rl.BLACK)
73
74		rl.EndDrawing()
75		//----------------------------------------------------------------------------------
76	}
77
78	// De-Initialization
79	//--------------------------------------------------------------------------------------
80	rl.CloseWindow()        // Close window and OpenGL context
81	//--------------------------------------------------------------------------------------
82}

Declarations Used 22