void StelQGLRenderer::drawWindow(StelViewportEffect* const effect)
{
	// At this point, FBOs have been released (if using FBOs), so we're drawing 
	// directly to the screen. The StelViewportEffect::drawToViewport call 
	// actually draws puts the rendered result onto the viewport.
	invariant();

	//Warn about any GL errors.
	checkGLErrors("drawWindow() start");
	
	//Effects are ignored when FBO is not supported.
	//That might be changed for some GPUs, but it might not be worth the effort.
	
	viewport.prepareToDrawViewport();

	if(NULL == effect)
	{
		// If using FBO, we still need to put it on the screen.
		if(viewport.useFBO())
		{
			StelTextureNew* screenTexture = getViewportTexture();
			const QSize size = screenTexture->getDimensions();

			glDisable(GL_BLEND);
			setGlobalColor(Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
			screenTexture->bind();
			drawTexturedRect(0, 0, size.width(), size.height());
			delete screenTexture;
		}
		// If not using FBO, the result is already drawn to the screen.
	}
	else
	{
		effect->drawToViewport(this);
	}

	viewport.disablePainting();

	checkGLErrors("drawWindow() end");
	invariant();
}
void StelViewportDistorterFisheyeToSphericMirror::drawToViewport(StelRenderer* renderer) 
{
	// Screen texture might be larger than the screen 
	// if power-of-two textures are required.
	// In such cases, we need to adjust texture coordinates
	// and do that every time screen size is changed.
	StelTextureNew* screenTexture = renderer->getViewportTexture();

	const QSize viewportSize = renderer->getViewportSize();
	const QSize texSize = screenTexture->getDimensions();
	const QSizeF newMaxTexCoords(viewportSize.width() / static_cast<float>(texSize.width()),
				     viewportSize.height() / static_cast<float>(texSize.height()));
	if(maxTexCoords != newMaxTexCoords)
	{
		recalculateTexCoords(newMaxTexCoords);
	}

	screenTexture->bind();

	foreach(StelIndexBuffer* strip, stripBuffers)
	{
		renderer->drawVertexBuffer(vertexGrid, strip);
	}