Skip to content

Commit 053dd05

Browse files
committed
Load background image using existing texture system
- Removed manual QImage loading and texture setup for background image in MapCanvas::initializeGL(). - Background image is now loaded via loadTexture() in initTextures(), using the same fallback mechanism as other modding assets. - Renamed 'background.png' to 'background-image.png' for consistency and alignment with naming in mmapper2.qrc.
1 parent 75c1736 commit 053dd05

4 files changed

Lines changed: 9 additions & 27 deletions

File tree

src/display/Textures.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ void MapCanvas::initTextures()
255255
textures.room_needs_update = loadTexture(getPixmapFilenameRaw("room-needs-update.png"));
256256
textures.room_modified = loadTexture(getPixmapFilenameRaw("room-modified.png"));
257257

258+
textures.backgroundImage = loadTexture(getPixmapFilenameRaw("background-image.png"));
259+
260+
258261
{
259262
textures.for_each([this](SharedMMTexture &pTex) -> void {
260263
auto &tex = deref(pTex);

src/display/mapcanvas_gl.cpp

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -244,30 +244,6 @@ void MapCanvas::initializeGL()
244244
// REVISIT: should the font texture have the lowest ID?
245245
initTextures();
246246

247-
{
248-
QImage image(":/pixmaps/arda-map.png");
249-
image = image.mirrored();
250-
251-
if (!image.isNull()) {
252-
// Load the image into the backgroundImage texture
253-
m_textures.loadCustomTexture(
254-
m_textures.backgroundImage,
255-
"BackgroundImage", // Just a label
256-
QOpenGLTexture::Target2D,
257-
image);
258-
259-
// Register the texture properly with OpenGL
260-
if (m_textures.backgroundImage) {
261-
auto &tex = deref(m_textures.backgroundImage);
262-
const auto id = allocateTextureId();
263-
tex.setId(id);
264-
m_opengl.setTextureLookup(id, m_textures.backgroundImage);
265-
}
266-
} else {
267-
qWarning() << "Failed to load background image.";
268-
}
269-
}
270-
271247
auto &font = getGLFont();
272248
font.setTextureId(allocateTextureId());
273249
font.init();
@@ -574,7 +550,9 @@ void MapCanvas::actuallyPaintGL()
574550
auto &gl = getOpenGL();
575551
gl.clear(Color{getConfig().canvas.backgroundColor});
576552

577-
if (m_textures.backgroundImage && m_textures.backgroundImage->getId() != INVALID_MM_TEXTURE_ID) {
553+
if (getConfig().canvas.showBackgroundImage.get()
554+
&& m_textures.backgroundImage
555+
&& m_textures.backgroundImage->getId() != INVALID_MM_TEXTURE_ID) {
578556
const auto &tex = m_textures.backgroundImage;
579557

580558
// Z is arbitrary since we don't rely on depth testing here

src/resources/mmapper2.qrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<!DOCTYPE RCC><RCC version="1.0">
2-
<qresource>
1+
<RCC>
2+
<qresource prefix="/">
33
<file>LICENSE.GLM</file>
44
<file>LICENSE.GPL2</file>
55
<file>LICENSE.LGPL</file>
@@ -84,6 +84,7 @@
8484
<file>icons/viewmag+.png</file>
8585
<file>icons/viewmag-.png</file>
8686
<file>icons/viewmagfit.png</file>
87+
<file>pixmaps/background-image.png</file>
8788
<file>pixmaps/char-arrows.png</file>
8889
<file>pixmaps/char-room-sel.png</file>
8990
<file>pixmaps/door-down.png</file>
6.86 MB
Loading

0 commit comments

Comments
 (0)