Jump to content
  • Advertisement

Archived

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

Roble

Making a world

This topic is 5674 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

Say I wanted to make a world (like in any RPG), and load it into DirectX, how would I go about doing this?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
you could make a world in a 3d modelling program
and then export as a .x file
then load and render it in direct3d

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
How would I make the .x file load?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Where can I get a good 3D world making program

Share this post


Link to post
Share on other sites
In the DX SDK there is built in support for .x files, Milkshape is a good program for working with models and it has a .x file exporter. In order to get it to work though, you will need to know more about directx, I suggest finding a book on it, on half.com you usually can find a good deal on used DirectX books.

Lata,
Ben

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This is what it says in the DX SDK help:

<b>Loading an X File</b>

<i>Use the following procedure to load an .x file.

Use the DirectXFileCreate function to create an IDirectXFile object.

If templates are present in the Microsoft® DirectX® file that you will load, use the IDirectXFile::RegisterTemplates method to register those templates.

Use the IDirectXFile::CreateEnumObject method to create an IDirectXFileEnumObject enumerator object.

Loop through the objects in the file. For each object, perform the following steps.

Use the IDirectXFileEnumObject::GetNextDataObject method to retrieve each IDirectXFileData object.

Use the IDirectXFileData::GetType method to retrieve the data''s type.

Load the data using the IDirectXFileData::GetData method.

If the object has optional members, retrieve the optional members by calling the IDirectXFileData::GetNextObject method.

Release the IDirectXFileData object.

Release the IDirectXFileEnumObject object.

Release the IDirectXFile object. </i>

One word "?" =P anyone have any actual CODE?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
// -------------------------------------------------------------
// mesh.h


class CMesh_X
{

protected:

IDirect3DDevice9* m_pd3dDevice;
ID3DXMesh* m_pMesh;
D3DMATERIAL9* m_pMaterials;
IDirect3DTexture9** m_pTextures;
DWORD m_dwNumMaterials;

public:

CMesh_X();
~CMesh_X() { Destroy(); }

bool Create(IDirect3DDevice9* pd3dDevice, LPCTSTR pFilename);
void Destroy();

bool Render();

};


// -------------------------------------------------------------

// -------------------------------------------------------------
// mesh.cpp


#include <d3dx9.h>
#include "mesh.h"

CMesh_X::CMesh_X()
{
m_pd3dDevice = NULL;
m_pMesh = NULL;
m_pMaterials = NULL;
m_pTextures = NULL;
m_dwNumMaterials = 0L;
}

bool CMesh_X::Create(IDirect3DDevice9* pd3dDevice, LPCTSTR pFilename)
{

m_pd3dDevice = pd3dDevice;

ID3DXBuffer* pAdjacencyBuffer = NULL;
ID3DXBuffer* pMtrlBuffer = NULL;

// Load the mesh from the specified file
if( FAILED( D3DXLoadMeshFromX(pFilename, D3DXMESH_SYSTEMMEM, pd3dDevice, &pAdjacencyBuffer, &pMtrlBuffer, NULL, &m_dwNumMaterials, &m_pMesh) ) )
return false;

// Allocate memory for the materials and textures
m_pMaterials = new D3DMATERIAL9[m_dwNumMaterials];
m_pTextures = new LPDIRECT3DTEXTURE9[m_dwNumMaterials];

// Optimize the mesh
if( FAILED( m_pMesh->OptimizeInplace(D3DXMESHOPT_COMPACT|D3DXMESHOPT_ATTRSORT|D3DXMESHOPT_VERTEXCACHE, (DWORD*)pAdjacencyBuffer->GetBufferPointer(), NULL, NULL, NULL) ) )
return false;

// Get the materials and texture names from the material buffer
D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pMtrlBuffer->GetBufferPointer();

// Copy each material and create its texture
for( DWORD i=0; i<m_dwNumMaterials; i++ )
{
// Copy the material
m_pMaterials = d3dxMaterials[i].MatD3D;
m_pTextures[i] = NULL;

// Set the ambient color for the material (D3DX does not do this)
m_pMaterials[i].Ambient = m_pMaterials[i].Diffuse;

// Create texture
if( d3dxMaterials[i].pTextureFilename != NULL && lstrlen(d3dxMaterials[i].pTextureFilename) > 0 )
D3DXCreateTextureFromFile(pd3dDevice, d3dxMaterials[i].pTextureFilename, &m_pTextures[i]);
}

// Release the adjacency buffer
if( pAdjacencyBuffer )
pAdjacencyBuffer->Release();

// Release the material buffer
if( pMtrlBuffer )
pMtrlBuffer->Release();

return true;
}

void CMesh_X::Destroy()
{
if( m_pMaterials )
{
delete[] m_pMaterials;
m_pMaterials = NULL;
}

if( m_pTextures )
{
for( DWORD i=0; i < m_dwNumMaterials; i++ )
{
if( m_pTextures[i] )
{
m_pTextures[i]->Release();
m_pTextures[i] = NULL;
}
}
delete[] m_pTextures;
m_pTextures = NULL;
}

if( m_pMesh )
{
m_pMesh->Release();
m_pMesh = NULL;
}
}

bool CMesh_X::Render()
{

// Meshes are divided into subsets, one for each material. Render them in a loop
for( DWORD i=0; i<m_dwNumMaterials; i++ )
{
// Set the material and texture for this subset
m_pd3dDevice->SetMaterial(&m_pMaterials[i]);
m_pd3dDevice->SetTexture(0, m_pTextures[i]);

// Draw the mesh subset
m_pMesh->DrawSubset(i);
}

return true;
}

Share this post


Link to post
Share on other sites
I don''t know if tha will work with my SDK (DX 8.1) because that''s for DX 9 SDK? BTW, Where would I paste the name of my .x file in that code? =)

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!