Talk:Adding a Scope
Jump to navigation
Jump to search
where must i copy my scope.vmt and scope.vtf? ;administrator, Today, irgendwann, UDP
Different way to handle Screen Ratios
I got a different (and maybe better) way to handle the different screen ratios. This works by just adding black bars (assumed that your scope-image is black) on the Top and Bottom or Right and Left. The Code for this is pretty simple, just some mathematics are involved:
int wide, tall;
GetHudSize( wide, tall );
float fAspectRatio = (float)wide / (float)tall;
float fAspectRatioCRT = 4.0f / 3.0f;
if( fAspectRatio == (4.0f / 3.0f) ) //Normal CRT (4:3)
{
vgui::surface()->DrawTexturedRect( 0, 0, wide, tall );
}
else if( fAspectRatio < 1.33f ) //LCD 5:4, draw at full width with bars on top & bottom
{
int iImageHeightHalf = (int)(((float)wide / fAspectRatioCRT) / 2 );
vgui::surface()->DrawTexturedRect( 0, tall/2 - iImageHeightHalf, wide, tall/2 + iImageHeightHalf );
vgui::surface()->DrawSetColor( 0, 0, 0, 255 );
vgui::surface()->DrawFilledRect( 0, 0, wide, tall/2-iImageHeightHalf ); //Top Bar
vgui::surface()->DrawFilledRect( 0, tall/2+iImageHeightHalf, wide, tall ); //Bottom Bar
}
else //LCD 16:9 or 16:10, draw at full heigth with bars left & right
{
int iImageWidthHalf = (int)(((float)tall * fAspectRatioCRT) / 2);
vgui::surface()->DrawTexturedRect( wide/2 - iImageWidthHalf, 0, wide/2 + iImageWidthHalf, tall );
vgui::surface()->DrawSetColor(0,0,0,255);
vgui::surface()->DrawFilledRect( 0, 0, wide/2 - iImageWidthHalf, tall );//Left rectangle
vgui::surface()->DrawFilledRect( wide/2 + iImageWidthHalf, 0, wide, tall );//Right rectangle
}
This works good for me, and I think its less work to implement.
--RedPuma 14:27, 9 February 2009 (UTC)