This topic is now archived and is closed to further replies.


Help with my experiment with mesh

Recommended Posts

Hi... I am just trying to learn what mesh is. However I have hit a problem which is my mesh is not rendered Basically i created it from, what I want to do is just to create a rectangle. so I did a D3DXCreateMeshFVF I specified 4 vertices and such then I call GetVertexBuffer then I lock it by calling LockVertexBuffer then I populate the vertex buffer and draw using DrawSubset However the mesh is not showing... my vertex format is D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE I had light/material turn on I just wonder why? Thank you.

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
try clearing the background to another color then might show up so you can see that it was drawn (this would help a lighting problem)

check that you set all 3 matrix values...World,View,Projection. Also make sure all the values you use to setup each matrix is correct. For example, I used the RECT to get the client area and then got the aspect ratio from it, the problem was RECT uses I needed to cast it to a float so I didn''t lose the decimal points.

Share this post

Link to post
Share on other sites

Thanks for replying...
Here are some of my codes...pardon me if the codes seemed stupid,after all I''m a newbie only

return FALSE;

I suppose this create mesh with 1 face and 9 vertices, I was hoping kind like a star with 4 sharp protruding edges. (Not sure if this is the way)

float x,y,z;
float nx,ny,nz;
DWORD colour;


then I populate using

pVertices[0].x = points
pVertices[0].y = 0.0f;
pVertices[0].z = points
pVertices[0].nx = pVertices[0].ny = pVertices[0].nz = 0;

this goes on until the 8 subscipt of the array.
Does the order of the points has to be in clockwise direction?
the plane is lying flat on x-z plane. so i would put my camera
on the positive y axis

Then i calculate the normal

//camera position is like this
D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3(0.0f, 50.0f, 0.0f),
&D3DXVECTOR3(0.0f, 0.0f, 0.0f), &D3DXVECTOR3(1.0f, 0.0f, 0.0f));
g_pD3DDevice->SetTransform(D3DTS_VIEW, &matView);

FLOAT fAspect = (float) (g_iWidth2/g_iHeight2);
g_pD3DDevice->SetTransform(D3DTS_PROJECTION, &matProj);

World is just identity matrix.

Lights is like this
it is a point light with no attenuation
so i position the light far above my camera at the y axis.
d3dlight.Position.x = 0.0f;
d3dlight.Position.y = 500.0f;
d3dlight.Position.z = 0.0f;

d3dlight.Range = 1000;
d3dlight.Attenuation0 = 1;
d3dlight.Attenuation1 = 0;
d3dlight.Attenuation2 = 0;

basically these are the way i did it.
Now i am quite confused what is the difference between vertex buffer and meshes? All seemed to me just a collections of vertices. and is it possible to create line between 2 points in a mesh that is not a straight line?

Thanks all.

Share this post

Link to post
Share on other sites
Lotta work just to draw some triangles. You might want to look into rendering just a simple triangle list using a vertex buffer.

The problem with you mesh code could be that you did not set a material before trying to render?? If you have enabled lighting at any point your mesh will not show if you have not selected a material. Disable lighting and see if anything shows up.

pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);

Share this post

Link to post
Share on other sites

Yeah i know it is a lot of work. the point is i wanna learn meshes. I''m really a curious type *sigh*

anyway it''s fixed now. After checking up similiar posting, I found out that the mesh is drawn using indices. So
I simply locked my indices buffer. populate it in clockwise order. and bam...triangle is drawn well lit...

Thank you anyway guys...
u guys made the difference in my learning

Share this post

Link to post
Share on other sites