1
votes

My image appears to load properly but doesn't actually show up unless I drag the console window over the SDL display. Only the parts of the SDL display which the console window overlaps show up, so I can essentially "paint" the image on using the console window and after that it stays.

#include "SDL.h"

class Game 

   private:
      SDL_Surface* displayWindow_;
//Rest of class

};

The key function is: (note GetWallpaper() returns a valid pointer)

void Game::Render(){
   GameState* currentGameState = gameStateManager_->GetCurrentState();
   if(currentGameState)
   {
      surface::Draw(currentGameState->GetWallpaper(), displayWindow_, 0, 0);
      SDL_Flip(currentGameState->GetWallpaper());
   }
       return;
}

Finally

bool surface::Draw(SDL_Surface* sourceSurface, SDL_Surface* targetSurface,
                   int x, int y){
   if(sourceSurface == NULL || targetSurface == NULL)
      return false;

   SDL_Rect targetRectangle;

   targetRectangle.x = x;
   targetRectangle.y = y;

   SDL_BlitSurface(sourceSurface, NULL, targetSurface, &targetRectangle);

   return true;
}

Can anybody shed some light on this?

1
I think you should be flipping displayWindow_, not the surface you get from GetWallpaper. - jrok
Thank you so much jrok! You have cracked it! That is what I get for using functions I don't understand properly! Unfortunately I can't rep comments (I don't think) - Beetroot
I'll post a proper answer if that's it :) - jrok

1 Answers

1
votes

Judgng by your code, you're flipping the wrong surface:

SDL_Flip(currentGameState->GetWallpaper());

You're supposed to pass SDL_Flip() a pointer to the current video (display) surface, usualy that's the one you get from call to SDL_SetVideoMode(). In your case that seems to be displayWindow_.

As an aside - the behaviour you observed is explained by this quote from SDL_Flip() documentation:

A software screen surface is also updated automatically when parts of a SDL window are redrawn, caused by overlapping windows or by restoring from an iconified state.