Ejemplo n.º 1
0
SurfaceSdlGraphicsManager::~SurfaceSdlGraphicsManager() {
	// Unregister the event observer
	if (g_system->getEventManager()->getEventDispatcher() != NULL)
		g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this);

	closeOverlay();
}
SurfaceSdlGraphicsManager::~SurfaceSdlGraphicsManager() {
    closeOverlay();
}
Graphics::PixelBuffer SurfaceSdlGraphicsManager::setupScreen(uint screenW, uint screenH, bool fullscreen, bool accel3d) {
    uint32 sdlflags;
    int bpp;

    closeOverlay();

#ifdef USE_OPENGL
    _opengl = accel3d;
    _antialiasing = 0;
#endif
    _fullscreen = fullscreen;

    ConfMan.registerDefault("fullscreen_res", "desktop");
    const Common::String &fsres = ConfMan.get("fullscreen_res");
    if (fsres != "desktop") {
        uint newW, newH;
        int converted = sscanf(fsres.c_str(), "%ux%u", &newW, &newH);
        if (converted == 2) {
            _desktopW = newW;
            _desktopH = newH;
        } else {
            warning("Could not parse 'fullscreen_res' option: expected WWWxHHH, got %s", fsres.c_str());
        }
    }

    ConfMan.registerDefault("aspect_ratio", true);
    _lockAspectRatio = ConfMan.getBool("aspect_ratio");
    uint fbW = screenW;
    uint fbH = screenH;
    _gameRect = Math::Rect2d(Math::Vector2d(0, 0), Math::Vector2d(1, 1));

#ifdef USE_OPENGL
    bool framebufferSupported = false;

    // Use the desktop resolution for fullscreen when possible
    if (_fullscreen) {
        if (g_engine->hasFeature(Engine::kSupportsArbitraryResolutions)) {
            // If the game supports arbitrary resolutions, use the desktop mode as the game mode
            screenW = _desktopW;
            screenH = _desktopH;
        } else if (_opengl) {
            // If available, draw to a framebuffer and scale it to the desktop resolution
#ifndef AMIGAOS
            // Spawn a 32x32 window off-screen
            SDL_putenv(const_cast<char *>("SDL_VIDEO_WINDOW_POS=9000,9000"));
            SDL_SetVideoMode(32, 32, 0, SDL_OPENGL);
            SDL_putenv(const_cast<char *>("SDL_VIDEO_WINDOW_POS=centered"));
            Graphics::initExtensions();
            framebufferSupported = Graphics::isExtensionSupported("GL_EXT_framebuffer_object");
            if (_fullscreen && framebufferSupported) {
                screenW = _desktopW;
                screenH = _desktopH;

                if (_lockAspectRatio) {
                    float scale = MIN(_desktopH / float(fbH), _desktopW / float(fbW));
                    float scaledW = scale * (fbW / float(_desktopW));
                    float scaledH = scale * (fbH / float(_desktopH));
                    _gameRect = Math::Rect2d(
                                    Math::Vector2d(0.5 - (0.5 * scaledW), 0.5 - (0.5 * scaledH)),
                                    Math::Vector2d(0.5 + (0.5 * scaledW), 0.5 + (0.5 * scaledH))
                                );
                }
            }
#endif
        }
    }

    if (_opengl) {
        if (ConfMan.hasKey("antialiasing"))
            _antialiasing = ConfMan.getInt("antialiasing");

        SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
        setAntialiasing(true);

        sdlflags = SDL_OPENGL;
        bpp = 24;
    } else
#endif
    {
        bpp = 16;
        sdlflags = SDL_SWSURFACE;
    }

    if (_fullscreen && !accel3d && _lockAspectRatio) {
        screenW = _desktopW;
        screenH = _desktopH;
        _gameRect = Math::Rect2d(
                        Math::Vector2d((_desktopW - fbW) / 2, (_desktopH - fbH) / 2),
                        Math::Vector2d((_desktopW + fbW) / 2, (_desktopH + fbH) / 2)
                    );
    }

    if (_fullscreen)
        sdlflags |= SDL_FULLSCREEN;

    _screen = SDL_SetVideoMode(screenW, screenH, bpp, sdlflags);
#ifdef USE_OPENGL
    // If 32-bit with antialiasing failed, try 32-bit without antialiasing
    if (!_screen && _opengl && _antialiasing) {
        warning("Couldn't create 32-bit visual with AA, trying 32-bit without AA");
        setAntialiasing(false);
        _screen = SDL_SetVideoMode(screenW, screenH, bpp, sdlflags);
    }

    // If 32-bit failed, try 16-bit
    if (!_screen && _opengl) {
        warning("Couldn't create 32-bit visual, trying 16-bit");
        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_ALPHA_SIZE, 1);
        setAntialiasing(true);
        _screen = SDL_SetVideoMode(screenW, screenH, 0, sdlflags);
    }

    // If 16-bit with antialiasing failed, try 16-bit without antialiasing
    if (!_screen && _opengl && _antialiasing) {
        warning("Couldn't create 16-bit visual with AA, trying 16-bit without AA");
        setAntialiasing(false);
        _screen = SDL_SetVideoMode(screenW, screenH, 0, sdlflags);
    }

    // If 16-bit with alpha failed, try 16-bit without alpha
    if (!_screen && _opengl) {
        warning("Couldn't create 16-bit visual with alpha, trying without alpha");
        SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
        SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
        SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
        SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
        setAntialiasing(true);
        _screen = SDL_SetVideoMode(screenW, screenH, 0, sdlflags);
    }

    // If 16-bit without alpha and with antialiasing didn't work, try without antialiasing
    if (!_screen && _opengl && _antialiasing) {
        warning("Couldn't create 16-bit visual with AA, trying 16-bit without AA");
        setAntialiasing(false);
        _screen = SDL_SetVideoMode(screenW, screenH, 0, sdlflags);
    }
