- void EasySDL::initSDL()
- {
- // Init SDL
- cout << "Init SDL..." << endl;
- if (SDL_Init(SDL_INIT_VIDEO) < 0)
- {
- string sdlError = SDL_GetError();
- throw runtime_error("Fail to init SDL:" + sdlError);
- }
- // detect graphic card
- videoInfo = SDL_GetVideoInfo();
- if (videoInfo == NULL)
- {
- string sdlError = SDL_GetError();
- throw runtime_error("Unable to detect graphic card:" +sdlError);
- }
- // set flags
- videoFlags = SDL_OPENGL || SDL_DOUBLEBUF || SDL_HWPALETTE;
- if (videoInfo->hw_available)
- {
- cout << "Hardware Surface enabled..." << endl;
- videoFlags = videoFlags || SDL_HWSURFACE;
- }
- else
- {
- cout << "Software Surface enabled..." << endl;
- videoFlags = videoFlags || SDL_SWSURFACE;
- }
- // hardware blit
- if (videoInfo->blit_hw)
- {
- cout << "Hardware support" << endl;
- videoFlags = videoFlags || SDL_HWACCEL;
- }
- else
- cout << "Software support" << endl;
- // set attributes
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- // window caption
- SDL_WM_SetCaption(caption.c_str(), NULL);
- SDL_WM_SetIcon(IMG_Load(iconPath.c_str()), 0);
- // Init OpenGL surface
- surface = SDL_SetVideoMode(width, height, colorDepth,videoFlags);
- if (surface == NULL)
- {
- string sdlError = SDL_GetError();
- throw runtime_error("Fail to create surface:" + sdlError);
- }
- cout << "SDL done.\n";
- }