Skip to content

Commit 8f034df

Browse files
committed
fix: render the padding properly, without changing the crosshair color and without creating a duplicate with an offset
1 parent 0cf91e2 commit 8f034df

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

3rdparty/mainui_cpp

cl_dll/ammo.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,23 +1442,22 @@ void CHudAmmo::DrawCrosshairSection( int _x0, int _y0, int _x1, int _y1 )
14421442
float y0 = (float)_y0;
14431443
float x1 = (float)_x1;
14441444
float y1 = (float)_y1;
1445-
int color[3] = { 0, 255, 0 };
1446-
float alpha = 255.0f;
1445+
int color[4] = { 0, 255, 0, 255 };
14471446

14481447
// float top_left[2] = { x0, y0 };
14491448
// float top_right[2] = { x1, y0 };
14501449
// float bottom_right[2] = { x1, y1 };
14511450
// float bottom_left[2] = { x0, y1 };
14521451

1453-
if ( sscanf( xhair_color->string, "%d %d %d %f", &color[0], &color[1], &color[2], &alpha ) == 4 )
1452+
if ( sscanf( xhair_color->string, "%d %d %d %d", &color[0], &color[1], &color[2], &color[3] ) == 4 )
14541453
{
14551454
color[0] = bound( 0, color[0], 255 );
14561455
color[1] = bound( 0, color[1], 255 );
14571456
color[2] = bound( 0, color[2], 255 );
1458-
alpha = bound( 0.0f, alpha, 255.0f );
1457+
color[3] = bound( 0, color[3], 255 );
14591458
}
1460-
gEngfuncs.pTriAPI->Color4ub( color[0], color[1], color[2], alpha );
1461-
gEngfuncs.pTriAPI->Brightness( alpha / 255.0f );
1459+
gEngfuncs.pTriAPI->Color4f( color[0] / 255.0f, color[1] / 255.0f, color[2] / 255.0f, color[3] / 255.0f );
1460+
// gEngfuncs.pTriAPI->Brightness( 1.0f );
14621461

14631462
DrawUtils::Draw2DQuad( x0, y0, x1, y1 );
14641463
}
@@ -1470,7 +1469,7 @@ void CHudAmmo::DrawCrosshairPadding( int _pad, int _x0, int _y0, int _x1, int _y
14701469
float y0 = (float)_y0;
14711470
float x1 = (float)_x1;
14721471
float y1 = (float)_y1;
1473-
float alpha = 255.0f;
1472+
int alpha = 255;
14741473

14751474
// float out_top_left[2] = { x0 - pad, y0 - pad };
14761475
// float out_top_right[2] = { x1 + pad, y0 - pad };
@@ -1481,15 +1480,17 @@ void CHudAmmo::DrawCrosshairPadding( int _pad, int _x0, int _y0, int _x1, int _y
14811480
// float in_bottom_right[2] = { x1, y1 };
14821481
// float in_bottom_left[2] = { x0, y1 };
14831482

1484-
if ( sscanf( xhair_color->string, "%*d %*d %*d %f", &alpha ) == 1 )
1483+
if ( sscanf( xhair_color->string, "%*d %*d %*d %d", &alpha ) == 1 )
14851484
{
1486-
alpha = bound( 0.0f, alpha, 255.0f );
1485+
alpha = bound( 0, alpha, 255 );
14871486
}
1488-
gEngfuncs.pTriAPI->Color4ub( 0, 0, 0, alpha );
1489-
gEngfuncs.pTriAPI->Brightness( alpha / 255.0f );
1487+
gEngfuncs.pTriAPI->Color4f( 0, 0, 0, alpha / 255.0f );
1488+
// gEngfuncs.pTriAPI->Brightness( 1.0f );
14901489

1491-
DrawUtils::Draw2DQuad( x0, y0, x1, y1 );
1492-
DrawUtils::Draw2DQuad( x0 + pad, y0 + pad, x1 + pad, y1 + pad );
1490+
DrawUtils::Draw2DQuad( x0 - pad, y0 - pad, x1 + pad, y0 ); // top part
1491+
DrawUtils::Draw2DQuad( x0 - pad, y1, x1 + pad, y1 + pad ); // bottom part
1492+
DrawUtils::Draw2DQuad( x0 - pad, y0, x0, y1 ); // left part
1493+
DrawUtils::Draw2DQuad( x1, y0, x1 + pad, y1 ); // right part
14931494
}
14941495

14951496
void CHudAmmo::DrawCrosshair( int weaponId )
@@ -1533,7 +1534,7 @@ void CHudAmmo::DrawCrosshair( int weaponId )
15331534
if ( xhair_additive->value )
15341535
gEngfuncs.pTriAPI->RenderMode( kRenderTransAdd );
15351536
else
1536-
gEngfuncs.pTriAPI->RenderMode( kRenderTransTexture );
1537+
gEngfuncs.pTriAPI->RenderMode( kRenderTransAlpha );
15371538

15381539
if ( xhair_dot->value )
15391540
DrawCrosshairSection( x0, y0, x1, y1 );
@@ -1546,7 +1547,7 @@ void CHudAmmo::DrawCrosshair( int weaponId )
15461547
DrawCrosshairSection( inner.right, y0, outer.right, y1 );
15471548

15481549
if ( xhair_additive->value )
1549-
gEngfuncs.pTriAPI->RenderMode( kRenderTransTexture );
1550+
gEngfuncs.pTriAPI->RenderMode( kRenderTransAlpha );
15501551

15511552
/* draw padding if wanted */
15521553
if ( xhair_pad->value )

0 commit comments

Comments
 (0)