Results 1 to 1 of 1
  1. #1
    Veteran Dwar is on a distinguished road Dwar's Avatar
    Join Date
    2010 Mar
    Thanked 2,220 Times in 286 Posts
    Rep Power

    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);
    Please, post your questions on forum, not by PM or mail

    I spend my time, so please pay a little bit of your time to keep world in equilibrium

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

Similar Threads

  1. [Snippet] D3D Crosshairs
    By Dwar in forum D3D Programming
    Replies: 6
    Last Post: 2012-07-19, 07:18 AM
Visitors found this page by searching for:

c d3d crosshair

d3d crosshair c

crosshair c d3d crosshair tutorialc crosshair tutoHow to make D3D crosshair BY C c drawing crosshairmake a D3D crosshair in C How to draw D3D crosshair C =D3d crosshairsdrawline(pdevice screencenterx screencenteryc crosshair tutoriald3d crosshair tutoriaklC Crosshairsc crosshair d3dhow to make crosshair c C d3d crosshair viewporthow to add crosshair c CrossHair C D3Dvoid crosshairvoid Crosshair(LPDIRECT3DDEVICE9 pDevice)crosshair d3dvc crosshairc crosshair in gamemaking crosshair in c


Posting Permissions

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