Null problem?
Im having a little trouble with null values and such, heres my code for s simple Planet class , which is intended to assign a name and load a 3d planet.
I'm coming across the error in my Load function in Planet.cpp when it gets to
the (D3DXMATERIAL*)bufMaterials->GetBufferPointer(); i think bufmaterials is turning up null..... could anyone possibly tell me what I'm doing wrong?
====================Planet.h====================================================
#ifndef _planet
#define _planet
#include <d3dx9.h>
#include <vector>
class Planet
{
public:
std::string Name;
Planet();
Planet(char fName[], LPDIRECT3DDEVICE9* Dev);
~Planet();
void Load(char fName[], LPDIRECT3DDEVICE9* Dev);
void Render();
void Release();
void SetPosition(D3DXVECTOR3 p) {m_pos = p;}
void SetRotation(D3DXVECTOR3 r) {m_rot = r;}
void SetScale(D3DXVECTOR3 s) {m_sca = s;}
private:
D3DXVECTOR3 m_pos, m_rot, m_sca;
LPDIRECT3DDEVICE9 *m_pDevice;
LPD3DXBUFFER bufMaterials;
LPD3DXMESH mesh; // define the mesh pointer
D3DMATERIAL9* material; // define the material object
DWORD numMaterials;
LPDIRECT3DTEXTURE9* texture;
};
#endif
===============================Planet.cpp=======================================
void Planet::Load(char fName[], LPDIRECT3DDEVICE9* Dev)
{
m_pDevice = Dev;
D3DXLoadMeshFromX((LPCWSTR)fName,
D3DXMESH_SYSTEMMEM,
(*m_pDevice),
NULL,
bufMaterials,
NULL,
&numMaterials,
&mesh);
D3DXMATERIAL* tempMaterials = (D3DXMATERIAL*)bufMaterials->GetBufferPointer();
texture = new LPDIRECT3DTEXTURE9[numMaterials];
material = new D3DMATERIAL9[numMaterials];
for(DWORD i = 0; i < numMaterials; i++)
{
material = tempMaterials.MatD3D;
material.Ambient = material.Diffuse;
USES_CONVERSION;
if(FAILED(D3DXCreateTextureFromFile((*m_pDevice),
A2W(tempMaterials.pTextureFilename),
&texture)))
texture = NULL;
}
return;
}
In your LoadMeshFromX call, you need a pointer to the pointer to the materials buffer. Change "bufMaterials" to "&bufMaterials."
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement