99#include " CIO/CWindow.h"
1010#include " CMap.h"
1111#include " CSurface.h"
12+ #include " Texture.h"
1213#include " globals.h"
1314#include < glad/glad.h>
1415#ifdef _WIN32
@@ -40,46 +41,49 @@ void CGame::SetAppIcon()
4041void CGame::Render ()
4142{
4243 glClear (GL_COLOR_BUFFER_BIT );
43- SDL_FillRect (Surf_Display.get (), nullptr , SDL_MapRGBA (Surf_Display->format , 0 , 0 , 0 , 0 ));
44+ glEnable (GL_BLEND );
45+ glBlendFunc (GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA );
4446
4547 // if the S2 loading screen is shown, render only this until user clicks a mouse button
4648 if (showLoadScreen)
4749 {
48- splashBg_.Draw (Rect (0 , 0 , GameResolution.x , GameResolution.y ));
50+ splashBg_.draw (Rect (0 , 0 , GameResolution.x , GameResolution.y ));
4951 SDL_GL_SwapWindow (window_.get ());
5052 return ;
5153 }
5254
5355 // render the map if active
5456 if (MapObj && MapObj->isActive ())
5557 {
56- CSurface::Draw (Surf_Display, MapObj->getSurface (), 0 , 0 );
57- std::array<char , 100 > textBuffer;
58- // text for x and y of vertex (shown in upper left corner)
59- std::snprintf (textBuffer.data (), textBuffer.size (), " %d %d" , MapObj->getVertexX (), MapObj->getVertexY ());
60- CFont::writeText (Surf_Display, textBuffer.data (), Position (20 , 20 ));
61- // text for MinReduceHeight and MaxRaiseHeight
62- std::snprintf (textBuffer.data (), textBuffer.size (),
63- " min. height: %#04x/0x3C max. height: %#04x/0x3C NormalNull: 0x0A" ,
64- MapObj->getMinReduceHeight (), MapObj->getMaxRaiseHeight ());
65- CFont::writeText (Surf_Display, textBuffer.data (), Position (100 , 20 ));
66- // text for MovementLocked
67- if (MapObj->isHorizontalMovementLocked () && MapObj->isVerticalMovementLocked ())
68- CFont::writeText (Surf_Display, " Movement locked (F9 or F10 to unlock)" , Position (20 , 40 ), FontSize::Large,
69- FontColor::Orange);
70- else if (MapObj->isHorizontalMovementLocked ())
71- CFont::writeText (Surf_Display, " Horizontal movement locked (F9 to unlock)" , Position (20 , 40 ),
72- FontSize::Large, FontColor::Orange);
73- else if (MapObj->isVerticalMovementLocked ())
74- CFont::writeText (Surf_Display, " Vertical movement locked (F10 to unlock)" , Position (20 , 40 ),
75- FontSize::Large, FontColor::Orange);
58+ if (auto * mapSurf = MapObj->getSurface ())
59+ {
60+ std::array<char , 100 > textBuffer;
61+ std::snprintf (textBuffer.data (), textBuffer.size (), " %d %d" , MapObj->getVertexX (), MapObj->getVertexY ());
62+ CFont::writeText (mapSurf, textBuffer.data (), 20 , 20 );
63+ std::snprintf (textBuffer.data (), textBuffer.size (),
64+ " min. height: %#04x/0x3C max. height: %#04x/0x3C NormalNull: 0x0A" ,
65+ MapObj->getMinReduceHeight (), MapObj->getMaxRaiseHeight ());
66+ CFont::writeText (mapSurf, textBuffer.data (), 100 , 20 );
67+ if (MapObj->isHorizontalMovementLocked () && MapObj->isVerticalMovementLocked ())
68+ CFont::writeText (mapSurf, " Movement locked (F9 or F10 to unlock)" , 20 , 40 , FontSize::Large,
69+ FontColor::Orange);
70+ else if (MapObj->isHorizontalMovementLocked ())
71+ CFont::writeText (mapSurf, " Horizontal movement locked (F9 to unlock)" , 20 , 40 , FontSize::Large,
72+ FontColor::Orange);
73+ else if (MapObj->isVerticalMovementLocked ())
74+ CFont::writeText (mapSurf, " Vertical movement locked (F10 to unlock)" , 20 , 40 , FontSize::Large,
75+ FontColor::Orange);
76+
77+ mapTex_.load (mapSurf);
78+ mapTex_.draw (Rect (0 , 0 , GameResolution.x , GameResolution.y ));
79+ }
7680 }
7781
7882 // render active menus
7983 for (auto & Menu : Menus)
8084 {
8185 if (Menu->isActive ())
82- CSurface::Draw (Surf_Display, Menu->getSurface (), 0 , 0 );
86+ Menu->draw ( Position ( 0 , 0 ) );
8387 }
8488
8589 // render windows ordered by priority
@@ -96,7 +100,7 @@ void CGame::Render()
96100 for (auto & Window : Windows)
97101 {
98102 if (Window->getPriority () == actualPriority)
99- CSurface::Draw (Surf_Display, Window->getSurface (), Window-> getX (), Window-> getY ( ));
103+ Window->draw ( Position ( 0 , 0 ));
100104 }
101105 }
102106
@@ -105,7 +109,6 @@ void CGame::Render()
105109#endif
106110
107111 ++framesPassedSinceLastFps;
108-
109112 const auto curTicks = SDL_GetTicks ();
110113 const auto diffTicks = curTicks - lastFpsTick;
111114 if (diffTicks > 1000 )
@@ -114,9 +117,16 @@ void CGame::Render()
114117 framesPassedSinceLastFps = 0 ;
115118 lastFpsTick = curTicks;
116119 }
117- CSurface::Draw (Surf_Display, lastFps.getSurface (), 0 , 0 );
120+ lastFps.draw (Position (0 , 0 ));
121+
122+ const auto & cursorImg = Cursor.clicked ? (Cursor.button .right ? cross_ : cursorClicked_) : cursor_;
123+ cursorImg.draw (Cursor.pos );
118124
119- RenderPresent ();
125+ SDL_GL_SwapWindow (window_.get ());
126+
127+ #ifdef _ADMINMODE
128+ FrameCounter++;
129+ #endif
120130
121131 if (msWait)
122132 SDL_Delay (msWait);
0 commit comments