Help with my experiment with mesh

Started by
5 comments, last by budimul 21 years, 5 months ago
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.
Newbie
Advertisement
Did you add a light to the scene?

Can you show us some code so we can see your issue?



Much greatness is achieved thru perseverance and faith.
Much greatness is achieved thru perseverance and faith.
try clearing the background to another color then black...it 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 Integers..so I needed to cast it to a float so I didn''t lose the decimal points.

Hi...

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

if (FAILED(D3DXCreateMeshFVF(1, 9, 0 , D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE,
g_pD3DDevice,
g_pMesh)))
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)

then
CUSTOMVERTEX is of
struct CUSTOMVERTEX {
float x,y,z;
float nx,ny,nz;
DWORD colour;
}

CUSTOMVERTEX pVertices;
g_pMesh->LockVertexBuffer(0,(BYTE**)&pVertices));

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
D3DXComputeNormals(g_pMesh,NULL);
g_pMesh->UnlockVertexBuffer();

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

//projection
D3DXMATRIX matProj;
FLOAT fAspect = (float) (g_iWidth2/g_iHeight2);
D3DXMatrixPerspectiveFovLH(&matProj,45/fAspect,fAspect,0.1f,100.0f);
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.
Newbie
Helloo...can anybody help me?
thankss
Newbie
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);

Hi...

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

Newbie

This topic is closed to new replies.

Advertisement