Jump to content
  • Advertisement
Sign in to follow this  

My DirectX Shader is not working!

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


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):

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));


// Create the vertex declaration

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);



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);

Share this post

Link to post
Share on other sites
D3D 9 code, try disabling lighting: D3DRS_LIGHTING. If that doesn't solve your problem use PIX

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
Sign in to follow this  

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!