Jump to content
  • Advertisement

Archived

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

DevLiquidKnight

Load mesh with textures?

This topic is 5332 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 recently made a landscape using 3ds max and I exported it using the panda x file exporter. After which I tried to import into C++ for my game, the code I used was basically similar to the code in the tutorial on loading a mesh in the SDK however, once I got it to load it seemed as if there was no real lighting, and I don''t belive that the loading loaded my textures to the mesh which I had specified it to do. I cannot be sure though because I did not have very good lighting I was wondering #1 how to set it up so there like a better "global" lighting for scene so I Can see somthing besides this evil yucky grey stuff and #2 how exactly the loading of a mesh with textures should work and if im really doing it right?

Share this post


Link to post
Share on other sites
Advertisement

// for loading....

if( FAILED( D3DXLoadMeshFromX( "level.x", D3DXMESH_SYSTEMMEM,
g_pd3dDevice, NULL, &pD3DXMtrlBuffer, NULL,
&g_dwNumMaterials, &g_pMesh ) ) )
{
// If model is not in current folder, try parent folder

if( FAILED( D3DXLoadMeshFromX( "..\\level.x",
D3DXMESH_SYSTEMMEM, g_pd3dDevice, NULL,
&pD3DXMtrlBuffer, NULL, &g_dwNumMaterials,
&g_pMesh ) ) )
{
MessageBox(NULL, "Could not find level.x",NULL, MB_OK);
return E_FAIL;
}
}
d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
g_pMeshMaterials = new D3DMATERIAL9[g_dwNumMaterials];
g_pMeshTextures = new LPDIRECT3DTEXTURE9[g_dwNumMaterials];

for(int i=0; i<g_dwNumMaterials; i++)
{
g_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;
g_pMeshMaterials[i].Ambient = g_pMeshMaterials[i].Diffuse;
// Create the texture.

if( FAILED( D3DXCreateTextureFromFile( g_pd3dDevice,d3dxMaterials[i].pTextureFilename, &g_pMeshTextures[i] ) ) )
{
g_dwNumTextures++;
g_pMeshTextures[i] = NULL;
pD3DXMtrlBuffer->Release();
MessageBox(NULL, "Failed to create texture from file!",d3dxMaterials[i].pTextureFilename, MB_OK);
return FALSE;
}
MessageBox(NULL, "Is loaded.",d3dxMaterials[i].pTextureFilename, MB_OK);
}
pD3DXMtrlBuffer->Release();


// for drawing

for(int i=0; i<=g_dwNumMaterials; i++)
{
g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] );
if(i<g_dwNumTextures)
{
g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] );
}
g_pMesh->DrawSubset( i );
}

Share this post


Link to post
Share on other sites
More than likely it doesn''t have anything to do with your mesh code. Not trying to be sarcastic but, have you tried to texture a regular triangle yet? I ask this because if all you get is gray, then it probably has to do with the texture stage states not being set properly.

You need something like this before you render:

m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

This sets the appropriate blending stages for using just a single texture.

Also, make sure that lighting is enabled. Since you''re trying to use materials you''ll need to set up a light (because materials only work when lighting is enabled).

neneboricua

Share this post


Link to post
Share on other sites
oh, I wasn't aware I was afraid it could of been somthing more complicated like texture maping with the coordinates or somthing, thanks for help

The problem I seem to have a main problem with was that I was loading an X file, and It had multiple textures and it seemed to only put one texture on all of the meshes contained in the x file when there were multiple textures if you get what i mean 0.o

[edited by - DevLiquidKnight on January 15, 2004 3:24:29 PM]

Share this post


Link to post
Share on other sites
Do you mean that the mesh is using multi-texture? What I mean is do you have more than one texture applied to a particular triangle? If this is the case, then the problem is not with your code, but with the .x file format. .x files do not support multiple textures on a particular face. You can have different textures for different parts of the mesh, but you cannot apply more than one texture to any given face of the mesh. If your 3D Studio Max model uses multi-texture, then I think the exporter will ignore all other textures of a given face besides the first texture you applied.

If you want to be able to apply more than one texture to a given face of your mesh, then you won''t be able to use .x files for rendering. You''ll have to export your mesh from 3D Studio Max in some other format (like .asc or something else that''s pretty easy to parse. If 3D Stuido can export as a plain txt file, then that might be your best bet. I''m not a modeler, so I don''t know the details of how 3D Studio can export things) and write your own code to load and render the mesh with these multiple textures.

My advice is to use the DriectX App Wizard and make a blank project. Then try to draw just one or two triangles directly in front of the camera. Then texture and light these two triangles so that you get to understand the steps involved in texturing things. Once you know that, applying a whole series of materials and textures to a model will just be an extension of what you''ve been doing.

neneboricua

Share this post


Link to post
Share on other sites
No no what I ment by multiple textures is that I have a scene with a a curvy surface, with a grass-like texture on it; and a sperate object that is a geosphere with a cloud like texture on it, both in one x file not connected or anything both seperate in the 3d program just one is one texture the other is another

Unless you know of a good site that will show me an example of how to implement a simple skybox/skydome type of effect using directx 9 I found one on gametutorials.com but erm, the skybox was messed up badly >.< i could see like REALLY messed up mesh type stuff im basically trying to get a basic enviorment of a game going

[edited by - DevLiquidKnight on January 15, 2004 7:45:59 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!