Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ int CGame::Execute()

void CGame::RenderPresent()
{
displayTexture_.upload(Surf_Display->pixels);
displayTexture_.Draw(Rect(0, 0, GameResolution.x, GameResolution.y));

const auto& cursorImg = Cursor.clicked ? (Cursor.button.right ? cross_ : cursorClicked_) : cursor_;
cursorImg.Draw(Cursor.pos);

Expand Down
5 changes: 1 addition & 4 deletions CGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#pragma once

#include "CIO/CFont.h"
#include "SdlSurface.h"
#include "Texture.h"
#include <boost/filesystem/path.hpp>
#include <Point.h>
Expand All @@ -27,8 +26,6 @@ class CGame

bool Running;
bool showLoadScreen;
SdlSurface Surf_Display;
Texture displayTexture_;
SDL_GLContext glContext_ = nullptr;
SdlWindow window_;

Expand All @@ -52,6 +49,7 @@ class CGame
Texture cursor_;
Texture cursorClicked_;
Texture cross_;
Texture mapTex_; ///< Texture for the map/terrain (Surf_Map may be 8-bit)

// structure for mouse cursor
struct
Expand Down Expand Up @@ -111,6 +109,5 @@ class CGame
CMap* getMapObj();
void delMapObj();
void enterEditor(const boost::filesystem::path& filepath);
SDL_Surface* getDisplaySurface() const { return Surf_Display.get(); };
auto getRes() const { return GameResolution; }
};
11 changes: 0 additions & 11 deletions CGame_Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ bool CGame::CreateWindow()
SDL_ShowWindow(window_.get());

ApplyWindowChanges();
if(!displayTexture_.isValid() || !Surf_Display)
return false;

SetAppIcon();

Expand Down Expand Up @@ -125,16 +123,7 @@ void CGame::UpdateDisplaySize(const Extent& newSize)
appliedResolution_ = GameResolution;
appliedFullscreen_ = fullscreen;

Surf_Display = makeRGBSurface(GameResolution.x, GameResolution.y, true);
displayTexture_.createEmpty(GameResolution);

setGLViewport();
for(auto& menu : Menus)
{
menu->resetSurface();
}
for(auto& wnd : Windows)
wnd->resetSurface();
}

bool CGame::Init()
Expand Down
66 changes: 39 additions & 27 deletions CGame_Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "CIO/CWindow.h"
#include "CMap.h"
#include "CSurface.h"
#include "Texture.h"
#include "globals.h"
#include <glad/glad.h>
#ifdef _WIN32
Expand Down Expand Up @@ -40,7 +41,8 @@ void CGame::SetAppIcon()
void CGame::Render()
{
glClear(GL_COLOR_BUFFER_BIT);
SDL_FillRect(Surf_Display.get(), nullptr, SDL_MapRGBA(Surf_Display->format, 0, 0, 0, 0));
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

// if the S2 loading screen is shown, render only this until user clicks a mouse button
if(showLoadScreen)
Expand All @@ -53,33 +55,35 @@ void CGame::Render()
// render the map if active
if(MapObj && MapObj->isActive())
{
CSurface::Draw(Surf_Display, MapObj->getSurface(), 0, 0);
std::array<char, 100> textBuffer;
// text for x and y of vertex (shown in upper left corner)
std::snprintf(textBuffer.data(), textBuffer.size(), "%d %d", MapObj->getVertexX(), MapObj->getVertexY());
CFont::writeText(Surf_Display, textBuffer.data(), Position(20, 20));
// text for MinReduceHeight and MaxRaiseHeight
std::snprintf(textBuffer.data(), textBuffer.size(),
"min. height: %#04x/0x3C max. height: %#04x/0x3C NormalNull: 0x0A",
MapObj->getMinReduceHeight(), MapObj->getMaxRaiseHeight());
CFont::writeText(Surf_Display, textBuffer.data(), Position(100, 20));
// text for MovementLocked
if(MapObj->isHorizontalMovementLocked() && MapObj->isVerticalMovementLocked())
CFont::writeText(Surf_Display, "Movement locked (F9 or F10 to unlock)", Position(20, 40), FontSize::Large,
FontColor::Orange);
else if(MapObj->isHorizontalMovementLocked())
CFont::writeText(Surf_Display, "Horizontal movement locked (F9 to unlock)", Position(20, 40),
FontSize::Large, FontColor::Orange);
else if(MapObj->isVerticalMovementLocked())
CFont::writeText(Surf_Display, "Vertical movement locked (F10 to unlock)", Position(20, 40),
FontSize::Large, FontColor::Orange);
if(auto* mapSurf = MapObj->getSurface())
{
std::array<char, 100> textBuffer;
std::snprintf(textBuffer.data(), textBuffer.size(), "%d %d", MapObj->getVertexX(), MapObj->getVertexY());
CFont::writeText(mapSurf, textBuffer.data(), 20, 20);
std::snprintf(textBuffer.data(), textBuffer.size(),
"min. height: %#04x/0x3C max. height: %#04x/0x3C NormalNull: 0x0A",
MapObj->getMinReduceHeight(), MapObj->getMaxRaiseHeight());
CFont::writeText(mapSurf, textBuffer.data(), 100, 20);
if(MapObj->isHorizontalMovementLocked() && MapObj->isVerticalMovementLocked())
CFont::writeText(mapSurf, "Movement locked (F9 or F10 to unlock)", 20, 40, FontSize::Large,
FontColor::Orange);
else if(MapObj->isHorizontalMovementLocked())
CFont::writeText(mapSurf, "Horizontal movement locked (F9 to unlock)", 20, 40, FontSize::Large,
FontColor::Orange);
else if(MapObj->isVerticalMovementLocked())
CFont::writeText(mapSurf, "Vertical movement locked (F10 to unlock)", 20, 40, FontSize::Large,
FontColor::Orange);

mapTex_.load(mapSurf);
mapTex_.Draw(Rect(0, 0, GameResolution.x, GameResolution.y));
}
}

// render active menus
// render active menus — each draws itself with OpenGL
for(auto& Menu : Menus)
{
if(Menu->isActive())
CSurface::Draw(Surf_Display, Menu->getSurface(), 0, 0);
Menu->Draw(Position(0, 0));
}

// render windows ordered by priority
Expand All @@ -96,7 +100,7 @@ void CGame::Render()
for(auto& Window : Windows)
{
if(Window->getPriority() == actualPriority)
CSurface::Draw(Surf_Display, Window->getSurface(), Window->getX(), Window->getY());
Window->Draw(Position(0, 0));
}
}

Expand All @@ -105,7 +109,6 @@ void CGame::Render()
#endif

++framesPassedSinceLastFps;

const auto curTicks = SDL_GetTicks();
const auto diffTicks = curTicks - lastFpsTick;
if(diffTicks > 1000)
Expand All @@ -114,9 +117,18 @@ void CGame::Render()
framesPassedSinceLastFps = 0;
lastFpsTick = curTicks;
}
CSurface::Draw(Surf_Display, lastFps.getSurface(), 0, 0);
// Draw FPS counter directly with OpenGL text rendering
lastFps.Draw(Position(0, 0));

// ---- Cursor on top of everything ----
const auto& cursorImg = Cursor.clicked ? (Cursor.button.right ? cross_ : cursorClicked_) : cursor_;
cursorImg.Draw(Cursor.pos);

RenderPresent();
SDL_GL_SwapWindow(window_.get());

#ifdef _ADMINMODE
FrameCounter++;
#endif

if(msWait)
SDL_Delay(msWait);
Expand Down
Loading