#endif

    if (!_screen) {
        warning("Error: %s", SDL_GetError());
        g_system->quit();
    }

#ifdef USE_OPENGL
    if (_opengl) {
        int glflag;
        const GLubyte *str;

        // apply atribute again for sure based on SDL docs
        SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);

        str = glGetString(GL_VENDOR);
        debug("INFO: OpenGL Vendor: %s", str);
        str = glGetString(GL_RENDERER);
        debug("INFO: OpenGL Renderer: %s", str);
        str = glGetString(GL_VERSION);
        debug("INFO: OpenGL Version: %s", str);
        SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &glflag);
        debug("INFO: OpenGL Red bits: %d", glflag);
        SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &glflag);
        debug("INFO: OpenGL Green bits: %d", glflag);
        SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &glflag);
        debug("INFO: OpenGL Blue bits: %d", glflag);
        SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &glflag);
        debug("INFO: OpenGL Alpha bits: %d", glflag);
        SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &glflag);
        debug("INFO: OpenGL Z buffer depth bits: %d", glflag);
        SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &glflag);
        debug("INFO: OpenGL Double Buffer: %d", glflag);
        SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &glflag);
        debug("INFO: OpenGL Stencil buffer bits: %d", glflag);

#ifdef USE_GLEW
        debug("INFO: GLEW Version: %s", glewGetString(GLEW_VERSION));
        GLenum err = glewInit();
        if (err != GLEW_OK) {
            warning("Error: %s", glewGetErrorString(err));
            g_system->quit();
        }
#endif

#ifdef USE_OPENGL_SHADERS
        debug("INFO: GLSL version: %s", glGetString(GL_SHADING_LANGUAGE_VERSION));

        const GLfloat vertices[] = {
            0.0, 0.0,
            1.0, 0.0,
            0.0, 1.0,
            1.0, 1.0,
        };

        // Setup the box shader used to render the overlay
        const char* attributes[] = { "position", "texcoord", NULL };
        _boxShader = Graphics::Shader::fromStrings("box", Graphics::BuiltinShaders::boxVertex, Graphics::BuiltinShaders::boxFragment, attributes);
        _boxVerticesVBO = Graphics::Shader::createBuffer(GL_ARRAY_BUFFER, sizeof(vertices), vertices);
        _boxShader->enableVertexAttribute("position", _boxVerticesVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
        _boxShader->enableVertexAttribute("texcoord", _boxVerticesVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
#endif

        Graphics::initExtensions();

    }
#endif

    _overlayWidth = screenW;
    _overlayHeight = screenH;

#ifdef USE_OPENGL
    if (_opengl) {
        uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
        rmask = 0x00001f00;
        gmask = 0x000007e0;
        bmask = 0x000000f8;
        amask = 0x00000000;
#else
        rmask = 0x0000f800;
        gmask = 0x000007e0;
        bmask = 0x0000001f;
        amask = 0x00000000;
#endif
        _overlayscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth, _overlayHeight, 16,
                                              rmask, gmask, bmask, amask);
        _overlayScreenGLFormat = GL_UNSIGNED_SHORT_5_6_5;
    } else
