raylib/examples/shapes/shapes_basic_shapes.c

81 lines
3.6 KiB
C
Raw Normal View History

/*******************************************************************************************
*
* raylib [shapes] example - Draw basic shapes 2d (rectangle, circle, line...)
*
* This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
2022-06-21 19:53:18 +02:00
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
2019-05-20 16:36:42 +02:00
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
2019-05-20 16:36:42 +02:00
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing");
2019-05-20 16:36:42 +02:00
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
2014-09-29 23:41:05 +02:00
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
2014-09-29 23:41:05 +02:00
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
2014-09-29 23:41:05 +02:00
ClearBackground(RAYWHITE);
2014-09-29 23:41:05 +02:00
2013-12-20 12:50:43 +01:00
DrawText("some basic shapes available on raylib", 20, 20, 20, DARKGRAY);
// Circle shapes and lines
DrawCircle(screenWidth/5, 120, 35, DARKBLUE);
DrawCircleGradient(screenWidth/5, 220, 60, GREEN, SKYBLUE);
DrawCircleLines(screenWidth/5, 340, 80, DARKBLUE);
2013-12-20 12:50:43 +01:00
// Rectangle shapes and ines
2013-12-20 12:50:43 +01:00
DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED);
2017-10-14 00:11:37 +02:00
DrawRectangleGradientH(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD);
DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE); // NOTE: Uses QUADS internally, not lines
2013-12-20 12:50:43 +01:00
// Triangle shapes and lines
DrawTriangle((Vector2){screenWidth/4.0f *3.0f, 80.0f},
(Vector2){screenWidth/4.0f *3.0f - 60.0f, 150.0f},
(Vector2){screenWidth/4.0f *3.0f + 60.0f, 150.0f}, VIOLET);
2014-09-29 23:41:05 +02:00
DrawTriangleLines((Vector2){screenWidth/4.0f*3.0f, 160.0f},
(Vector2){screenWidth/4.0f*3.0f - 20.0f, 230.0f},
(Vector2){screenWidth/4.0f*3.0f + 20.0f, 230.0f}, DARKBLUE);
// Polygon shapes and lines
2021-10-25 01:21:16 -07:00
DrawPoly((Vector2){screenWidth/4.0f*3, 320}, 6, 80, 0, BROWN);
DrawPolyLinesEx((Vector2){screenWidth/4.0f*3, 320}, 6, 80, 0, 6, BEIGE);
// NOTE: We draw all LINES based shapes together to optimize internal drawing,
// this way, all LINES are rendered in a single draw pass
DrawLine(18, 42, screenWidth - 18, 42, BLACK);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
2014-09-29 23:41:05 +02:00
return 0;
}