XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

Help - I'm overlooking something

Last post 05-12-2008 8:21 AM by Fatming. 3 replies.
  • 05-10-2008 6:02 AM

    Help - I'm overlooking something

    For a school project I'm trying to draw lines on a screen, (constantly being updated), based on streaming data comming through the network.  I've got the lines drawing but the problem I'm running into is that I cannot get the lines to be drawn in any color other than black.  I'd like them to be drawn in green, cyan, yellow, etc based on the information received.

    Can anyone tell me why I can not get the lines to be a color other than black or what I'm doing wrong?  (My suspission is in the .FX file but I'm still new to DX10.)  Below is some snipets of code I have, (in C++).

    The Data Struct in the Header File:

    struct Vertex
    {
      D3DXVECTOR3 Pos;
      D3DCOLOR color;
    };

    Here is the code responsible for building the Input Layer:

      // Define the input layout
    D3D10_INPUT_ELEMENT_DESC layout[] =
    {
    { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
    D3D10_INPUT_PER_VERTEX_DATA, 0 },
    { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 0, 12,
    D3D10_INPUT_PER_VERTEX_DATA, 0 }
    };

    UINT numElements = sizeof(layout)/sizeof(layout[0]);

    // Create the input layout
    D3D10_PASS_DESC PassDesc;
    dxUtil->pTechnique->GetPassByIndex( 0 )->GetDesc( &PassDesc );
    hr = pd3dDevice->CreateInputLayout( layout,
                        numElements,
                        PassDesc.pIAInputSignature,
                        PassDesc.IAInputSignatureSize,
                        &(dxUtil->pVertexLayout) );

    And finally, here is the *.FX file I'm using.

    //-------------------------------------
    // Test Effects File
    //-------------------------------------
    cbuffer cbNeverChanges
    {
    matrix View;
    };

    cbuffer cbChangeOnResize
    {
    matrix Projection;
    };

    cbuffer cbChangesEveryFrame
    {
    matrix World;
    float4 vMeshColor;
    };

    struct VS_INPUT
    {
    float4 Pos : POSITION;
    float4 Color : COLOR;
    };

    struct PS_INPUT
    {
    float4 Pos : SV_POSITION;
    float4 Color : COLOR;
    };


    //-------------------------------------
    // Vertex Shader
    //-------------------------------------
    PS_INPUT VS( VS_INPUT input )
    {
    PS_INPUT output = (PS_INPUT)0;
    output.Pos = mul( input.Pos, World );
    output.Pos = mul( output.Pos, View );
    output.Pos = mul( output.Pos, Projection );
    output.Color = input.Color;

    return output;
    }


    //-------------------------------------
    // Pixel Shader
    //-------------------------------------
    float4 PS( PS_INPUT input) : SV_Target
    {
    return input.Color;
    }

    //-------------------------------------
    // Render
    //-------------------------------------
    technique10 Render
    {
    pass P0
    {
    SetVertexShader( CompileShader( vs_4_0, VS() ) );
    SetGeometryShader( NULL );
    SetPixelShader( CompileShader( ps_4_0, PS() ) );
    }
    }
    Hope this is enough, thanks in advance.  I've been pulling my hair out trying to get something this simple to work, so anything would be appreciated.  THanks again
  • 05-10-2008 1:00 PM In reply to

    Re: Help - I'm overlooking something

    assume the vertex is correct,u have to setup

    d3dDevice->IASetPrimitiveTopology( TYPE );

    the TYPE should be

    D3D10_PRIMITIVE_TOPOLOGY_LINELIST

    or

    D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP

    hope this can help you :)

  • 05-12-2008 2:28 AM In reply to

    Re: Help - I'm overlooking something

    Yes, I have that in there, and the vertex buffers are being initialized properly.

    Everything is drawing properly.  The only catch is that it's drawing only black lines.  I'm trying to figure out how to programatically change the line color, to say blue or red, based on the information recieved through the net.

    I can get it to draw in different colors by changing the pixel shader method in the FX file:

    //-------------------------------------
    // Pixel Shader
    //-------------------------------------
    float4 PS( PS_INPUT input) : SV_Target
    {
    return float4 (1.0, 1.0, 0.0. 1.0); // for yellow
    }
    But this still doesn't help me dynamically alter the line color based on the state the application is residing.
  • 05-12-2008 8:21 AM In reply to

    Re: Help - I'm overlooking something

    Ensure the vertex data u created, have contain Color element,
    or u can insted like below
    float4 Linecolor = {1,1,1,1};
    float4 PS( PS_INPUT input) : SV_Target
    {
    return Linecolor;
    }
    setup the color befor u render
Page 1 of 1 (4 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG