|
| 1 | +/******************************************************************************************* |
| 2 | +* |
| 3 | +* raylib [shapes] example - polygon lines |
| 4 | +* |
| 5 | +* Example complexity rating: [★★☆☆] 2/4 |
| 6 | +* |
| 7 | +* Example originally created with raylib 6.1, last time updated with raylib 6.1 |
| 8 | +* |
| 9 | +* Example contributed by Matthew Roush (@MatthewRoush) 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) 2026 Matthew Roush (@MatthewRoush) |
| 15 | +* |
| 16 | +********************************************************************************************/ |
| 17 | + |
| 18 | +#include "raylib.h" |
| 19 | + |
| 20 | +//------------------------------------------------------------------------------------ |
| 21 | +// Program main entry point |
| 22 | +//------------------------------------------------------------------------------------ |
| 23 | +int main(void) |
| 24 | +{ |
| 25 | + // Initialization |
| 26 | + //-------------------------------------------------------------------------------------- |
| 27 | + const int screenWidth = 800; |
| 28 | + const int screenHeight = 450; |
| 29 | + |
| 30 | + InitWindow(screenWidth, screenHeight, "raylib [shapes] example - polygon lines"); |
| 31 | + |
| 32 | + int thick = 2; |
| 33 | + float rotation = 0.0f; |
| 34 | + |
| 35 | + SetTargetFPS(60); |
| 36 | + //-------------------------------------------------------------------------------------- |
| 37 | + |
| 38 | + // Main game loop |
| 39 | + while (!WindowShouldClose()) // Detect window close button or ESC key |
| 40 | + { |
| 41 | + // Update |
| 42 | + //---------------------------------------------------------------------------------- |
| 43 | + if (IsKeyPressed(KEY_UP)) thick = thick + 1; |
| 44 | + if (IsKeyPressed(KEY_DOWN)) thick = thick - 1; |
| 45 | + |
| 46 | + thick = (thick < 1) ? 1 : (thick > 60) ? 60 : thick; |
| 47 | + |
| 48 | + rotation += (360.0f/10.0f)*GetFrameTime(); |
| 49 | + //---------------------------------------------------------------------------------- |
| 50 | + |
| 51 | + // Draw |
| 52 | + //---------------------------------------------------------------------------------- |
| 53 | + BeginDrawing(); |
| 54 | + |
| 55 | + ClearBackground(RAYWHITE); |
| 56 | + |
| 57 | + DrawText(TextFormat("thick = %d", thick), 10, 280, 20, LIME); |
| 58 | + |
| 59 | + // The square and circle outlines in the top left should match |
| 60 | + // The fist pair of outlines are drawn using `DrawRectangleLinesEx()` and `DrawCircleLinesEx()` |
| 61 | + // The second pair are drawn using `DrawPolyLinesEx()` with parameters that should visually match the first pair |
| 62 | + |
| 63 | + DrawText("These should look identical!", 10, 10, 20, MAROON); |
| 64 | + |
| 65 | + // Outline pair 1 |
| 66 | + DrawRectangle(10, 40, 50, 50, LIGHTGRAY); |
| 67 | + DrawRectangleLinesEx((Rectangle){ 10, 40, 50, 50 }, (float)thick, RED); |
| 68 | + |
| 69 | + DrawCircle(95, 65, 25, LIGHTGRAY); |
| 70 | + DrawCircleLinesEx((Vector2){ 95, 65 }, 25, (float)thick, RED); |
| 71 | + |
| 72 | + DrawText("DrawRectangleLinesEx() and DrawCircleLinesEx()", 130, 60, 10, BLACK); |
| 73 | + |
| 74 | + // Outline pair 2 |
| 75 | + DrawPoly((Vector2){ 35, 125 }, 4, 35.355f, 45, LIGHTGRAY); |
| 76 | + DrawPolyLinesEx((Vector2){ 35, 125 }, 4, 35.355f, 45, (float)thick, RED); |
| 77 | + |
| 78 | + DrawPoly((Vector2){ 95, 125 }, 36, 25, 0, LIGHTGRAY); |
| 79 | + DrawPolyLinesEx((Vector2){ 95, 125 }, 36, 25, 0, (float)thick, RED); |
| 80 | + |
| 81 | + DrawText("DrawPolyLinesEx()", 130, 120, 10, BLACK); |
| 82 | + |
| 83 | + // Some other shapes, all of these outlines should have the same looking thickness |
| 84 | + DrawPoly((Vector2){ 290, 220 }, 3, 60, rotation, LIGHTGRAY); |
| 85 | + DrawPolyLinesEx((Vector2){ 290, 220 }, 3, 60, rotation, (float)thick, BLUE); |
| 86 | + |
| 87 | + DrawPoly((Vector2){ 430, 220 }, 4, 60, rotation, LIGHTGRAY); |
| 88 | + DrawPolyLinesEx((Vector2){ 430, 220 }, 4, 60, rotation, (float)thick, BLUE); |
| 89 | + |
| 90 | + DrawPoly((Vector2){ 570, 220 }, 5, 60, rotation, LIGHTGRAY); |
| 91 | + DrawPolyLinesEx((Vector2){ 570, 220 }, 5, 60, rotation, (float)thick, BLUE); |
| 92 | + |
| 93 | + DrawPoly((Vector2){ 710, 220 }, 6, 60, rotation, LIGHTGRAY); |
| 94 | + DrawPolyLinesEx((Vector2){ 710, 220 }, 6, 60, rotation, (float)thick, BLUE); |
| 95 | + |
| 96 | + DrawPoly((Vector2){ 290, 360 }, 7, 60, rotation, LIGHTGRAY); |
| 97 | + DrawPolyLinesEx((Vector2){ 290, 360 }, 7, 60, rotation, (float)thick, BLUE); |
| 98 | + |
| 99 | + DrawPoly((Vector2){ 430, 360 }, 8, 60, rotation, LIGHTGRAY); |
| 100 | + DrawPolyLinesEx((Vector2){ 430, 360 }, 8, 60, rotation, (float)thick, BLUE); |
| 101 | + |
| 102 | + DrawPoly((Vector2){ 570, 360 }, 9, 60, rotation, LIGHTGRAY); |
| 103 | + DrawPolyLinesEx((Vector2){ 570, 360 }, 9, 60, rotation, (float)thick, BLUE); |
| 104 | + |
| 105 | + DrawPoly((Vector2){ 710, 360 }, 10, 60, rotation, LIGHTGRAY); |
| 106 | + DrawPolyLinesEx((Vector2){ 710, 360 }, 10, 60, rotation, (float)thick, BLUE); |
| 107 | + |
| 108 | + EndDrawing(); |
| 109 | + //---------------------------------------------------------------------------------- |
| 110 | + } |
| 111 | + |
| 112 | + // De-Initialization |
| 113 | + //-------------------------------------------------------------------------------------- |
| 114 | + CloseWindow(); // Close window and OpenGL context |
| 115 | + //-------------------------------------------------------------------------------------- |
| 116 | + |
| 117 | + return 0; |
| 118 | +} |
0 commit comments