SDL窗口显示不正确。在linux终端上

时间:2018-03-29 23:01:37

标签: c++ image sdl

这基本上是我的代码,非常简单,只需加载图像即可显示。但是我打开窗口表面的第一件事就是表面上有“X”,“S”等字符:

enter image description here

int main( int argc, char* args[] )
{
  SDL_Init( SDL_INIT_VIDEO );

  SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 0,
                                          SDL_HWSURFACE | SDL_DOUBLEBUF );
  SDL_WM_SetCaption( WINDOW_TITLE, 0 );
  SDL_Surface* bitmap = SDL_LoadBMP("bat.bmp");

  // Part of the bitmap that we want to draw                                                                  
  SDL_Rect source;
  source.x = 24;
  source.y = 63;
  source.w = 65;
  source.h = 44;

  // Part of the screen we want to draw the sprite to                                                         
  SDL_Rect destination;
  destination.x = 100;
  destination.y = 100;
  destination.w = 65;
  destination.h = 44;




  SDL_Event event;
  bool gameRunning = true;
  int i=1000;
  while (i)
    {
      if (SDL_PollEvent(&event))
        {
          if (event.type == SDL_QUIT)
            {
              gameRunning = false;
            }
        }
      SDL_BlitSurface(bitmap, &source, screen, &destination);
      SDL_Flip(screen);
      i--;
    }

  SDL_FreeSurface(bitmap);
  SDL_Quit();


  return 0;
}

0 个答案:

没有答案