⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 renderthread.cpp

📁 关于将SDL载入QT的程序,可以实现qT上的视频解码文件的载入
💻 CPP
字号:
#include "renderthread.h"

RenderThread::RenderThread()
{
   if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) 
   {
  	   fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
   	   ::exit(0);
   }
   atexit(SDL_Quit);
   p_ptrScreen = SDL_SetVideoMode( 640, 480, 0, SDL_SWSURFACE );
   if ( p_ptrScreen == NULL ) 
   {
   	   fprintf(stderr, "Unable to set video: %s\n", SDL_GetError());
   	   ::exit(0);
   }
   p_ptrBMP = SDL_LoadBMP( "test.bmp" );

   if (SDL_MUSTLOCK(p_ptrScreen))
      if (SDL_LockSurface(p_ptrScreen) < 0) 
        return;
    p_ptrBMP = SDL_LoadBMP( "test.bmp" );
    if (p_ptrBMP == NULL)
    {
		fprintf(stderr, "Unable to load image: %s\n", SDL_GetError());
   	   ::exit(0);
    }
    if (SDL_MUSTLOCK(p_ptrScreen)) 
        SDL_UnlockSurface(p_ptrScreen);

   p_rctPosition.x = 0;
   p_rctPosition.y = 0;
   p_rctPosition.w = p_ptrBMP->w;
   p_rctPosition.h = p_ptrBMP->h;
}

RenderThread::~RenderThread()
{
   qDebug( "Cleaning up the mess" );
   SDL_FreeSurface( p_ptrBMP );
   SDL_Quit();
}

void RenderThread::run()
{
   SDL_Event event;
   bool bRunning = false;
   
   while( 1 )
   {
      if( SDL_PollEvent( &event ) )
      {
         if( event.type == SDL_KEYDOWN )
         {
            if( event.key.keysym.sym == SDLK_ESCAPE )
            {
               ::exit( 0 );
               return;
            }
            else if( event.key.keysym.sym == SDLK_SPACE )
            {
               bRunning = bRunning == true ? false : true;
            }
         }
      }
      
      if( bRunning )
      {
         move();
      }
      
      SDL_FillRect( p_ptrScreen, 0, 0 );
      SDL_BlitSurface( p_ptrBMP, 0, p_ptrScreen, &p_rctPosition );
      SDL_Flip( p_ptrScreen );
      
      // Limit to 25 fps
      SDL_Delay( 40 );
   }
   ::exit(1);
}

void RenderThread::move()
{
   p_rctPosition.x += 5;
   if( p_rctPosition.x + p_rctPosition.w >= p_ptrScreen->w )
   {
      p_rctPosition.x = 0;
      p_rctPosition.y += 5;
   }
   if( p_rctPosition.y + p_rctPosition.h >= p_ptrScreen->h )
   {
      p_rctPosition.x = 0;
      p_rctPosition.y = 0;
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -