-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplay_image_in_responsive_way.cpp
More file actions
44 lines (36 loc) · 1.15 KB
/
Copy pathDisplay_image_in_responsive_way.cpp
File metadata and controls
44 lines (36 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Generate responsive image in window
#include <raylib.h>
#include <string>
int main()
{
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
InitWindow(800, 600, "Full Window Image Viewer");
SetTargetFPS(60);
Texture2D image = LoadTexture("assets/Mahayami.png");
Rectangle src = {0, 0, static_cast<float>(image.width), static_cast<float>(image.height)};
Vector2 origin = {0, 0};
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(BLACK);
if (image.id != 0)
{
Rectangle dest = {0, 0, static_cast<float>(GetScreenWidth()), static_cast<float>(GetScreenHeight())};
DrawTexturePro(image, src, dest, origin, 0.0f, WHITE);
}
else
{
const char *msg = "Failed to load image!";
int fontSize = 20;
int textWidth = MeasureText(msg, fontSize);
int x = (GetScreenWidth() - textWidth) / 2;
int y = GetScreenHeight() / 2 - fontSize / 2;
DrawText(msg, x, y, fontSize, RED);
}
EndDrawing();
}
if (image.id != 0)
UnloadTexture(image);
CloseWindow();
return 0;
}