Jump to content
  • Advertisement
Sign in to follow this  
shoez

Problem Drawing Line

This topic is 2517 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Everything Compiles fine but i cannot see the line on the screen :( any ideas on what im doing wrong?

Pixel Shader
All i want this to do is pass in my vertexs and color them



////////////////////////////////////////////////////////////////////////////////
// Filename: color.ps
////////////////////////////////////////////////////////////////////////////////


//////////////
// TYPEDEFS //
//////////////
struct PixelInputType
{
float4 Position : SV_POSITION;
float4 Color : COLOR;
};


////////////////////////////////////////////////////////////////////////////////
// Pixel Shader
////////////////////////////////////////////////////////////////////////////////
float4 PS_Main(PixelInputType input) : SV_TARGET
{
return input.Color;
}



Vertex Shader
All i want this to do it pass in vertices thru without performing any special things to them



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


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




// Passing 3d coordinates
// convert to projection
VS_OUTPUT VS_Main( in VS_INPUT In )
{
VS_OUTPUT Out;
Out.Pos = In.Pos;
Out.Color = In.Color;
return Out;
}




Line initialization function
void InitializeLine()
{
// Assume Function Failure
bool bFunctionStatus = false;

if (pDevice == NULL || pDeviceContext == NULL) return bFunctionStatus;
m_pDevice = pDevice;
m_pDeviceContext = pDeviceContext;

// Create Vertex Buffer
SVertex2 Vertex[] =
{
{ D3DXVECTOR3(50.0f, 50.0f, 1.0f), D3DXCOLOR(0.5f, 0.5f, 0.5f, 0.5f) },
{ D3DXVECTOR3(100.0f, 100.0f, 1.0f), D3DXCOLOR(0.5f, 0.5f, 0.5f, 0.5f) }
};

// Create Description of buffer we are wanting...in this case a vertex buffer
D3D11_BUFFER_DESC vbd;
vbd.ByteWidth = sizeof(SVertex2) * 2;
vbd.Usage = D3D11_USAGE_DEFAULT;
vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vbd.CPUAccessFlags = 0;
vbd.MiscFlags = 0;
/*vbd.StructureByteStride = ???*/

// Create Sub Resource so we can fill created buffer
D3D11_SUBRESOURCE_DATA vInitData;
vInitData.pSysMem = &Vertex;

// Create the buffer now
HRESULT hrErrorCode;
hrErrorCode = m_pDevice->CreateBuffer(&vbd, &vInitData, &m_pVertexBuffer);
if (hrErrorCode != S_OK) {
OutputDebugString(L"ErrorCreating Vertex Buffer");
return bFunctionStatus;
}
ID3DBlob* vsBuffer = NULL;
ID3DBlob* psBuffer = NULL;
__try {
// Compile Vertex Shader
bool bOk = CompileD3DShader(L"VS_Shader.fx", "VS_Main", "vs_4_0", &vsBuffer);
if( bOk == false )
{
OutputDebugString( L"Error compiling the vertex shader!" );
__leave;
}

// Create Vertex Shader with Compiled Code
HRESULT hrErrorCode;
hrErrorCode = m_pDevice->CreateVertexShader(vsBuffer->GetBufferPointer(), vsBuffer->GetBufferSize(), 0, &m_pVSShader);
if ( hrErrorCode != S_OK )
{
OutputDebugString( L"Error creating the vertex shader!" );
__leave;
}

// Describe Layout for Custom Vertex structure of each element
// Lets Describe Vertex Layout
D3D11_INPUT_ELEMENT_DESC VertexDescription[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }
};

// Create InputLayout
hrErrorCode = m_pDevice->CreateInputLayout(VertexDescription, 2,vsBuffer->GetBufferPointer(), vsBuffer->GetBufferSize(), &m_pInputLayout);
if ( hrErrorCode != S_OK )
{
OutputDebugString( L"Error Creating Input Layout!" );
__leave;
}

// Compile Pixel Shader
bOk = CompileD3DShader(L"PS_Shader.fx", "PS_Main", "ps_4_0", &psBuffer);
if ( bOk == false )
{
OutputDebugString( L"Error compiling the vertex shader!" );
__leave;
}

// Create Pixel Shader with compiled bytecode
hrErrorCode = m_pDevice->CreatePixelShader(psBuffer->GetBufferPointer(), psBuffer->GetBufferSize(), 0, &m_pPSShader);
if ( bOk == false )
{
OutputDebugString( L"Error Creating Pixel Shader!" );
__leave;
}
bFunctionStatus = true;
}

__finally {
// Free Resources to prevent leak!
if (vsBuffer)
vsBuffer->Release();

if (psBuffer)
psBuffer->Release();
}
return(bFunctionStatus);
}
}


void DrawLine()
{


// Clearing back buffer/render target here
......

UINT stride = sizeof(SVertex2);
UINT offset = 0;

// Setup pipeline
// Input Assembler
m_pDeviceContext->IASetInputLayout(m_pInputLayout);
m_pDeviceContext->IASetVertexBuffers(0, 1, &m_pVertexBuffer, &stride, &offset);
m_pDeviceContext->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINELIST);

// Vertex Shader
m_pDeviceContext->VSSetShader(m_pVSShader, NULL, NULL);

// Pixel Shader
m_pDeviceContext->PSSetShader(m_pPSShader, NULL, NULL );

// Draw
m_pDeviceContext->Draw(2,0);

// Calling Present Here
......
}

Share this post


Link to post
Share on other sites
Advertisement
[color=#000000]m_pDeviceContext[color=#666600]->[color=#660066]IASetPrimitiveTopology[color=#666600]([color=#000000]D3D10_PRIMITIVE_TOPOLOGY_LINELIST[color=#666600]);

I think you mean (change 10 to 11)

[color=#000000]m_pDeviceContext[color=#666600]->[color=#660066]IASetPrimitiveTopology[color=#666600]([color=#000000]D3D11_PRIMITIVE_TOPOLOGY_LINELIST[color=#666600]);

Share this post


Link to post
Share on other sites
Hi!

Your vertex shader just passes through your line geometry, which means your input geometry is assumed to be in post-projection space. In D3D the post-projection space in [-1..1]²x[0..1] is mapped to the viewport.

So, what happens if you put in your vertex buffer vertices in that range?
E.g.:
SVertex2 Vertex[] =
{
{ D3DXVECTOR3(-1.0f, -1.0f, 1.0f), D3DXCOLOR(0.5f, 0.5f, 0.5f, 0.5f) },
{ D3DXVECTOR3(1.0f, 1.0f, 1.0f), D3DXCOLOR(0.5f, 0.5f, 0.5f, 0.5f) }
};


That should give you a diagonal line all across the viewport.
Cheers!

Share this post


Link to post
Share on other sites
I made the above changes and i'm still getting a blank window :(





so no matter what orientation of space of vertices i pass into the vertex buffer they should come out in Projection Space?

Share this post


Link to post
Share on other sites
Hello again,

I don't see any obvious mistakes in the code you posted here.
So, I pasted most of your code into Tutorial03 of the DxSDK. I attached the source and you should recognize most of the parts. It looks fine on my end (gray line all across the screen), so if you like to compare some working code to yours, go ahead.

Oh and one thing…
Whenever you create description objects, you should invoke a ZeroMemory to initialize all their fields to zero.
D3D11_BUFFER_DESC bd;
ZeroMemory( &bd, sizeof(bd) );



so no matter what orientation of space of vertices i pass into the vertex buffer they should come out in Projection Space?

Yes, the last shader before the rasterizer always outputs the vertices in post-projection space (in your case the vertex shader).

Cheers!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!