Skip to content

Commit 7982ff7

Browse files
committed
fix loading screen
1 parent 1163baf commit 7982ff7

File tree

3 files changed

+43
-23
lines changed

3 files changed

+43
-23
lines changed

Source/Menus/LoadingScreen.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515

1616
#include "raylib/raylib.h"
1717
#include "raylib/rlgl.h"
18+
#include "RenderTarget.h"
1819

1920
using namespace RTE;
2021

22+
LoadingScreen::LoadingScreen() { Clear(); }
2123
void LoadingScreen::Clear() {
2224
m_LoadingLogWriter = nullptr;
2325
m_LoadingSplashBitmap = nullptr;
26+
m_LoadingBackground.reset();
2427
m_ProgressListboxBitmap = nullptr;
2528
m_ProgressListboxPosX = 0;
2629
m_ProgressListboxPosY = 0;
@@ -69,13 +72,21 @@ void LoadingScreen::CreateLoadingSplash(int xOffset) {
6972
m_LoadingSplashBitmap = create_bitmap_ex(FrameMan::c_BPP, backbuffer->w, backbuffer->h);
7073
clear_bitmap(m_LoadingSplashBitmap);
7174

72-
StaticSceneLayer loadingSplash;
73-
loadingSplash.Create(ContentFile("Base.rte/GUIs/Title/LoadingSplash.png").GetAsBitmap(COLORCONV_NONE, false), false, Vector(), true, false, Vector(1.0F, 0));
74-
loadingSplash.SetOffset(Vector(static_cast<float>(((loadingSplash.GetBitmap()->w - g_WindowMan.GetResX()) / 2) + xOffset), 0));
75-
76-
Box loadingSplashTargetBox(Vector(0, static_cast<float>((g_WindowMan.GetResY() - loadingSplash.GetBitmap()->h) / 2)), static_cast<float>(g_WindowMan.GetResX()), static_cast<float>(loadingSplash.GetBitmap()->h));
75+
m_LoadingBackground = std::make_unique<StaticSceneLayer>();
76+
m_LoadingBackground->Create(ContentFile("Base.rte/GUIs/Title/LoadingSplash.png").GetAsBitmap(COLORCONV_NONE, false), false, Vector(), true, false, Vector(1.0F, 0));
77+
m_LoadingBackground->SetOffset(Vector(static_cast<float>(((m_LoadingBackground->GetBitmap()->w - g_WindowMan.GetResX()) / 2) + xOffset), 0));
78+
79+
Box loadingSplashTargetBox(Vector(0, static_cast<float>((g_WindowMan.GetResY() - m_LoadingBackground->GetBitmap()->h) / 2)), static_cast<float>(g_WindowMan.GetResX()), static_cast<float>(m_LoadingBackground->GetBitmap()->h));
80+
RenderTarget defaultTarget{
81+
FloatRect(0, 0, g_WindowMan.GetResX(), g_WindowMan.GetResY()),
82+
FloatRect(0, 0, g_WindowMan.GetResX(), g_WindowMan.GetResY()),
83+
0,
84+
Texture2D(),
85+
true
86+
};
87+
defaultTarget.Begin();
7788
g_WindowMan.ClearBackbuffer();
78-
loadingSplash.Draw(loadingSplashTargetBox, loadingSplashTargetBox);
89+
m_LoadingBackground->Draw(loadingSplashTargetBox, loadingSplashTargetBox);
7990
rlDrawRenderBatchActive();
8091
g_WindowMan.Present();
8192
}
@@ -140,7 +151,10 @@ void LoadingScreen::LoadingSplashProgressReport(const std::string& reportString,
140151

141152
blit(g_LoadingScreen.m_ProgressListboxBitmap, g_FrameMan.GetBackBuffer32(), 0, 0, g_LoadingScreen.m_ProgressListboxPosX, g_LoadingScreen.m_ProgressListboxPosY, g_LoadingScreen.m_ProgressListboxBitmap->w, g_LoadingScreen.m_ProgressListboxBitmap->h);
142153

154+
Box loadingSplashTargetBox(Vector(0, static_cast<float>((g_WindowMan.GetResY() - g_LoadingScreen.m_LoadingBackground->GetBitmap()->h) / 2)), static_cast<float>(g_WindowMan.GetResX()), static_cast<float>(g_LoadingScreen.m_LoadingBackground->GetBitmap()->h));
143155
g_WindowMan.ClearBackbuffer(false);
156+
g_WindowMan.GetScreenBuffer()->Begin();
157+
g_LoadingScreen.m_LoadingBackground->Draw(loadingSplashTargetBox, loadingSplashTargetBox);
144158
g_WindowMan.UploadFrame();
145159
}
146160
}

Source/Menus/LoadingScreen.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ namespace RTE {
1313
class GUIInputWrapper;
1414
class GUIControlManager;
1515
class Writer;
16+
class StaticSceneLayer;
1617

1718
/// Handling for the loading screen composition and loading progress box when starting the game.
1819
class LoadingScreen : public Singleton<LoadingScreen> {
1920

2021
public:
2122
#pragma region Creation
2223
/// Constructor method used to instantiate a LoadingScreen object in system memory.
23-
LoadingScreen() { Clear(); }
24+
LoadingScreen();
2425

2526
/// Makes the LoadingScreen object ready for use.
2627
/// @param guiScreen Pointer to a GUIScreen interface that will be used by this LoadingScreen's GUIControlManager. Ownership is NOT transferred!
@@ -58,6 +59,7 @@ namespace RTE {
5859

5960
BITMAP* m_LoadingSplashBitmap; //!< BITMAP that is used for drawing the splash screen.
6061
BITMAP* m_ProgressListboxBitmap; //!< BITMAP that the progress report will be drawn into.
62+
std::unique_ptr<StaticSceneLayer> m_LoadingBackground; //!< Loading Screen Background image.
6163
int m_ProgressListboxPosX; //!< Position of the progress report box on X axis.
6264
int m_ProgressListboxPosY; //!< Position of the progress report box on Y axis.
6365

Source/Renderer/RenderTarget.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,35 @@ using namespace RTE;
1414
RenderTarget::RenderTarget(const FloatRect& size, const FloatRect& defaultViewport, int bitDepth, Texture2D colorTexture, bool defaultFB0) {
1515
m_Size = size;
1616
m_Viewport = defaultViewport;
17-
if (colorTexture.id != 0) {
18-
m_Texture = colorTexture;
19-
m_ColorTextureOwned = false;
20-
} else {
21-
m_Texture = {
22-
.id = rlLoadTexture(nullptr, size.w, size.h, bitDepth == 8 ? PIXELFORMAT_UNCOMPRESSED_GRAYSCALE : PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1),
17+
if (!defaultFB0) {
18+
if (colorTexture.id != 0) {
19+
m_Texture = colorTexture;
20+
m_ColorTextureOwned = false;
21+
} else {
22+
m_Texture = {
23+
.id = rlLoadTexture(nullptr, size.w, size.h, bitDepth == 8 ? PIXELFORMAT_UNCOMPRESSED_GRAYSCALE : PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1),
24+
.width = static_cast<int>(size.w),
25+
.height = static_cast<int>(size.h),
26+
.mipmaps = 0,
27+
.format = bitDepth == 8 ? PIXELFORMAT_UNCOMPRESSED_GRAYSCALE : PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
28+
};
29+
}
30+
m_Depth = {
31+
.id = rlLoadTextureDepth(size.w, size.h, false),
2332
.width = static_cast<int>(size.w),
2433
.height = static_cast<int>(size.h),
2534
.mipmaps = 0,
26-
.format = bitDepth == 8 ? PIXELFORMAT_UNCOMPRESSED_GRAYSCALE : PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
35+
.format = GL_DEPTH_COMPONENT,
2736
};
28-
}
29-
m_Depth = {
30-
.id = rlLoadTextureDepth(size.w, size.h, false),
31-
.width = static_cast<int>(size.w),
32-
.height = static_cast<int>(size.h),
33-
.mipmaps = 0,
34-
.format = GL_DEPTH_COMPONENT,
35-
};
36-
if (!defaultFB0) {
3737
m_FBO = rlLoadFramebuffer();
3838
rlEnableFramebuffer(m_FBO);
3939
rlFramebufferAttach(m_FBO, m_Texture.id, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_TEXTURE2D, 0);
4040
rlFramebufferAttach(m_FBO, m_Depth.id, RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_TEXTURE2D, 0);
4141
rlDisableFramebuffer();
42+
} else {
43+
m_ColorTextureOwned = false;
44+
m_Depth.id = 0;
45+
m_Texture.id = 0;
4246
}
4347
}
4448

0 commit comments

Comments
 (0)