2021-03-25 16:22:10 +03:00
|
|
|
/*******************************************************************************************
|
|
|
|
*
|
|
|
|
* raylib [shapes] example - Draw Textured Polygon
|
|
|
|
*
|
2021-03-28 21:07:59 +03:00
|
|
|
* This example has been created using raylib 3.7 (www.raylib.com)
|
2021-03-25 16:22:10 +03:00
|
|
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
|
|
|
*
|
2021-03-28 21:07:59 +03:00
|
|
|
* 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)
|
2021-03-25 16:22:10 +03:00
|
|
|
*
|
|
|
|
********************************************************************************************/
|
|
|
|
|
|
|
|
#include "raylib.h"
|
|
|
|
#include "raymath.h"
|
|
|
|
|
2021-03-28 21:07:59 +03:00
|
|
|
#define MAX_POINTS 11 // 10 points and back to the start
|
|
|
|
|
2021-03-25 16:22:10 +03:00
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
// Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
const int screenWidth = 800;
|
|
|
|
const int screenHeight = 450;
|
|
|
|
|
2021-03-28 21:07:59 +03:00
|
|
|
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
|
2021-03-25 16:22:10 +03:00
|
|
|
};
|
|
|
|
|
2021-03-28 21:07:59 +03:00
|
|
|
Vector2 points[MAX_POINTS] = { 0 };
|
2021-03-25 16:22:10 +03:00
|
|
|
|
2021-03-28 21:07:59 +03:00
|
|
|
// Create the poly coords from the UV's
|
2021-03-25 16:22:10 +03:00
|
|
|
// you don't have to do this you can specify
|
|
|
|
// them however you want
|
2021-03-28 21:07:59 +03:00
|
|
|
for (int i = 0; i < MAX_POINTS; i++)
|
2021-03-25 16:22:10 +03:00
|
|
|
{
|
2021-03-28 21:07:59 +03:00
|
|
|
points[i].x = (texcoords[i].x - 0.5f)*256.0f;
|
|
|
|
points[i].y = (texcoords[i].y - 0.5f)*256.0f;
|
2021-03-25 16:22:10 +03:00
|
|
|
}
|
|
|
|
|
2021-03-28 21:07:59 +03:00
|
|
|
InitWindow(screenWidth, screenHeight, "raylib [textures] example - textured polygon");
|
2021-03-25 16:22:10 +03:00
|
|
|
|
2021-03-28 21:07:59 +03:00
|
|
|
Texture texture = LoadTexture("resources/cat.png");
|
|
|
|
|
|
|
|
float ang = 0;
|
2021-03-25 16:22:10 +03:00
|
|
|
|
|
|
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
|
|
|
//--------------------------------------------------------------------------------------
|
2021-03-28 21:07:59 +03:00
|
|
|
|
2021-03-25 16:22:10 +03:00
|
|
|
// Main game loop
|
|
|
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
|
|
|
{
|
|
|
|
// Update
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
ang++;
|
|
|
|
|
2021-03-28 21:07:59 +03:00
|
|
|
Vector2 positions[MAX_POINTS] = { 0 };
|
|
|
|
|
|
|
|
for (int i = 0; i < MAX_POINTS; i++) positions[i] = Vector2Rotate(points[i], ang);
|
|
|
|
//----------------------------------------------------------------------------------
|
2021-03-25 16:22:10 +03:00
|
|
|
|
|
|
|
// Draw
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
BeginDrawing();
|
|
|
|
|
|
|
|
ClearBackground(RAYWHITE);
|
|
|
|
|
2021-03-28 21:07:59 +03:00
|
|
|
DrawText("textured polygon", 20, 20, 20, DARKGRAY);
|
2021-03-25 16:22:10 +03:00
|
|
|
|
2021-03-28 21:07:59 +03:00
|
|
|
DrawTexturePoly(texture, (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 },
|
|
|
|
positions, texcoords, MAX_POINTS, WHITE);
|
2021-03-25 16:22:10 +03:00
|
|
|
|
|
|
|
EndDrawing();
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
}
|
|
|
|
|
|
|
|
// De-Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
2021-03-28 21:07:59 +03:00
|
|
|
UnloadTexture(texture); // Unload texture
|
|
|
|
|
|
|
|
CloseWindow(); // Close window and OpenGL context
|
2021-03-25 16:22:10 +03:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|