void RotateGLIfNeeded(CL_Mat4f &mat)
{

	if (BaseApp::GetBaseApp()->GetManualRotationMode())
	{
		float degrees = OrientationToDegrees(GetOrientation());
		mat = mat.rotate(CL_Angle(degrees, cl_degrees), 0,0,1.0f);
	}
    
    if (g_extraScreenRotation != 0)
    {
        mat = mat.rotate(CL_Angle(-g_extraScreenRotation, cl_degrees), 0,0,1.0f);
	}

}
void RotateGLIfNeeded()
{
	if (BaseApp::GetBaseApp()->GetManualRotationMode())
	{
		float degrees = OrientationToDegrees(GetOrientation());
		glRotatef(degrees, 0.0f, 0.0f, 1.0f);

		
	}
    
    if (g_extraScreenRotation != 0)
    {
        glRotatef(-g_extraScreenRotation, 0,0,1);
    }

}
void RenderScissorComponent::FilterOnRender(VariantList *pVList)
{

	CHECK_GL_ERROR()
	g_globalBatcher.Flush();

	GLboolean b = false;
	
	//Note: This fails when using the webOS emulation libs on Windows.. but works on the real device
	glGetBooleanv(GL_SCISSOR_TEST, &b);
	
#if defined(WIN32) && defined(RT_WEBOS) && defined(_DEBUG)
	//clear the error out so it doesn't flood our log
	glGetError();
#endif
	m_bOldScissorEnabled = b != 0;
	CHECK_GL_ERROR()
	if (m_bOldScissorEnabled)
	{
		//warning: Untested code...
		GLint nums[4];
		glGetIntegerv(GL_SCISSOR_BOX, &nums[0]);
		m_oldScissorPos = CL_Vec2f((float)nums[0],(float) nums[1]);
		m_oldScissorSize = CL_Vec2f((float)nums[2],(float) nums[3]);
		CHECK_GL_ERROR()
	}

	CL_Vec2f vFinalPos = pVList->m_variant[0].GetVector2()+*m_pPos2d;
	//vFinalPos -= GetAlignmentOffset(*m_pSize2d, eAlignment(*m_pAlignment));	

	CL_Rectf clipRect(vFinalPos.x, vFinalPos.y, vFinalPos.x+m_pSize2d->x, vFinalPos.y+m_pSize2d->y);
		
	//well, turns out we need to always do this on iOS, as this accounts for the screen being rotated as well, not just
	//the scaling issue

//	if (NeedToUseFakeScreenSize())
	{
		//Oh shit-sticks. We're stretching our content and using a fake screensize.  We'll need to convert
		//our glScissor rect to match the real gl surface size.
	
		float angle = OrientationToDegrees(GetOrientation());
		while (angle < 0)
		{
			angle+= 360;
		}
		rtRectf r = rtRectf(clipRect.left, clipRect.top, clipRect.right, clipRect.bottom);
		r = ConvertFakeScreenRectToReal(r);
		clipRect = CL_Rectf(r.left, r.top, r.right, r.bottom);

		float primaryX = (float)GetPrimaryGLX();
		float primaryY = (float)GetPrimaryGLY();
		
		if (InLandscapeGUIMode())
		{
			swap(primaryX, primaryY);
		}
		
		clipRect = RotateRect(clipRect, angle, CL_Vec2f(primaryX, primaryY));
	}

	//remember, glScissors x/y is the LOWER LEFT of the rect, not upper left. (and lower left is 0,0)
	glScissor((GLint)clipRect.left, (GLint)GetPrimaryGLY()-((GLint)clipRect.top+(GLint)clipRect.get_height()), (GLint)clipRect.get_width(),(GLint) clipRect.get_height());
	glEnable(GL_SCISSOR_TEST);

}