# Thread: D3D Crosshairs example

1. ## D3D Crosshairs example

Variant 1:
```/*This down here create the function with the name "DrawXHair", so for use you'll  write: DrawXHair(pDevice, D3DCOLOR_XRGB(0, 0, 0); //for example. The  color can be as in the example but also hex (0xFFFFFFFF), and in ARGB.*/

void DrawXHair(LPDIRECT3DDEVICE9 pDevice, D3DCOLOR color)
{
D3DVIEWPORT9 viewP;    //this create a D3DVIEWPORT9 variable
pDevice->GetViewport( &viewP );    //put the values of screen resolution, viewport coords, in viewP
DWORD ScreenCenterX = viewP.Width / 2;    //Create a DWORD that represent the screen center X     // STUDY CARTESIAN AXES AND ALGEBRA
DWORD ScreenCenterY = viewP.Height / 2;    // Same as up there, but for Y

D3DRECT rect1 = {ScreenCenterX-25, ScreenCenterY, ScreenCenterX+ 25,  ScreenCenterY+1};    //Create a D3DRECT variable that contains the coord of where we are going to draw a line
D3DRECT rect2 = {ScreenCenterX, ScreenCenterY-25, ScreenCenterX+ 1,  ScreenCenterY+25};    //Same as up there

pDevice->Clear( 1, &rect1, D3DCLEAR_TARGET, color, 0,  0 );    //This function draw a line on determinated coords
pDevice->Clear( 1, &rect2, D3DCLEAR_TARGET, color, 0,  0 );    //Same as up there
}```

here another way to draw a crosshair:
```void CrossHair(LPDIRECT3DDEVICE9 pDevice, int size, int strong,  D3DCOLOR xcolor){
int iCenterX = GetSystemMetrics( 0 ) / 2;
int iCenterY = GetSystemMetrics( 1 ) / 2;
if( iCenterX < 20 && iCenterY < 20 )
{
iCenterX = ( GetSystemMetrics( 0 ) / 2 );
iCenterY = ( GetSystemMetrics( 1 ) / 2 );
}
D3DRECT rec2 = { iCenterX- size, iCenterY, iCenterX+ size, iCenterY+ strong};
D3DRECT rec3 = { iCenterX, iCenterY- size, iCenterX+ strong,iCenterY+ size};
pDevice->Clear(1, &rec2, D3DCLEAR_TARGET, xcolor, 1000,  0);
pDevice->Clear(1, &rec3, D3DCLEAR_TARGET, xcolor, 100,  0);
}```

2. ### The Following User Says Thank You to Dwar For This Useful Post:

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•