IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [原]SDL_Init函数

    caimouse发表于 2016-12-09 13:03:05
    love 0

    SDL_Init函数:

    用来初始化SDL库,必须在使用SDL其它函数之前调用此函数。

    int SDL_Init(Uint32 flags)

    其中,flags可以取下列值:
    SDL_INIT_TIMER:定时器
    SDL_INIT_AUDIO:音频
    SDL_INIT_VIDEO:视频
    SDL_INIT_JOYSTICK:摇杆
    SDL_INIT_HAPTIC:触摸屏
    SDL_INIT_GAMECONTROLLER:游戏控制器
    SDL_INIT_EVENTS:事件
    SDL_INIT_NOPARACHUTE:不捕获关键信号(这个不理解)
    SDL_INIT_EVERYTHING:包含上述所有选项

    http://blog.csdn.net/leixiaohua1020/article/details/40680907


    #include <exception>
    #include <string>
    #include "SDL.h"
    
    class InitError: public std::exception {
        public:
            InitError();
            InitError(const std::string&);
            virtual ~InitError() throw();
            virtual const char* what() const throw();
        private:
            std::string msg;
    };
    
    InitError::InitError():
      exception(), msg(SDL_GetError()) {}
    InitError::InitError(const std::string& m):
      exception(), msg(m) {}
    InitError::~InitError() throw() {}
    const char* InitError::what() const throw() {
        return msg.c_str();
    }
    
    class SDL {
        public:
            SDL(Uint32 flags = 0) throw(InitError);
            virtual ~SDL();
    };
    
    SDL::SDL(Uint32 flags) throw(InitError) {
        if (SDL_Init(flags) != 0)
            throw InitError();
    }
    
    SDL::~SDL() {
        SDL_Quit();
    }
    
    /* ... */
    
    #include <iostream>
    
    int main(int argc, char **argv) {
        try {
            SDL sdl(SDL_INIT_VIDEO|SDL_INIT_TIMER);
    
            /* ... */
    
            return 0;
        }
    
        catch (const InitError& err) {
            std::cerr
                << "Error while initializing SDL:  "
                << err.what() << std::endl;
        }
    
        return 1;
    }


    http://edu.csdn.net/course/detail/3324


    蔡军生



沪ICP备19023445号-2号
友情链接