【问题标题】:Strange SDL blitting behaviour奇怪的 SDL blitting 行为
【发布时间】:2012-09-02 01:57:50
【问题描述】:

我的图片似乎可以正常加载,但是 除非我将控制台窗口拖到 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;
}

有人能解释一下吗?

【问题讨论】:

  • 我认为你应该翻转displayWindow_,而不是你从GetWallpaper获得的表面。
  • 非常感谢你!你已经破解了它!这就是我使用我不正确理解的功能所得到的!不幸的是我不能代表 cmets(我不认为)
  • 如果是这样,我会发布一个正确的答案:)

标签: c++ sdl


【解决方案1】:

从你的代码来看,你翻错了表面:

SDL_Flip(currentGameState->GetWallpaper());

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

顺便说一句,SDL_Flip() documentation 的这句话解释了您观察到的行为:

当重绘 SDL 窗口的某些部分时,软件屏幕表面也会自动更新,这由重叠窗口或从图标化状态恢复引起。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多