#endif
    {
        _overlayscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth, _overlayHeight, 16,
                                              _screen->format->Rmask, _screen->format->Gmask, _screen->format->Bmask, _screen->format->Amask);
    }

    if (!_overlayscreen) {
        warning("Error: %s", SDL_GetError());
        g_system->quit();
    }

    /*_overlayFormat.bytesPerPixel = _overlayscreen->format->BytesPerPixel;

    // 	For some reason the values below aren't right, at least on my system
    _overlayFormat.rLoss = _overlayscreen->format->Rloss;
    _overlayFormat.gLoss = _overlayscreen->format->Gloss;
    _overlayFormat.bLoss = _overlayscreen->format->Bloss;
    _overlayFormat.aLoss = _overlayscreen->format->Aloss;

    _overlayFormat.rShift = _overlayscreen->format->Rshift;
    _overlayFormat.gShift = _overlayscreen->format->Gshift;
    _overlayFormat.bShift = _overlayscreen->format->Bshift;
    _overlayFormat.aShift = _overlayscreen->format->Ashift;*/

    _overlayFormat = Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0);

    _screenChangeCount++;

    SDL_PixelFormat *f = _screen->format;
    _screenFormat = Graphics::PixelFormat(f->BytesPerPixel, 8 - f->Rloss, 8 - f->Gloss, 8 - f->Bloss, 0,
                                          f->Rshift, f->Gshift, f->Bshift, f->Ashift);

#if defined(USE_OPENGL) && !defined(AMIGAOS)
    if (_opengl && _fullscreen
            && !g_engine->hasFeature(Engine::kSupportsArbitraryResolutions)
            && framebufferSupported) {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
        _frameBuffer = new Graphics::FrameBuffer(fbW, fbH);
        _frameBuffer->attach();
    }
#endif
    if (_fullscreen && !accel3d) {
        _subScreen = SDL_CreateRGBSurface(SDL_SWSURFACE, fbW, fbH, bpp, _screen->format->Rmask, _screen->format->Gmask, _screen->format->Bmask, _screen->format->Amask);
        return Graphics::PixelBuffer(_screenFormat, (byte *)_subScreen->pixels);
    }
    return Graphics::PixelBuffer(_screenFormat, (byte *)_screen->pixels);
}
void SurfaceSdlGraphicsManager::launcherInitSize(uint w, uint h) {
    closeOverlay();
    setupScreen(w, h, false, false);
}
Graphics::PixelBuffer SurfaceSdlGraphicsManager::setupScreen(uint screenW, uint screenH, bool fullscreen, bool accel3d) {
	uint32 sdlflags;
	int bpp;

	closeOverlay();

#ifdef USE_OPENGL
	_opengl = accel3d;
	_antialiasing = 0;
#endif
	_fullscreen = fullscreen;

#ifdef USE_OPENGL
	if (_opengl) {
		if (ConfMan.hasKey("antialiasing"))
			_antialiasing = ConfMan.getInt("antialiasing");

		SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
		SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
		SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
		SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
		SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
		SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
		setAntialiasing(true);

		sdlflags = SDL_OPENGL;
		bpp = 24;
	} else
#endif
	{
		bpp = 16;
		sdlflags = SDL_SWSURFACE;
	}

	if (_fullscreen)
		sdlflags |= SDL_FULLSCREEN;

	_screen = SDL_SetVideoMode(screenW, screenH, bpp, sdlflags);
#ifdef USE_OPENGL
	// If 32-bit with antialiasing failed, try 32-bit without antialiasing
	if (!_screen && _opengl && _antialiasing) {
		warning("Couldn't create 32-bit visual with AA, trying 32-bit without AA");
		setAntialiasing(false);
		_screen = SDL_SetVideoMode(screenW, screenH, bpp, sdlflags);
	}

	// If 32-bit failed, try 16-bit
	if (!_screen && _opengl) {
		warning("Couldn't create 32-bit visual, trying 16-bit");
		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_ALPHA_SIZE, 1);
		setAntialiasing(true);
		_screen = SDL_SetVideoMode(screenW, screenH, 0, sdlflags);
	}

	// If 16-bit with antialiasing failed, try 16-bit without antialiasing
	if (!_screen && _opengl && _antialiasing) {
		warning("Couldn't create 16-bit visual with AA, trying 16-bit without AA");
		setAntialiasing(false);
		_screen = SDL_SetVideoMode(screenW, screenH, 0, sdlflags);
	}
#endif

	if (!_screen) {
		warning("Error: %s", SDL_GetError());
		g_system->quit();
	}

