@@ -139,8 +139,6 @@ bool TCSDL_Init(ScreenSurface screen, const char* title, bool fullScreen) {
139139 std::cerr << " SDL_CreateTexturet(): " << SDL_GetError () << ' \n ' ;
140140 return false ;
141141 }
142- } else {
143- surface = SDL_GetWindowSurface (window);
144142 }
145143
146144 // Get pixel format struct
@@ -161,14 +159,9 @@ bool TCSDL_Init(ScreenSurface screen, const char* title, bool fullScreen) {
161159 // pixel order
162160 screen->pixelformat = windowPixelFormat;
163161
164- if (usesTexture) {
165- // Adjusts screen's pixel surface
166- if (IS_NULL (screen->pixels = (uint8*) malloc (screen->pitch * screen->screenH ))) {
167- std::cerr << " Failed to alloc " << (screen->pitch * screen->screenH ) << " bytes for pixel surface" << ' \n ' ;
168- return false ;
169- }
170- }else {
171- screen->pixels = (uint8*) surface->pixels ;
162+ if (IS_NULL (screen->pixels = (uint8*) malloc (screen->pitch * screen->screenH ))) {
163+ std::cerr << " Failed to alloc " << (screen->pitch * screen->screenH ) << " bytes for pixel surface" << ' \n ' ;
164+ return false ;
172165 }
173166
174167 if (IS_NULL (screen->extension = (ScreenSurfaceEx) malloc (sizeof (TScreenSurfaceEx)))) {
@@ -178,6 +171,17 @@ bool TCSDL_Init(ScreenSurface screen, const char* title, bool fullScreen) {
178171 std::cerr << " Failed to alloc TScreenSurfaceEx of " << sizeof (TScreenSurfaceEx) << " bytes" << ' \n ' ;
179172 return false ;
180173 }
174+
175+ if (!usesTexture) {
176+ surface = SDL_CreateRGBSurfaceWithFormatFrom (
177+ screen->pixels ,
178+ screen->screenW ,
179+ screen->screenH ,
180+ screen->bpp ,
181+ screen->pitch ,
182+ windowPixelFormat);
183+ }
184+
181185 SCREEN_EX (screen)->window = window;
182186 SCREEN_EX (screen)->renderer = renderer;
183187 SCREEN_EX (screen)->texture = texture;
@@ -200,6 +204,9 @@ void TCSDL_UpdateTexture(int w, int h, int pitch, void* pixels) {
200204 if (usesTexture) {
201205 // Update the given texture rectangle with new pixel data.
202206 SDL_UpdateTexture (texture, NULL , pixels, pitch);
207+ } else {
208+ // Copy virtual surface to window surface
209+ SDL_BlitSurface (surface, NULL , SDL_GetWindowSurface (window), NULL );
203210 }
204211 // Call SDL render present
205212 TCSDL_Present ();
0 commit comments