1

我的图像似乎可以正确加载,但实际上并没有显示,除非我将控制台窗口拖到 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;
}

任何人都可以对此有所了解吗?

4

1 回答 1

1

从您的代码来看,您正在翻转错误的表面:

SDL_Flip(currentGameState->GetWallpaper());

你应该传递SDL_Flip()一个指向当前视频(显示)表面的指针,通常是你从调用SDL_SetVideoMode(). 在你的情况下,这似乎是displayWindow_

顺便说一句- 您观察到的行为由SDL_Flip() 文档中的此引用解释:

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.

于 2012-09-08T12:42:08.603 回答