Sign in to follow this  
Bertil

DirectX FVF problems

Recommended Posts

I've recently started to program 3D with DirectX 9 and I've encountered a problem. I haven't really found anything fruitfull on google that has helped me. I have my own vertex declaration consisting of a position, a normal and texture coordinates. I made my own HLSL shader that is rendering my geometry and puts a texture on them. This all worked fine, but the problem came up when I wanted to use my own shader with my vertex declaration on the DirectX generated meshes like the teapot for example. I wanted to use these since I don't have any 3D modelling program and I'd like to learn how to use the D3DXMESH'es. I wanted to use these default models to try my lightning shader I made. So, enough beating around the bush... My problem is that I don't know how I can use my own vertex declaration on these DX generated models, because I need the normals and the texture coordinates for the shader (which has matching input data from my own declaration). How can I access the DX generated vertices with normals, texture coordinates and such? I've been looking at the CloneMesh() and UpdateSemantics() functions but hasn't really figured how they really work and how I can use them to solve my problem. Can anyone tell me how I can do this? or at least point me in the right direction where I can see an example of how one can handle this Flexible vertex format because I haven't really understood it. Here is my vertex declaration: struct TextureVertex { TextureVertex():Position(0.0f, 0.0f, 0.0f){} TextureVertex(float x, float y, float z):Position(x,y,z){} TextureVertex(const D3DXVECTOR3& v):Position(v){} D3DXVECTOR3 Position; D3DXVECTOR3 Normal; D3DXVECTOR2 TextureCoordinates; static IDirect3DVertexDeclaration9 *p_VertexDeclaration; }; D3DVERTEXELEMENT9 TextureVertexComponents[] = { {0,0,D3DDECLTYPE_FLOAT3,D3DDECLMETHOD_DEFAULT,D3DDECLUSAGE_POSITION,0}, {0,sizeof(D3DXVECTOR3),D3DDECLTYPE_FLOAT3,D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL,0}, {0,2*sizeof(D3DXVECTOR3),D3DDECLTYPE_FLOAT2,D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,0}, D3DDECL_END() }; and I created the teapot for example with this call: D3DXCreateTeapot(p_Device,&p_Model,0); and render it with: p_Model->DrawSubset(0); If I've been unclear with something let me know and I can try to be more specific. Oh and btw. I am sure that the shader and the rest of the code works because I have manualy created quads, and a 50 x 50 vertices big grid that I texture and that worked nice and looks good. Thank you for reading all of it. :)

Share this post


Link to post
Share on other sites
Off the top of my head the D3DX shape functions create geometry with D3DFVF_XYZ and D3DFVF_NORMAL - they don't have any texture coordinates.

The way I've done it is to use ::CloneMesh{FVF}() and then stepped through the data filling in any missing information (such as texture coordinates).

Generating texture coordinates for the meshes tends to be non-trivial. The UV Atlas libraries can help out though, but it's far from being perfect 100% of the time!

hth
Jack

Share this post


Link to post
Share on other sites
The mesh has a matching declaration to its vertices, so your shader will get the available data (position, normal) correctly. You don't have to change to your own declaration for that.

As Jack said, the generated meshes don't contain texture coordinates, and changing the mesh to a format which has texture coordinates will not magically generate values for them.

Share this post


Link to post
Share on other sites
Ah thank you. :) I will attempt to find some way to calculate texturecoordinates for the meshes. Good think that they have the normals already though, that means I can perhaps get some lightning to the scene. And regarding the texture coordinates I will start to try get it work for the D3DXCreateBox() since that should be easiest. If I get that one working then at least I have solved the FVF problem I have.

Thank you again for your help!

Share this post


Link to post
Share on other sites

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