我的图像似乎可以正确加载,但实际上并没有显示,除非我将控制台窗口拖到 SDL 显示器上。只有控制台窗口重叠的 SDL 显示部分会显示出来,所以我基本上可以使用控制台窗口“绘制”图像,然后它会保留下来。
#include "SDL.h"
class Game
private:
SDL_Surface* displayWindow_;
//Rest of class
};
关键函数是:(注意 GetWallpaper() 返回一个有效指针)
void Game::Render(){
GameState* currentGameState = gameStateManager_->GetCurrentState();
if(currentGameState)
{
surface::Draw(currentGameState->GetWallpaper(), displayWindow_, 0, 0);
SDL_Flip(currentGameState->GetWallpaper());
}
return;
}
最后
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;
}
任何人都可以对此有所了解吗?