@@ -40,7 +40,6 @@ void CGame::SetAppIcon()
4040void CGame::Render ()
4141{
4242 glClear (GL_COLOR_BUFFER_BIT );
43- SDL_FillRect (Surf_Display.get (), nullptr , SDL_MapRGBA (Surf_Display->format , 0 , 0 , 0 , 0 ));
4443
4544 // if the S2 loading screen is shown, render only this until user clicks a mouse button
4645 if (showLoadScreen)
@@ -50,53 +49,58 @@ void CGame::Render()
5049 return ;
5150 }
5251
53- // render the map if active
52+ // ---- 1. Menu backgrounds are drawn via getTexture() ----
53+
54+ // ---- 2. Render map (software) and draw via GL ----
55+ // Map renders directly to its own Surf_Map; we upload that to GL.
56+ // Text overlays are written onto Surf_Map before upload.
5457 if (MapObj && MapObj->isActive ())
5558 {
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);
59+ auto * mapSurf = MapObj->getSurface ();
60+ if (mapSurf)
61+ {
62+ std::array<char , 100 > textBuffer;
63+ std::snprintf (textBuffer.data (), textBuffer.size (), " %d %d" , MapObj->getVertexX (), MapObj->getVertexY ());
64+ CFont::writeText (mapSurf, textBuffer.data (), 20 , 20 );
65+ std::snprintf (textBuffer.data (), textBuffer.size (),
66+ " min. height: %#04x/0x3C max. height: %#04x/0x3C NormalNull: 0x0A" ,
67+ MapObj->getMinReduceHeight (), MapObj->getMaxRaiseHeight ());
68+ CFont::writeText (mapSurf, textBuffer.data (), 100 , 20 );
69+ if (MapObj->isHorizontalMovementLocked () && MapObj->isVerticalMovementLocked ())
70+ CFont::writeText (mapSurf, " Movement locked (F9 or F10 to unlock)" , 20 , 40 , FontSize::Large,
71+ FontColor::Orange);
72+ else if (MapObj->isHorizontalMovementLocked ())
73+ CFont::writeText (mapSurf, " Horizontal movement locked (F9 to unlock)" , 20 , 40 , FontSize::Large,
74+ FontColor::Orange);
75+ else if (MapObj->isVerticalMovementLocked ())
76+ CFont::writeText (mapSurf, " Vertical movement locked (F10 to unlock)" , 20 , 40 , FontSize::Large,
77+ FontColor::Orange);
78+
79+ mapTex_.load (mapSurf);
80+ mapTex_.Draw (Rect (0 , 0 , GameResolution.x , GameResolution.y ));
81+ }
7682 }
7783
78- // render active menus
84+ // ---- 3. Draw UI controls via OpenGL ----
7985 for (auto & Menu : Menus)
8086 {
8187 if (Menu->isActive ())
82- CSurface::Draw (Surf_Display, Menu->getSurface () , 0 , 0 );
88+ Menu->getTexture (). Draw ( Rect ( 0 , 0 , GameResolution. x , GameResolution. y ) );
8389 }
8490
85- // render windows ordered by priority
91+ // render windows ordered by priority, lowest first
8692 int highestPriority = 0 ;
87- // first find the highest priority
8893 for (auto & Window : Windows)
8994 {
9095 if (Window->getPriority () > highestPriority)
9196 highestPriority = Window->getPriority ();
9297 }
93- // render from lowest priority to highest
9498 for (int actualPriority = 0 ; actualPriority <= highestPriority; actualPriority++)
9599 {
96100 for (auto & Window : Windows)
97101 {
98102 if (Window->getPriority () == actualPriority)
99- CSurface::Draw (Surf_Display, Window->getSurface (), Window->getX (), Window->getY ());
103+ Window->getTexture (). Draw ( Position ( Window->getX (), Window->getY () ));
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,36 @@ void CGame::Render()
114117 framesPassedSinceLastFps = 0 ;
115118 lastFpsTick = curTicks;
116119 }
117- CSurface::Draw (Surf_Display, lastFps.getSurface (), 0 , 0 );
120+ {
121+ auto * fpsSurf = lastFps.getSurface ();
122+ if (fpsSurf)
123+ {
124+ fpsTex_.load (fpsSurf);
125+ glBindTexture (GL_TEXTURE_2D , fpsTex_.getHandle ());
126+ glBegin (GL_QUADS );
127+ glTexCoord2f (0 , 0 );
128+ glVertex2i (0 , 0 );
129+ glTexCoord2f (1 , 0 );
130+ glVertex2i (fpsSurf->w , 0 );
131+ glTexCoord2f (1 , 1 );
132+ glVertex2i (fpsSurf->w , fpsSurf->h );
133+ glTexCoord2f (0 , 1 );
134+ glVertex2i (0 , fpsSurf->h );
135+ glEnd ();
136+ }
137+ }
138+
139+ // ---- 5. Cursor on top of everything ----
140+ {
141+ const auto & cursorImg = Cursor.clicked ? (Cursor.button .right ? cross_ : cursorClicked_) : cursor_;
142+ cursorImg.Draw (Cursor.pos );
143+ }
118144
119- RenderPresent ();
145+ SDL_GL_SwapWindow (window_.get ());
146+
147+ #ifdef _ADMINMODE
148+ FrameCounter++;
149+ #endif
120150
121151 if (msWait)
122152 SDL_Delay (msWait);
0 commit comments