• Advertisement
Sign in to follow this  

Vertex Declaration doesn't have corresponding usage

This topic is 2068 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 made a sphere with 'D3DXCreateSphere()', pretty simple

I try to draw the sphere with a texture on it, pretty simple
In order to draw a texture you need uv's 'TEXCOORD', a 'float2'

but when i try to draw my simple little sphere it keeps telling me TEXCOORD0 doesn't correspond with the current vertex declaration
which im pretty sure the vertex declaration for these premade meshes is

POSITION
NORMAL
TEXCOORD
COLOR


ive used TEXCOORD0 with a sphere several times and it worked

what could be causing this error, i dont know how long i've been trying to figure this out. Maybe i'm not initializing something write when i initialize D3D?

This is what my code looks like

// HLSL
struct VS_INPUT
{
float3 untransformed_pos : POSITION0;
float2 uv : TEXCOORD0;
};

// C++
ID3DXMesh *mesh;
IDirect3DTexture9 *texture;
ID3DXEffect *shader;

// Load the spere mesh in, and the texture
D3DXCreateSphere(d3dDevice,.5f,30,30,&mesh,nullptr);
D3DXCreateTextureFromFileA(d3dDevice,"sun.png",&texture);

unsigned passes(0);
shader->Begin(&passes,0);

for(unsigned i = 0;i < passes;++i)
{
shader->BeginPass(i);
shader->SetMatrix(gWorldViewProjection,&(Transform*Camera*proj));
shader->SetTexture(gTexture,texture);
shader->CommitChanges();

mesh->DrawSubset(0);

shader->EndPass();
}

shader->End();

// I don't know what's wrong
Edited by Muzzy A

Share this post


Link to post
Share on other sites
Advertisement
I'm not so sure that texture coords are included in the vertices. I just took a look at the D3D10 DXUT code and the vertices only have positions and normals.

Share this post


Link to post
Share on other sites
Maybe it's best to create your own geometry yourself? That way you can be sure of the exact format of your vertices every time.

Also what version of DirectX are you using? It's often best to specify this in the post as implementations can vary wildly between versions. For instance, I'm a DX11 guy, and I know that the vertex format should be set up in the input assembler, which you don't appear to have.

Also if you're expecting Position, Normal, TexCoord and Color, then why are you only accepting position and texcoord in your vertex shader input?

Share this post


Link to post
Share on other sites
Use of IDirect3DTexture9 in the supplied code suggests that the OP is using D3D9. Correct that D3DXCreateSphere will create a sphere without texcoords - that's documented in the SDK:
This function creates a mesh with the D3DXMESH_MANAGED creation option and D3DFVF_XYZ | D3DFVF_NORMAL flexible vertex format (FVF).[/quote]

The OP is correct that these functions are simple, but they're also quite simplistic and limited too. That's the tradeoff. If you want anything more you have to do a certain amount of setup yourself.

Share this post


Link to post
Share on other sites

Use of IDirect3DTexture9 in the supplied code suggests that the OP is using D3D9. Correct that D3DXCreateSphere will create a sphere without texcoords - that's documented in the SDK:
This function creates a mesh with the D3DXMESH_MANAGED creation option and D3DFVF_XYZ | D3DFVF_NORMAL flexible vertex format (FVF).


The OP is correct that these functions are simple, but they're also quite simplistic and limited too. That's the tradeoff. If you want anything more you have to do a certain amount of setup yourself.
[/quote]

Hadn't spotted the call to DX9, oops! You're right, OP's best bet is to craft his/her own geometry. OP: Wikipedia the formula for a sphere, it's actually fairly easy to make a vertex sphere.

Share this post


Link to post
Share on other sites
wow i could have sworn there was a texcoord in there, im a failure. lol Thanks for the help guys!

Share this post


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

  • Advertisement