#ifdef USE_OPENGL
	if (_opengl) {
		int glflag;
		const GLubyte *str;

		// apply atribute again for sure based on SDL docs
		SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);

		str = glGetString(GL_VENDOR);
		debug("INFO: OpenGL Vendor: %s", str);
		str = glGetString(GL_RENDERER);
		debug("INFO: OpenGL Renderer: %s", str);
		str = glGetString(GL_VERSION);
		debug("INFO: OpenGL Version: %s", str);
		SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &glflag);
		debug("INFO: OpenGL Red bits: %d", glflag);
		SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &glflag);
		debug("INFO: OpenGL Green bits: %d", glflag);
		SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &glflag);
		debug("INFO: OpenGL Blue bits: %d", glflag);
		SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &glflag);
		debug("INFO: OpenGL Alpha bits: %d", glflag);
		SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &glflag);
		debug("INFO: OpenGL Z buffer depth bits: %d", glflag);
		SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &glflag);
		debug("INFO: OpenGL Double Buffer: %d", glflag);
		SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &glflag);
		debug("INFO: OpenGL Stencil buffer bits: %d", glflag);

#ifdef USE_OPENGL_SHADERS
		debug("INFO: GLSL version: %s", glGetString(GL_SHADING_LANGUAGE_VERSION));

		debug("INFO: GLEW Version: %s", glewGetString(GLEW_VERSION));

		// GLEW needs to be initialized to use shaders
		GLenum err = glewInit();
		if (err != GLEW_OK) {
			warning("Error: %s", glewGetErrorString(err));
			g_system->quit();
		}

		const GLfloat vertices[] = {
			0.0, 0.0,
			1.0, 0.0,
			0.0, 1.0,
			1.0, 1.0,
		};

		// Setup the box shader used to render the overlay
		const char* attributes[] = { "position", "texcoord", NULL };
		_boxShader = Graphics::Shader::fromStrings("box", Graphics::BuiltinShaders::boxVertex, Graphics::BuiltinShaders::boxFragment, attributes);
		_boxVerticesVBO = Graphics::Shader::createBuffer(GL_ARRAY_BUFFER, sizeof(vertices), vertices);
		_boxShader->enableVertexAttribute("position", _boxVerticesVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
		_boxShader->enableVertexAttribute("texcoord", _boxVerticesVBO, 2, GL_FLOAT, GL_TRUE, 2 * sizeof(float), 0);
#endif

	}
#endif

	_overlayWidth = screenW;
	_overlayHeight = screenH;

#ifdef USE_OPENGL
	if (_opengl) {
		uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
		rmask = 0x00001f00;
		gmask = 0x000007e0;
		bmask = 0x000000f8;
		amask = 0x00000000;
#else
		rmask = 0x0000f800;
		gmask = 0x000007e0;
		bmask = 0x0000001f;
		amask = 0x00000000;
#endif
		_overlayscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth, _overlayHeight, 16,
						rmask, gmask, bmask, amask);
		_overlayScreenGLFormat = GL_UNSIGNED_SHORT_5_6_5;
	} else
#endif
	{
		_overlayscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth, _overlayHeight, 16,
					_screen->format->Rmask, _screen->format->Gmask, _screen->format->Bmask, _screen->format->Amask);
	}

	if (!_overlayscreen) {
		warning("Error: %s", SDL_GetError());
		g_system->quit();
	}

	/*_overlayFormat.bytesPerPixel = _overlayscreen->format->BytesPerPixel;

// 	For some reason the values below aren't right, at least on my system
	_overlayFormat.rLoss = _overlayscreen->format->Rloss;
	_overlayFormat.gLoss = _overlayscreen->format->Gloss;
	_overlayFormat.bLoss = _overlayscreen->format->Bloss;
	_overlayFormat.aLoss = _overlayscreen->format->Aloss;

	_overlayFormat.rShift = _overlayscreen->format->Rshift;
	_overlayFormat.gShift = _overlayscreen->format->Gshift;
	_overlayFormat.bShift = _overlayscreen->format->Bshift;
	_overlayFormat.aShift = _overlayscreen->format->Ashift;*/

	_overlayFormat = Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0);

	_screenChangeCount++;

	SDL_PixelFormat *f = _screen->format;
	_screenFormat = Graphics::PixelFormat(f->BytesPerPixel, 8 - f->Rloss, 8 - f->Gloss, 8 - f->Bloss, 0,
										f->Rshift, f->Gshift, f->Bshift, f->Ashift);

	return Graphics::PixelBuffer(_screenFormat, (byte *)_screen->pixels);
}
Ejemplo n.º 6
0
Graphics::PixelBuffer SurfaceSdlGraphicsManager::setupScreen(int screenW, int screenH, bool fullscreen, bool accel3d) {
	uint32 sdlflags;
	int bpp;

	closeOverlay();

#ifdef USE_OPENGL
	_opengl = accel3d;
	_antialiasing = 0;
#endif
	_fullscreen = fullscreen;

#ifdef USE_OPENGL
	if (_opengl) {
		if (ConfMan.hasKey("antialiasing"))
			_antialiasing = ConfMan.getInt("antialiasing");

		SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
		SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
		SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
		SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
		SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
		SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
		setAntialiasing(true);

		sdlflags = SDL_OPENGL;
		bpp = 24;
	} else
#endif
	{
		bpp = 16;
		sdlflags = SDL_HWSURFACE;
	}

	if (_fullscreen)
		sdlflags |= SDL_FULLSCREEN;

	_screen = SDL_SetVideoMode(screenW, screenH, bpp, sdlflags);
#ifdef USE_OPENGL
	// If 32-bit with antialiasing failed, try 32-bit without antialiasing
	if (!_screen && _opengl && _antialiasing) {
		warning("Couldn't create 32-bit visual with AA, trying 32-bit without AA");
		setAntialiasing(false);
		_screen = SDL_SetVideoMode(screenW, screenH, bpp, sdlflags);
	}

	// If 32-bit failed, try 16-bit
	if (!_screen && _opengl) {
		warning("Couldn't create 32-bit visual, trying 16-bit");
		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_ALPHA_SIZE, 1);
		setAntialiasing(true);
		_screen = SDL_SetVideoMode(screenW, screenH, 0, sdlflags);
	}

	// If 16-bit with antialiasing failed, try 16-bit without antialiasing
	if (!_screen && _opengl && _antialiasing) {
		warning("Couldn't create 16-bit visual with AA, trying 16-bit without AA");
		setAntialiasing(false);
		_screen = SDL_SetVideoMode(screenW, screenH, 0, sdlflags);
	}
