From c20df9aa47f3a9bdaf974d7e0f6c586a5852fca2 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sun, 17 Oct 2021 19:10:09 +0200 Subject: Reviewed examples --- examples/textures/textures_poly.c | 96 ------------------------------- examples/textures/textures_poly.png | Bin 194233 -> 0 bytes examples/textures/textures_polygon.c | 100 +++++++++++++++++++++++++++++++++ examples/textures/textures_polygon.png | Bin 0 -> 194233 bytes 4 files changed, 100 insertions(+), 96 deletions(-) delete mode 100644 examples/textures/textures_poly.c delete mode 100644 examples/textures/textures_poly.png create mode 100644 examples/textures/textures_polygon.c create mode 100644 examples/textures/textures_polygon.png (limited to 'examples/textures') diff --git a/examples/textures/textures_poly.c b/examples/textures/textures_poly.c deleted file mode 100644 index a2423a4b..00000000 --- a/examples/textures/textures_poly.c +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************************* -* -* raylib [shapes] example - Draw Textured Polygon -* -* This example has been created using raylib 3.7 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Example contributed by Chris Camacho (@codifies - bedroomcoders.co.uk) and -* reviewed by Ramon Santamaria (@raysan5) -* -* Copyright (c) 2021 Chris Camacho (@codifies) and Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" -#include "raymath.h" - -#define MAX_POINTS 11 // 10 points and back to the start - -int main(void) -{ - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - Vector2 texcoords[MAX_POINTS] = { - (Vector2){ 0.75f, 0.0f }, - (Vector2){ 0.25f, 0.0f }, - (Vector2){ 0.0f, 0.5f }, - (Vector2){ 0.0f, 0.75f }, - (Vector2){ 0.25f, 1.0f}, - (Vector2){ 0.375f, 0.875f}, - (Vector2){ 0.625f, 0.875f}, - (Vector2){ 0.75f, 1.0f}, - (Vector2){ 1.0f, 0.75f}, - (Vector2){ 1.0f, 0.5f}, - (Vector2){ 0.75f, 0.0f} // Close the poly - }; - - Vector2 points[MAX_POINTS] = { 0 }; - - // Create the poly coords from the UV's - // you don't have to do this you can specify - // them however you want - for (int i = 0; i < MAX_POINTS; i++) - { - points[i].x = (texcoords[i].x - 0.5f)*256.0f; - points[i].y = (texcoords[i].y - 0.5f)*256.0f; - } - - InitWindow(screenWidth, screenHeight, "raylib [textures] example - textured polygon"); - - Texture texture = LoadTexture("resources/cat.png"); - - float angle = 0.0f; - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - angle++; - - Vector2 positions[MAX_POINTS] = { 0 }; - - for (int i = 0; i < MAX_POINTS; i++) positions[i] = Vector2Rotate(points[i], angle*DEG2RAD); - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - DrawText("textured polygon", 20, 20, 20, DARKGRAY); - - DrawTexturePoly(texture, (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 }, - positions, texcoords, MAX_POINTS, WHITE); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(texture); // Unload texture - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} diff --git a/examples/textures/textures_poly.png b/examples/textures/textures_poly.png deleted file mode 100644 index b977ada8..00000000 Binary files a/examples/textures/textures_poly.png and /dev/null differ diff --git a/examples/textures/textures_polygon.c b/examples/textures/textures_polygon.c new file mode 100644 index 00000000..9d26505e --- /dev/null +++ b/examples/textures/textures_polygon.c @@ -0,0 +1,100 @@ +/******************************************************************************************* +* +* raylib [shapes] example - Draw Textured Polygon +* +* This example has been created using raylib 3.7 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Example contributed by Chris Camacho (@codifies - bedroomcoders.co.uk) and +* reviewed by Ramon Santamaria (@raysan5) +* +* Copyright (c) 2021 Chris Camacho (@codifies) and Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" +#include "raymath.h" + +#define MAX_POINTS 11 // 10 points and back to the start + +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - textured polygon"); + + // Define texture coordinates to map our texture to poly + Vector2 texcoords[MAX_POINTS] = { + (Vector2){ 0.75f, 0.0f }, + (Vector2){ 0.25f, 0.0f }, + (Vector2){ 0.0f, 0.5f }, + (Vector2){ 0.0f, 0.75f }, + (Vector2){ 0.25f, 1.0f}, + (Vector2){ 0.375f, 0.875f}, + (Vector2){ 0.625f, 0.875f}, + (Vector2){ 0.75f, 1.0f}, + (Vector2){ 1.0f, 0.75f}, + (Vector2){ 1.0f, 0.5f}, + (Vector2){ 0.75f, 0.0f} // Close the poly + }; + + // Define the base poly vertices from the UV's + // NOTE: They can be specified in any other way + Vector2 points[MAX_POINTS] = { 0 }; + for (int i = 0; i < MAX_POINTS; i++) + { + points[i].x = (texcoords[i].x - 0.5f)*256.0f; + points[i].y = (texcoords[i].y - 0.5f)*256.0f; + } + + // Define the vertices drawing position + // NOTE: Initially same as points but updated every frame + Vector2 positions[MAX_POINTS] = { 0 }; + for (int i = 0; i < MAX_POINTS; i++) positions[i] = points[i]; + + // Load texture to be mapped to poly + Texture texture = LoadTexture("resources/cat.png"); + + float angle = 0.0f; // Rotation angle (in degrees) + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // Update points rotation with an angle transform + // NOTE: Base points position are not modified + angle++; + for (int i = 0; i < MAX_POINTS; i++) positions[i] = Vector2Rotate(points[i], angle*DEG2RAD); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("textured polygon", 20, 20, 20, DARKGRAY); + + DrawTexturePoly(texture, (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 }, + positions, texcoords, MAX_POINTS, WHITE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(texture); // Unload texture + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/examples/textures/textures_polygon.png b/examples/textures/textures_polygon.png new file mode 100644 index 00000000..b977ada8 Binary files /dev/null and b/examples/textures/textures_polygon.png differ -- cgit v1.2.3