Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problems displaying a mesh

Started by DividedByZero Jun 25, 2015 at 10:56 PM 4 replies 3.7k views
Original Post
DividedByZero
DividedByZero

Hi guys,

I have a basic DirectX 9c project, but I am having a problem displaying a simple cube mesh.

I can create a cube manually which displays correctly by using vertex buffers etc. So, I know my camera is working correctly.

But, now I am trying to load a cube with the same dimensions via an .X file.

I can load the file happily with no errors being reported and I can see (by querying the mesh interface) that it has 24 verticies and 12 triangles. But nothing is being rendered to the screen.

There are no materials assigned to this mesh, so I'd expect to see a plain white cube.

How I created it


HRESULT hr = D3DXLoadMeshFromX("cube.x", D3DXMESH_SYSTEMMEM, g_d3dDev, &g_adjBuffer, &g_materialBuffer, NULL, &g_numMaterials, &g_model);

And how I am trying to present it.


HRESULT hr=g_model->DrawSubset(0);

Any ideas as to why nothing is being displayed would be awesome :)

Thanks in advance.

Buckeye
Buckeye

Possibilities:

1. world matrix is incorrect.

2. view matrix is incorrect.

3. projection matrix is incorrect.

4. one or more viewport parameters are incorrect.

5. the mesh vertices or indices are incorrect ( winding order incorrect, triangles are degenerate ).

6. the scene viewpoint is inside the cube looking out.

7. you don't set a default texture.

If you can create your own vertex/index buffers correctly to display a cube, load those into ID3DXMesh, and get it to display that way. Then use D3DXSaveMeshToX to save the mesh to an X file. Compare that (successful) file with your unsuccessful file to determine the differences.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly. You don't forget how to play when you grow old; you grow old when you forget how to play.
Anddos
Anddos

have you added a light source ?


// this is the function that sets up the lights and materials
void init_light(void)
{
    D3DLIGHT9 light;    // create the light struct
    D3DMATERIAL9 material;    // create the material struct

    ZeroMemory(&light, sizeof(light));    // clear out the light struct for use
    light.Type = D3DLIGHT_DIRECTIONAL;    // make the light type 'directional light'
    light.Diffuse = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);    // set the light's color
    light.Direction = D3DXVECTOR3(-1.0f, -0.3f, -1.0f);

    d3ddev->SetLight(0, &light);    // send the light struct properties to light #0
    d3ddev->LightEnable(0, TRUE);    // turn on light #0

    ZeroMemory(&material, sizeof(D3DMATERIAL9));    // clear out the struct for use
    material.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);    // set diffuse color to white
    material.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);    // set ambient color to white

    d3ddev->SetMaterial(&material);    // set the globably-used material to &material
}
 
//set these after you make the device
 
d3ddev->SetRenderState(D3DRS_LIGHTING, TRUE);    // turn on the 3D lighting
d3ddev->SetRenderState(D3DRS_ZENABLE, TRUE);    // turn on the z-buffer
d3ddev->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50));    // ambient light
 
:)
TomKQT
TomKQT

There are no materials assigned to this mesh, so I'd expect to see a plain white cube.

Or a plain black cube. I hope your background color isn't black ;) That's just a tip, to be sure (maybe you're doing it, but we can never know) - during these initial attempts, never clear your backbuffer to white or black, use some general color, like a yellowish-gray etc :)

L. Spiro
L. Spiro

Or a plain black cube. I hope your background color isn't black

Ninja’d.


L. Spiro
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
Anddos
Anddos

you will still need lighting regardless if the mesh has no materials or textures

:)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.