#endif

	if (!_screen)
		error("Could not initialize video: %s", SDL_GetError());

#ifdef USE_OPENGL
	if (_opengl) {
		int glflag;

		// apply atribute again for sure based on SDL docs
		SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);

		SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &glflag);
		warning("INFO: GL RED bits: %d", glflag);
		SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &glflag);
		warning("INFO: GL GREEN bits: %d", glflag);
		SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &glflag);
		warning("INFO: GL BLUE bits: %d", glflag);
		SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &glflag);
		warning("INFO: GL APLHA bits: %d", glflag);
		SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &glflag);
		warning("INFO: GL Z buffer depth bits: %d", glflag);
		SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &glflag);
		warning("INFO: GL Double Buffer: %d", glflag);
		SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &glflag);
		warning("INFO: GL Stencil buffer bits: %d", glflag);
	}
#endif

	_overlayWidth = screenW;
	_overlayHeight = screenH;

#ifdef USE_OPENGL
	if (_opengl) {
		uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
		rmask = 0x00001f00;
		gmask = 0x000007e0;
		bmask = 0x000000f8;
		amask = 0x00000000;
#else
		rmask = 0x0000f800;
		gmask = 0x000007e0;
		bmask = 0x0000001f;
		amask = 0x00000000;
#endif
		_overlayscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth, _overlayHeight, 16,
						rmask, gmask, bmask, amask);
	} else
#endif
	{
		_overlayscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _overlayWidth, _overlayHeight, 16,
					_screen->format->Rmask, _screen->format->Gmask, _screen->format->Bmask, _screen->format->Amask);
	}

	if (!_overlayscreen)
		error("allocating _overlayscreen failed");

	/*_overlayFormat.bytesPerPixel = _overlayscreen->format->BytesPerPixel;

// 	For some reason the values below aren't right, at least on my system
	_overlayFormat.rLoss = _overlayscreen->format->Rloss;
	_overlayFormat.gLoss = _overlayscreen->format->Gloss;
	_overlayFormat.bLoss = _overlayscreen->format->Bloss;
	_overlayFormat.aLoss = _overlayscreen->format->Aloss;

	_overlayFormat.rShift = _overlayscreen->format->Rshift;
	_overlayFormat.gShift = _overlayscreen->format->Gshift;
	_overlayFormat.bShift = _overlayscreen->format->Bshift;
	_overlayFormat.aShift = _overlayscreen->format->Ashift;*/

	_overlayFormat = Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0);

	_screenChangeCount++;

	SDL_PixelFormat *f = _screen->format;
	_screenFormat = Graphics::PixelFormat(f->BytesPerPixel, 8 - f->Rloss, 8 - f->Gloss, 8 - f->Bloss, 0,
										f->Rshift, f->Gshift, f->Bshift, f->Ashift);

	return Graphics::PixelBuffer(_screenFormat, (byte *)_screen->pixels);
}