Repository navigation
Expand file tree
/
Copy pathLoadingWindowGUI.cpp
More file actions
100 lines (70 loc) · 1.92 KB
/
Copy pathLoadingWindowGUI.cpp
File metadata and controls
100 lines (70 loc) · 1.92 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "LoadingWindowGUI.h"
void LoadingWindowGUI::Init()
{
screenWidth = 1280;
screenHeight = 720;
SetConfigFlags(FLAG_WINDOW_UNDECORATED);
SetConfigFlags(FLAG_WINDOW_TRANSPARENT);
InitWindow(screenWidth, screenHeight, "Echo - Loading Screen");
SetTargetFPS(120);
plm = plm_create_with_filename("/Users/macbook/Downloads/Echoo.mpeg");
if (!plm) exit(-1);
framerate = plm_get_framerate(plm);
plm_set_loop(plm, 1);
int width = plm_get_width(plm);
int height = plm_get_height(plm);
plm_samples_t* sample = NULL;
imFrame.width = width;
imFrame.height = height;
imFrame.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8;
imFrame.mipmaps = 1;
imFrame.data = (unsigned char*)malloc(width * height * 3);
texture = LoadTextureFromImage(imFrame);
//pause = false;
int framesCounter = 0;
baseTime = GetTime(); // Time since InitWindow()
}
void LoadingWindowGUI::StartLoop()
{
while (!pause)
{
HandleEvents();
Draw();
}
}
void LoadingWindowGUI::Draw()
{
BeginDrawing();
ClearBackground(BLANK);
DrawTexture(texture, GetScreenWidth() / 2 - texture.width / 2, GetScreenHeight() / 2 - texture.height / 2, WHITE);
EndDrawing();
}
void LoadingWindowGUI::HandleEvents()
{
// Video should run at 'framerate' fps => One new frame every 1/framerate
double time = (GetTime() - baseTime);
if (time >= (1.0 / framerate))
{
baseTime = GetTime();
// Decode video frame
frame = plm_decode_video(plm); // Get frame as 3 planes: Y, Cr, Cb
if (frame != nullptr)
{
plm_frame_to_rgb(frame, static_cast<uint8_t*>(imFrame.data)); // Convert (Y, Cr, Cb) to RGB on the CPU (slow)
// Update texture
UpdateTexture(texture, static_cast<uint8_t*>(imFrame.data));
}
else {
pause = true;
}
}
}
void LoadingWindowGUI::ShutDown()
{
UnloadImage(imFrame);
UnloadTexture(texture);
plm_destroy(plm);
CloseWindow();
window->ClearState(FLAG_WINDOW_UNDECORATED);
window->ClearState(FLAG_WINDOW_TRANSPARENT);
}