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?
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 toSDL_SetVideoMode(). In your case that seems to bedisplayWindow_.As an aside – the behaviour you observed is explained by this quote from SDL_Flip() documentation: