Sign in to follow this  

My DirectX Shader is not working!

This topic is 2315 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

Hi,

I have something going on with my DirectX Shader. When I replace the call (at the end of the code list) of DrawPrimitive() with DrawPrimitiveUP() it renders triangles. But not with the Shader and DrawPrimitive()

Here is the code (you can assume any variables not declared here were set up elsewhere):

[code]



Vertex vertices[] =
{
{20, 40, 1, D3DCOLOR_RGBA(0, 255, 255, 255)},
{40, 20, 1, D3DCOLOR_RGBA(255, 0, 0, 255)},
{60, 60, 1, D3DCOLOR_RGBA(0, 255, 255, 255)},
{20, 40, 1, D3DCOLOR_RGBA(0, 255, 255, 255)},
};

void * pVertices;

const char * strShader =
"vs_1_1 \n"
"dcl_position v0 \n"
"dcl_color v1 \n"
"m4x4 oPos, v0, c0 \n"
"mov oD0, v1 \n"
"";

int result;

// for test create vertex buffer
// create a pixel shader
result = mDevice->CreateVertexBuffer(
4 * sizeof(Vertex), 0, 0, D3DPOOL_DEFAULT, &mVertexBuffer, 0);

// lock the buffer to prepare for copying info into shader
mVertexBuffer->Lock(0, sizeof(vertices), (void**)&pVertices, 0);

memcpy(pVertices, vertices, sizeof(vertices));

mVertexBuffer->Unlock();

// Create the vertex declaration
D3DVERTEXELEMENT9 decl[]=
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
D3DDECL_END()
};

result = mDevice->CreateVertexDeclaration(
decl, &mVertexDeclaration);

// now we are ready to assemble the shader
result = D3DXAssembleShader(
strShader, (UINT)strlen(strShader), 0, 0, D3DXSHADER_DEBUG, &mShader, 0 );

if(result != 0)
{
Debug::PrintF("ERROR: Shader::loadString D3DXAssembleShader failed error code %d\n", result);
}

// create a vertex shader
result = mDevice->CreateVertexShader(
(DWORD*) mShader->GetBufferPointer(), &mVertexShader );

if(result != 0)
{
Debug::PrintF("ERROR: Shader::loadString CreateVertexShader failed error code %d\n", result);
}

D3DXMATRIX mMatWorld;

mDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);

D3DXMatrixIdentity( &mMatWorld );

result = mDevice->SetVertexShaderConstantF( 0, (float *)&mMatWorld, 4 );
result = mDevice->SetVertexDeclaration( mVertexDeclaration );
result = mDevice->SetVertexShader( mVertexShader );
result = mDevice->SetStreamSource(0, mVertexBuffer, 0, sizeof(Vertex));

// now we get the magic list of triangles back from the shader!
result = mDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 1);

mDevice->SetVertexShader( 0 );
mDevice->SetTexture(0, NULL);


[/code]

Share this post


Link to post
Share on other sites
To extend on Asesh's comment, I think the best thing to do is take a frame capture with PIX. Then you can see the contents of the vertex buffer before and after the vertex shader. This usually provides a good idea of why your rendered results don't show up. In the frame capture you can also inspect the contents of the device before the rendering call, which can also remind you of states that you forgot to set.

Share this post


Link to post
Share on other sites

This topic is 2315 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this