Esempio n. 1
6
void TerrainRenderable::LoadTexture()
{
	auto device = Globals::GetDevice()->GetDeviceD3D9();
	HRESULT v=S_OK;
	v += D3DXCreateTextureFromFileA(device, "../media/terrain/texture_0.jpg", &m_pTextrue[0]);
	v += D3DXCreateTextureFromFileA(device, "../media/terrain/texture_1.jpg", &m_pTextrue[1]);
	v += D3DXCreateTextureFromFileA(device, "../media/terrain/normal.tga", &m_pTextrue[2]);

}
Esempio n. 2
0
void Texture::loadTextures(void)
{
	D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
	g_pMeshTextures = new LPDIRECT3DTEXTURE9[g_dwNumMaterials];
	if(g_pMeshTextures == NULL)
	{
		throw (TEXT("Out of Memory! Could not create Texture."));
		return;
	}
	for(DWORD i = 0; i < g_dwNumMaterials; i++)
	{
		g_pMeshTextures[i] = NULL;
		if(d3dxMaterials[i].pTextureFilename != NULL &&
			lstrlenA(d3dxMaterials[i].pTextureFilename) > 0)
		{
			// Build the texture.
			if(FAILED(D3DXCreateTextureFromFileA(g_pd3dDevice, d3dxMaterials[i].pTextureFilename,
				&g_pMeshTextures[i])))
			{
				throw (TEXT("Could not find texture map."));
				return;
			} else
				d3dxMaterials[i].pTextureFilename = "textures";
			if(FAILED(D3DXCreateTextureFromFileA(g_pd3dDevice, d3dxMaterials[i].pTextureFilename,
				&g_pMeshTextures[i])))
			{
				throw (TEXT("Could not find texture in specified folder:")); 
				std::cout << d3dxMaterials[i].pTextureFilename;
				return;
			}
		}
	}
};
Esempio n. 3
0
void AssetLoader::loadTexture(LPCSTR path)
{
	IDirect3DTexture9 * tempTex;

	int rc = D3DXCreateTextureFromFileA(d3dDev, path, &tempTex);
	if (rc != D3D_OK)
		D3DXCreateTextureFromFileA(d3dDev, "Assets\\Error.png", &tempTex);
	
	Texture * tempTexture = new Texture();
	tempTexture->name = path;
	tempTexture->texture = tempTex;
	ptextures->push_back(tempTexture);
}
Esempio n. 4
0
IDirect3DTexture9* Resources::LoadTexture(IDirect3DDevice9* dev, string textureFilename)
{
	if (loadedTextures.count(textureFilename) == 0) {
		IDirect3DTexture9* texture;
		if (FAILED(D3DXCreateTextureFromFileA(dev, (imagePath + textureFilename).c_str(), &texture))) {
			if (FAILED(D3DXCreateTextureFromFileA(dev, (dataPath + textureFilename).c_str(), &texture))) {
				MessageBoxA(NULL, ("Could not find texture " + textureFilename).c_str() , "COLLADA", MB_OK);
				exit(1);
			}
		}
		loadedTextures[textureFilename] = texture;
	}
	return loadedTextures[textureFilename];
}
Esempio n. 5
0
Mesh::Mesh(char *catalog, char *filename)
{
	char filepath[222];
	LPD3DXBUFFER pMtrlBuffer = NULL;
	pAdjBuffer = 0;
	strcpy(filepath, catalog);
	strcat(filepath, filename);
	if (FAILED(D3DXLoadMeshFromX(filepath, D3DXMESH_MANAGED, gdevice,
		&pAdjBuffer, &pMtrlBuffer, NULL, &Mtnum, &m_pmesh))) {
		MessageBox(0, "load mesh fail ", 0, 0);
		return;
	}

	//二,读取材质和纹理数据  
	D3DXMATERIAL*pMtrls = (D3DXMATERIAL*)pMtrlBuffer->GetBufferPointer(); //创建一个D3DXMATERIAL结构体用于读取材质和纹理信息  
	pMaterial = new D3DMATERIAL9[Mtnum];
	pTexture = new LPDIRECT3DTEXTURE9[Mtnum];

	for (DWORD i = 0; i<Mtnum; i++) {
		//获取材质,并设置环境光的颜色值  
		pMaterial[i] = pMtrls[i].MatD3D;
		pMaterial[i].Ambient = pMaterial[i].Diffuse;
		strcpy(filepath, catalog);
		strcat(filepath, pMtrls[i].pTextureFilename);
		if(FAILED(D3DXCreateTextureFromFileA(gdevice, filepath, &pTexture[i]))) 
			MessageBox(0, "load mesh texture fail ", 0, 0);
	}

	LoadData();			// load vertex and face 

	RELEASE(pMtrlBuffer);
}
Esempio n. 6
0
void GEMesh::loadFromMemory(void* Data, unsigned int SizeOfData)
{
    LPD3DXBUFFER pD3DXMtrlBuffer;
    D3DXMATERIAL* d3dxMaterials;

    // load mesh
    D3DXLoadMeshFromXInMemory(Data, SizeOfData, D3DXMESH_SYSTEMMEM, d3ddev, NULL, &pD3DXMtrlBuffer, NULL, 
                              &iNumMaterials, &mMesh);
    
    // load materials and textures
    d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
    mMaterials = new D3DMATERIAL9[iNumMaterials];
    mTextures = new LPDIRECT3DTEXTURE9[iNumMaterials];

    for(DWORD i = 0; i < iNumMaterials; i++)
    {
        mMaterials[i] = d3dxMaterials[i].MatD3D;
        mMaterials[i].Ambient = mMaterials[i].Diffuse;
        mMaterials[i].Specular = mMaterials[i].Diffuse;
        mTextures[i] = NULL;

        if(d3dxMaterials[i].pTextureFilename != NULL && lstrlenA(d3dxMaterials[i].pTextureFilename) > 0)
            D3DXCreateTextureFromFileA(d3ddev, d3dxMaterials[i].pTextureFilename, &mTextures[i]);
    }

    pD3DXMtrlBuffer->Release();
}
Esempio n. 7
0
void Meshes::load_meshes(LPCSTR pFilename, LPDIRECT3DDEVICE9 pD3DDevice)
{
	ID3DXBuffer* buff_Material = NULL;
	ID3DXBuffer* buff_Adjacency = NULL;

	D3DXLoadMeshFromX(pFilename, D3DXMESH_MANAGED, pD3DDevice, &buff_Adjacency, &buff_Material, NULL, &numMaterials, &Model); 

	
	D3DXMATERIAL* tempMaterials = (D3DXMATERIAL*)buff_Material->GetBufferPointer();


	material = new D3DMATERIAL9[numMaterials];
	texture = new LPDIRECT3DTEXTURE9[numMaterials];

	for(DWORD i = 0; i < numMaterials; i++) 
	{
		material[i] = tempMaterials[i].MatD3D; 
		material[i].Ambient = material[i].Diffuse; 

		if(FAILED(D3DXCreateTextureFromFileA(pD3DDevice,tempMaterials[i].pTextureFilename,&texture[i])))
			texture[i] = NULL; 
	}
	

	return;
}
Esempio n. 8
0
//-----------------------------------------------------------------------------
// Name: Init()
// Desc: 
//-----------------------------------------------------------------------------
HRESULT CParticleSystem::Init( LPDIRECT3DDEVICE9 pd3dDevice )
{
    HRESULT hr;

    // Initialize the particle system
    if( FAILED( hr = RestoreDeviceObjects( pd3dDevice ) ) )
        return hr;

    // Get max point size
    D3DCAPS9 d3dCaps;
    pd3dDevice->GetDeviceCaps( &d3dCaps );
    m_fMaxPointSize = d3dCaps.MaxPointSize;

    // Check and see if we can change the size of point sprites 
    // in hardware by sending D3DFVF_PSIZE with the FVF.

    if( d3dCaps.FVFCaps & D3DFVFCAPS_PSIZE )
        m_bDeviceSupportsPSIZE = true;
    else
        m_bDeviceSupportsPSIZE = false;

    // Load Texture Map for particles
	LPCSTR str = (LPCSTR)m_chTexFile;
    if( FAILED( D3DXCreateTextureFromFileA( pd3dDevice, str, &m_ptexParticle ) ) )
        return E_FAIL;

    return S_OK;
}
Esempio n. 9
0
BOOL DMeshRender::CreateMeshFromFileX(LPCWSTR pFileName, DWORD options)
{

	LPD3DXBUFFER ppAdjacency;
	LPD3DXBUFFER ppMaterials;
	LPD3DXBUFFER ppEffectInstances;
	DWORD NumMaterials;

	if (FAILED(D3DXLoadMeshFromX(pFileName, options, DDEInitialize::gRootDevice, 
		&ppAdjacency, &ppMaterials, &ppEffectInstances, &NumMaterials, &m_pMess)))
		return FALSE;

	D3DXMATERIAL *pMtrls = (D3DXMATERIAL*)ppMaterials->GetBufferPointer();
	LPDIRECT3DTEXTURE9 tmpTexture = nullptr;
	for (DWORD matRenderIndex = 0; matRenderIndex < NumMaterials; matRenderIndex++)
	{
		if (!FAILED(D3DXCreateTextureFromFileA(DDEInitialize::gRootDevice, pMtrls[matRenderIndex].pTextureFilename, &tmpTexture)))
		{
			DMaterialRender* matRender = new DMaterialRender(m_gameObj, 0, pMtrls[matRenderIndex].MatD3D, tmpTexture);
			m_matRenders.push_back(matRender);
		}
	}
	m_isEnabled = TRUE;
	return TRUE;
}
Esempio n. 10
0
void TerrainRenderablePlane::LoadTexture()
{
	auto device = Globals::GetDevice()->GetDeviceD3D9();
	HRESULT v = D3DXCreateTextureFromFileA(device, "../media/grid.dds", &m_pTextrue[0]);

	
}
Esempio n. 11
0
bool ObjectInit(HWND hwnd)
{
	srand(unsigned(time(nullptr)));
	PlaySound(_T("コミネリサ - Resuscitated Hope.wav"), nullptr, SND_ASYNC | SND_FILENAME | SND_LOOP);
	D3DXCreateFont(gPD3DDevice, 30, 0, 0, 0, 0, 0, 0, 0, 0, _T("微软雅黑"), &gPTextAdapterFont);
	D3DXCreateFont(gPD3DDevice, 20, 0, 0, 0, 0, 0, 0, 0, 0, _T("华文中宋"), &gPTextHelperFont);
	D3DXCreateFont(gPD3DDevice, 30, 0, 0, 0, 0, 0, 0, 0, 0, _T("黑体"), &gPTextInfoFont);
	D3DXCreateFont(gPD3DDevice, 36, 0, 0, 0, 0, 0, 0, 0, 0, _T("楷体"), &gPTextFPSFont);

	//////////////////////////////////////////////////////////////////////////
	// Load mesh and materials here  
	//////////////////////////////////////////////////////////////////////////
	LPD3DXBUFFER pAdjBuffer;
	LPD3DXBUFFER pMtrlBuffer;
	D3DXLoadMeshFromX(_T("loli.X"), D3DXMESH_MANAGED, gPD3DDevice, &pAdjBuffer, &pMtrlBuffer, nullptr, &gDwNumMtrl, &gPCharacter);
	D3DXMATERIAL* pMaterial = (D3DXMATERIAL*)(pMtrlBuffer->GetBufferPointer());
	gPMaterial = new D3DMATERIAL9[gDwNumMtrl];
	gPTexture = new LPDIRECT3DTEXTURE9[gDwNumMtrl];
	for (DWORD i = 0; i < gDwNumMtrl; i++)
	{
		gPMaterial[i] = pMaterial->MatD3D;
		gPMaterial[i].Ambient = gPMaterial[i].Diffuse;
		gPTexture[i] = nullptr;
		D3DXCreateTextureFromFileA(gPD3DDevice, pMaterial[i].pTextureFilename, &gPTexture[i]);
	}

	pAdjBuffer->Release();
	SAFE_RELEASE(pMtrlBuffer);
	// 设置渲染状态
	gPD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);   //开启背面消隐
	gPD3DDevice->SetRenderState(D3DRS_AMBIENT, D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f)); //设置环境光

	return true;
}
Esempio n. 12
0
void GameObject::InitMesh(LPDIRECT3DDEVICE9& d3dDevice)
{
	LPD3DXBUFFER pD3DXMtrlBuffer = nullptr;
	if ( d3dDevice )

	D3DXLoadMeshFromX( L"spaceMan.x", D3DXMESH_SYSTEMMEM,
		d3dDevice, NULL,
		&pD3DXMtrlBuffer, NULL, &m_NumMaterial,
		&m_pMesh );

	D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();

	// skip error handling -.-;;
	m_pMeshMaterials = new D3DMATERIAL9[m_NumMaterial];
	m_pMeshTextures = new LPDIRECT3DTEXTURE9[m_NumMaterial];

	for ( DWORD i = 0; i < m_NumMaterial; ++i )
	{
		m_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;

		m_pMeshMaterials[i].Ambient = m_pMeshMaterials[i].Diffuse;

		m_pMeshTextures[i] = NULL;
		
		D3DXCreateTextureFromFileA( d3dDevice,
			d3dxMaterials[i].pTextureFilename,
			&m_pMeshTextures[i] );
	}

	pD3DXMtrlBuffer->Release();
}
Esempio n. 13
0
void GEMesh::loadFromFile(const char* Filename, const char* TexturesPath)
{
    LPD3DXBUFFER pD3DXMtrlBuffer;
    D3DXMATERIAL* d3dxMaterials;
    char sTextureFilename[256];

    // load mesh
    D3DXLoadMeshFromXA(Filename, D3DXMESH_SYSTEMMEM, d3ddev, NULL, &pD3DXMtrlBuffer, NULL, &iNumMaterials, &mMesh);

    // load materials and textures
    d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
    mMaterials = new D3DMATERIAL9[iNumMaterials];
    mTextures = new LPDIRECT3DTEXTURE9[iNumMaterials];

    for(DWORD i = 0; i < iNumMaterials; i++)
    {
        mMaterials[i] = d3dxMaterials[i].MatD3D;
        mMaterials[i].Ambient = mMaterials[i].Diffuse;
        mMaterials[i].Specular.a = 0.5f;
        mMaterials[i].Specular.r = 0.5f;
        mMaterials[i].Specular.g = 0.5f;
        mMaterials[i].Specular.b = 0.5f;
        mTextures[i] = NULL;

        if(d3dxMaterials[i].pTextureFilename != NULL && lstrlenA(d3dxMaterials[i].pTextureFilename) > 0)
        {
            sprintf(sTextureFilename, "%s%s", TexturesPath, d3dxMaterials[i].pTextureFilename);
            D3DXCreateTextureFromFileA(d3ddev, sTextureFilename, &mTextures[i]);
        }
    }

    pD3DXMtrlBuffer->Release();
}
Esempio n. 14
0
int _stdcall LoadShader(const char* path) {
	if ((GraphicsMode < 4) || (strstr(path, "..")) || (strstr(path, ":"))) return -1;
	char buf[MAX_PATH];
	sprintf(buf, "%s\\shaders\\%s", *(char**)_patches, path);
	for(DWORD d=0;d<shaders.size();d++) {
		if(!shaders[d].Effect) {
			if(FAILED(D3DXCreateEffectFromFile(d3d9Device, buf, 0, 0, 0, 0, &shaders[d].Effect, 0))) return -1;
			else return d;
		}
	}
	sShader shader=sShader();
	if(FAILED(D3DXCreateEffectFromFile(d3d9Device, buf, 0, 0, 0, 0, &shader.Effect, 0))) return -1;

	shader.Effect->SetFloatArray("rcpres", rcpres, 2);

	for(int i=1;i<128;i++) {
		const char* name;
		IDirect3DTexture9* tex;

		sprintf_s(buf, "texname%d", i);
		if(FAILED(shader.Effect->GetString(buf, &name))) break;
		sprintf_s(buf, "%s\\art\\stex\\%s", *(char**)_patches, name);
		if(FAILED(D3DXCreateTextureFromFileA(d3d9Device,buf,&tex))) continue;
		sprintf_s(buf, "tex%d", i);
		shader.Effect->SetTexture(buf, tex);
		shaderTextures.push_back(tex);
	}
	
	shader.ehTicks=shader.Effect->GetParameterByName(0, "tickcount");
	shaders.push_back(shader);
	return shaders.size()-1;
}
HRESULT KWSkyBox::LoadSkyBox( LPCSTR szTextureNames[], float fSize )
{
	ReleaseSkyBox();
	for (int i = 0; i < 5; i++)
	{
		HRESULT hr = D3DXCreateTextureFromFileA(m_pDevice, szTextureNames[i], &m_pTextures[i]);
		if (FAILED(hr))
			return S_FALSE;
	}

	m_pDevice->CreateVertexBuffer(
		sizeof(KWVertex) * 20, 
		D3DUSAGE_WRITEONLY, 
		KWVertex::FVF, 
		D3DPOOL_DEFAULT, 
		&m_pVertexBuffer, 
		NULL);

	float fHalfSize = fSize * 0.5f;
	m_fSize = fSize;

	KWVertex* vertices;
	m_pVertexBuffer->Lock(0, 0, (void**)&vertices, 0);

	//font
	vertices[0] = KWVertex(-fHalfSize, fHalfSize, fHalfSize, 0.0f, 0.0f);
	vertices[1] = KWVertex(fHalfSize, fHalfSize, fHalfSize, 1.0f, 0.0f);
	vertices[2] = KWVertex(fHalfSize, -fHalfSize, fHalfSize, 1.0f, 1.0f);
	vertices[3] = KWVertex(-fHalfSize, -fHalfSize, fHalfSize, 0.0f, 1.0f);

	//back
	vertices[4] = KWVertex(fHalfSize, fHalfSize, -fHalfSize, 0.0f, 0.0f);
	vertices[5] = KWVertex(-fHalfSize, fHalfSize, -fHalfSize, 1.0f, 0.0f);
	vertices[6] = KWVertex(-fHalfSize, -fHalfSize, -fHalfSize, 1.0f, 1.0f);
	vertices[7] = KWVertex(fHalfSize, -fHalfSize, -fHalfSize, 0.0f, 1.0f);

	//left
	vertices[8] = KWVertex(-fHalfSize, fHalfSize, -fHalfSize, 0.0f, 0.0f);
	vertices[9] = KWVertex(-fHalfSize, fHalfSize, fHalfSize, 1.0f, 0.0f);
	vertices[10] = KWVertex(-fHalfSize, -fHalfSize, fHalfSize, 1.0f, 1.0f);
	vertices[11] = KWVertex(-fHalfSize, -fHalfSize, -fHalfSize, 0.0f, 1.0f);

	//right
	vertices[12] = KWVertex(fHalfSize, fHalfSize, fHalfSize, 0.0f, 0.0f);
	vertices[13] = KWVertex(fHalfSize, fHalfSize, -fHalfSize, 1.0f, 0.0f);
	vertices[14] = KWVertex(fHalfSize, -fHalfSize, -fHalfSize, 1.0f, 1.0f);
	vertices[15] = KWVertex(fHalfSize, -fHalfSize, fHalfSize, 0.0f, 1.0f);

	//up
	vertices[16] = KWVertex(fHalfSize, fHalfSize, -fHalfSize, 1.0f, 0.0f);
	vertices[17] = KWVertex(fHalfSize, fHalfSize, fHalfSize, 1.0f, 1.0f);
	vertices[18] = KWVertex(-fHalfSize, fHalfSize, fHalfSize, 0.0f, 1.0f);
	vertices[19] = KWVertex(-fHalfSize, fHalfSize, -fHalfSize, 0.0f, 0.0f);

	m_pVertexBuffer->Unlock();


	return S_OK;
}
Esempio n. 16
0
void TerrainBorderRenderable::LoadTexture()
{
	auto device = Globals::GetDevice()->GetDeviceD3D9();
	IDirect3DTexture9* ptex = 0;
	HRESULT v = D3DXCreateTextureFromFileA(device, "../media/mesh2.tga", &ptex);
	m_pTextrue.reset(ptex, [&](IDirect3DTexture9* p){p->Release(); });

}
Esempio n. 17
0
//初期化。
void Model::Init(LPDIRECT3DDEVICE9 pd3dDevice, const char* fileName)
{
	Release();
	//Xファイルをロード。
	LPD3DXBUFFER pD3DXMtrlBuffer;
	//Xファイルのロード。
	D3DXLoadMeshFromX(fileName, D3DXMESH_SYSTEMMEM,
		pd3dDevice, NULL,
		&pD3DXMtrlBuffer, NULL, &numMaterial,
		&mesh);
	//法線が存在するか調べる。
	if ((mesh->GetFVF() & D3DFVF_NORMAL) == 0) {
		//法線がないので作成する。
		ID3DXMesh* pTempMesh = NULL;

		mesh->CloneMeshFVF(mesh->GetOptions(),
			mesh->GetFVF() | D3DFVF_NORMAL, g_pd3dDevice, &pTempMesh);

		D3DXComputeNormals(pTempMesh, NULL);
		mesh->Release();
		mesh = pTempMesh;

	}

	// マテリアルバッファを取得。
	D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();

	//テクスチャをロード。
	textures = new LPDIRECT3DTEXTURE9[numMaterial];
	for (DWORD i = 0; i < numMaterial; i++)
	{
		textures[i] = NULL;
		//テクスチャを作成する。
		D3DXCreateTextureFromFileA(pd3dDevice,
			d3dxMaterials[i].pTextureFilename,
			&textures[i]);
	}
	// マテリアルバッファを解放。
	pD3DXMtrlBuffer->Release();

	//シェーダーをコンパイル。
	LPD3DXBUFFER  compileErrorBuffer = NULL;
	//シェーダーをコンパイル。
	HRESULT hr = D3DXCreateEffectFromFile(
		pd3dDevice,
		"basic.fx",
		NULL,
		NULL,
		D3DXSHADER_SKIPVALIDATION,
		NULL,
		&effect,
		&compileErrorBuffer
		);
	if (hr != S_OK) {
		MessageBox(NULL, (char*)(compileErrorBuffer->GetBufferPointer()), "error", MB_OK);
		std::abort();
	}
}
Esempio n. 18
0
void START::init_text(wchar_t **name_text,int num_start,int num_prompt)
{
	_num_start = num_start;			//记录字符串数量
	_num_prompt = num_prompt;

	D3DXMatrixScaling(&_scale_text,_scale_text_date / 4,_scale_text_date,_scale_text_date);
	D3DXMatrixRotationAxis(&_rotation_text,&D3DXVECTOR3(0,1,0),_angle_text);

	HDC hdc = CreateCompatibleDC( 0 );		//创建设备环境,hdc为windows设置环境的句柄
    HFONT hFont;
    HFONT hFontOld;

    LOGFONT lf;
	ZeroMemory(&lf, sizeof(LOGFONT));		//描述字体信息
	lf.lfHeight         = 200;				//
	lf.lfWidth          = 200;				//
	lf.lfEscapement     = 0;        
	lf.lfOrientation    = 0;     
	lf.lfWeight         = 1000;				// boldness, range 0(light) - 1000(bold)
	lf.lfItalic         = false;				//斜体
	lf.lfUnderline      = false;				//下划线
	lf.lfStrikeOut      = false;    
	lf.lfCharSet        = DEFAULT_CHARSET;
	lf.lfOutPrecision   = 0;              
	lf.lfClipPrecision  = 0;          
	lf.lfQuality        = 0;           
	lf.lfPitchAndFamily = 0;    
	
	wcscpy(lf.lfFaceName,L"宋体");	//字体

	//创建字体
    hFont = CreateFontIndirect(&lf);
    hFontOld = (HFONT)SelectObject(hdc, hFont); //将字体选入设备环境,并记录原字体

	//创建字体网格
	_text_start = new TEXT_STRUCT[num_start];
	_text_prompt = new TEXT_STRUCT[num_prompt];
	for(int i = 0;i < num_start + num_prompt;i++)
	{
		if(i < num_start)
		{
			create_text(&_text_start[i],name_text[i],hdc,i);							//创建开始游戏网格以及包装球
		}
		else 
		{	//i对应着名称的后半部分
			create_text(&_text_prompt[i - num_start],name_text[i],hdc,i - num_start);	//创建提示字体网格以及包装球		
		}
	}

    SelectObject(hdc, hFontOld);			//选入原字体
    DeleteObject( hFont );					//释放字体资源
    DeleteDC( hdc );						//释放设备环境

	D3DXCreateTextureFromFileA(_device,
				"陆雪琪(修改).jpg",			//从pMtrBuffer得到起始地址
				&_textures);				//存储纹理
}
Esempio n. 19
0
shap* InitShap(string smodpath)
{
	shap *pShap=new shap;
	

	LPD3DXBUFFER pD3DXMtrlBuffer;
	wstring s=s2ws(smodpath);
    // 装载.x文件,初始化shap的mesh和dwNumMaterials
	if( FAILED( D3DXLoadMeshFromX( s.c_str(), D3DXMESH_SYSTEMMEM,
                                   g_pd3dDevice, NULL,
								   &pD3DXMtrlBuffer, NULL, &pShap->dwNumMaterials,
								   &pShap->mesh ) ) )
    {        
            return NULL;
     
    }



    // 取出materials和textures
    D3DXMATERIAL* d3dxMaterials = ( D3DXMATERIAL* )pD3DXMtrlBuffer->GetBufferPointer();
	pShap->pMeshMaterials = new D3DMATERIAL9[pShap->dwNumMaterials];
    if( pShap->pMeshMaterials == NULL )
        return NULL;
	pShap->pMeshTextures = new LPDIRECT3DTEXTURE9[pShap->dwNumMaterials];
    if( pShap->pMeshTextures == NULL )
        return NULL;

    for( DWORD i = 0; i < pShap->dwNumMaterials; i++ )
    {
        // Copy the material
        pShap->pMeshMaterials[i] = d3dxMaterials[i].MatD3D;

        // Set the ambient color for the material (D3DX does not do this)
        pShap->pMeshMaterials[i].Ambient = pShap->pMeshMaterials[i].Diffuse;
		///////////////////////////////////////////////////////////////////////////////////
        pShap->pMeshTextures[i] = NULL;
        if( d3dxMaterials[i].pTextureFilename != NULL &&
            lstrlenA( d3dxMaterials[i].pTextureFilename ) > 0 )
        {
            // Create the texture
            if( FAILED( D3DXCreateTextureFromFileA( g_pd3dDevice,
                                                    d3dxMaterials[i].pTextureFilename,
                                                    &pShap->pMeshTextures[i] ) ) )
            {
                ;
            }
        }
    }

    // Done with the material buffer
    pD3DXMtrlBuffer->Release();

    return pShap;
	
}
Esempio n. 20
0
bool Mesh::LoadTexture(const char* name)
{
	if (FAILED(D3DXCreateTextureFromFileA(GetGlobalDevice(),name,&pTex)))
	{
		DXWriteConsol(CC_RED,"Error!");
		PopupError("Mesh::Mesh");
		return false;
	}
	return true;
}
Esempio n. 21
0
TextureResource::TextureResource(std::string path, LPDIRECT3DDEVICE9 g_pd3dDevice)
{
	if (FAILED(D3DXCreateTextureFromFileA(g_pd3dDevice, path.c_str(), &texture)))
	{
		std::string lol = std::string(path);
		Logger::getInstance().log(WARNING, "Could not find texture: " + lol);
		isLoaded = false;
		return;
	}
	isLoaded = true;
};
Esempio n. 22
0
bool NavigationLine::CreateDeviceObjects()
{
	if (!m_visible)
		return true;

	ID3DXBuffer* errors = 0;
	HRESULT hr;

	hr = D3DXCreateTextureFromFileA(g_pDevice, m_textureFile.c_str(), &m_lineTexture);
	if (FAILED(hr))
	{
		DebugSpewAlways("Failed to load texture!");

		InvalidateDeviceObjects();
		return false;
	}

	hr = D3DXCreateEffectFromFileA(g_pDevice, m_shaderFile.c_str(),
		NULL, NULL, 0, NULL, &m_effect, &errors);
	if (FAILED(hr))
	{
		if (errors)
		{
			DebugSpewAlways("Effect error: %s", errors->GetBufferPointer());

			errors->Release();
			errors = nullptr;
		}

		InvalidateDeviceObjects();
		return false;
	}

	D3DVERTEXELEMENT9 vertexElements[] =
	{
		{ 0,  0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION,  0 },
		{ 0, 12,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL,  0 },
		{ 0, 24,  D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,  0 },
		{ 0, 40,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,  1 },
		D3DDECL_END()
	};

	hr = g_pDevice->CreateVertexDeclaration(vertexElements, &m_vDeclaration);
	if (FAILED(hr))
	{
		InvalidateDeviceObjects();
		return false;
	}

	m_effect->SetTexture("lineTexture", m_lineTexture);
	m_loaded = true;

	return true;
}
IDirect3DTexture9*	MyResourceManager::loadTexture( const string& fileName )
{
	static IDirect3DDevice9* pDevice = MyGame3DDevice::GetSingleton()->GetDevice();
	string relativeFileName = textureFolder + fileName;
	IDirect3DTexture9*	texture;
	HR(D3DXCreateTextureFromFileA(
					pDevice,
					relativeFileName.c_str(),
					&texture ));
	return texture;
}
Esempio n. 24
0
void TowerRenderable::LoadFromFile(TowerCreateInfo& towerInfo)
{
	auto device = Globals::GetDevice()->GetDeviceD3D9();
	FillRenderableMeshWithXFile(towerInfo.sobj.meshFilename.c_str(), device, &m_pD3dxMesh);

	HRESULT v = D3DXCreateTextureFromFileA(device, towerInfo.sobj.textureFilename.at(0).c_str(), &m_d3d_texture);

	m_fxhandle = Globals::GetFxManager()->RequireEffectFormFile(towerInfo.sobj.fxFilename.c_str());
	m_fxhandle->SetTechnique("RenderSceneWithTexture1Light");
	TowerEntity* pTower = (TowerEntity *)m_parent;
	InitPatchQuad(pTower->GetRange());
}
Esempio n. 25
0
HRESULT InitGeometry()
{
    LPD3DXBUFFER pD3DXMtrlBuffer;

    // Load the mesh from the specified file
    if( FAILED( D3DXLoadMeshFromX( L"model\\Tiger.x", D3DXMESH_SYSTEMMEM,
                                   g_pd3dDevice, NULL,
                                   &pD3DXMtrlBuffer, NULL, &g_dwNumMaterials,
                                   &g_pMesh ) ) )
    {        
            return E_FAIL;
     
    }



    // We need to extract the material properties and texture names from the 
    // pD3DXMtrlBuffer
    D3DXMATERIAL* d3dxMaterials = ( D3DXMATERIAL* )pD3DXMtrlBuffer->GetBufferPointer();
    g_pMeshMaterials = new D3DMATERIAL9[g_dwNumMaterials];
    if( g_pMeshMaterials == NULL )
        return E_OUTOFMEMORY;
    g_pMeshTextures = new LPDIRECT3DTEXTURE9[g_dwNumMaterials];
    if( g_pMeshTextures == NULL )
        return E_OUTOFMEMORY;

    for( DWORD i = 0; i < g_dwNumMaterials; i++ )
    {
        // Copy the material
        g_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;

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

        g_pMeshTextures[i] = NULL;
        if( d3dxMaterials[i].pTextureFilename != NULL &&
            lstrlenA( d3dxMaterials[i].pTextureFilename ) > 0 )
        {
            // Create the texture
            if( FAILED( D3DXCreateTextureFromFileA( g_pd3dDevice,
                                                    d3dxMaterials[i].pTextureFilename,
                                                    &g_pMeshTextures[i] ) ) )
            {
                
            }
        }
    }

    // Done with the material buffer
    pD3DXMtrlBuffer->Release();

    return S_OK;
}
Esempio n. 26
0
bool Texture::Init( LPDIRECT3DDEVICE9 pDevice )
{
	assert( pDevice );
	pDevice_ = pDevice;
	HRESULT hr = S_OK;
	hr = D3DXCreateTextureFromFileA( pDevice_, 
		AssetID_.c_str(),
		&pTexture_ );
	if( FAILED( hr ) )
	{
		return false;
	}
	return true;
}
Esempio n. 27
0
void TestScene::initEffect()
{
    LPD3DXBUFFER bufferErrors = NULL;
    HRESULT hr;

    //D3DXMatrixIdentity(&world);
    //D3DXMatrixIdentity(&view);
    //D3DXMatrixIdentity(&proj);

    //D3DXMatrixPerspectiveFovLH(&proj, D3DXToRadian(40.0f), (float)GameGlobal::GetWidth() / (float)GameGlobal::GetHeight(), 0.0f, 100.0f);

    unsigned int vertexDataSize = 4 * sizeof(VertexData);

    //create vertex buffer
    GameGlobal::GetCurrentDevice()->CreateVertexBuffer(vertexDataSize, D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, 
                                                        D3DPOOL_DEFAULT, &vertexBuffer, 0);

    void *pVertices = NULL;
    vertexBuffer->Lock(0, vertexDataSize, (void**)&pVertices, 0);
    memcpy(pVertices, vertexData, vertexDataSize);
    vertexBuffer->Unlock();

    hr = D3DXCreateEffectFromFileA(GameGlobal::GetCurrentDevice(), "Empty.fx", 0, 0, 0, 0, &effect, &bufferErrors);

    //D3DXMatrixTranslation(&view, 0, 0, 2.75);
    //D3DXMATRIX matrix = world * view * proj;
    //effect->SetMatrix("WorldViewProj", &(world * view * proj));

    //D3DXCreateTexture(GameGlobal::GetCurrentDevice(), GameGlobal::GetWidth(), GameGlobal::GetHeight(), D3DX_DEFAULT,
    //                        D3DUSAGE_RENDERTARGET, D3DFMT_A8B8G8R8, D3DPOOL_DEFAULT, &texture0);

    //D3DXCreateTexture(GameGlobal::GetCurrentDevice(), GameGlobal::GetWidth(), GameGlobal::GetHeight(), D3DX_DEFAULT,
    //                        D3DUSAGE_RENDERTARGET, D3DFMT_A8B8G8R8, D3DPOOL_DEFAULT, &texture1);

    D3DXCreateTextureFromFileA(GameGlobal::GetCurrentDevice(), "valve.png", &texture0);
    D3DXCreateTextureFromFileA(GameGlobal::GetCurrentDevice(), "hungtrung.png", &texture1);  
}
Esempio n. 28
0
Mesh::Mesh ( std::wstring filename, LPDIRECT3DDEVICE9 directX )
{
	LPD3DXBUFFER pD3DXMtrlBuffer;

	// Load the mesh from the specified file
	D3DXLoadMeshFromX( filename.c_str(), D3DXMESH_SYSTEMMEM,
					   directX, NULL,
					   &pD3DXMtrlBuffer, NULL, &m_numMaterials,
					   &m_mesh );

	// We need to extract the material properties and texture names from the pD3DXMtrlBuffer
	D3DXMATERIAL* d3dxMaterials = ( D3DXMATERIAL* )pD3DXMtrlBuffer->GetBufferPointer();
	m_materials = new D3DMATERIAL9[m_numMaterials];
	m_textures = new LPDIRECT3DTEXTURE9[m_numMaterials];
	
	for( DWORD i = 0; i < m_numMaterials; i++ )
	{
		// Copy the material
		m_materials[i] = d3dxMaterials[i].MatD3D;

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

		m_textures[i] = NULL;
		if( d3dxMaterials[i].pTextureFilename != NULL &&
			lstrlenA( d3dxMaterials[i].pTextureFilename ) > 0 )
		{
			// Create the texture found in the assets folder
			const CHAR* strPrefix = "assets\\meshes\\";
			CHAR strTexture[MAX_PATH];
			strcpy_s( strTexture, MAX_PATH, strPrefix );
			strcat_s( strTexture, MAX_PATH, d3dxMaterials[i].pTextureFilename );
			// If texture is not in current folder, try parent folder
			if( FAILED( D3DXCreateTextureFromFileA( directX,
													strTexture,
													&m_textures[i] ) ) )
			{
				MessageBox( NULL, L"Could not find texture map", L"TalesOfPool.exe", MB_OK );
			}
		}
	}

	// Assert checks
	assert( m_materials != NULL );
	assert( m_textures != NULL );

	// Done with the material buffer
	pD3DXMtrlBuffer->Release();
}
Esempio n. 29
0
void TowerRenderable::InitPatchQuad(float scale)
{
	auto device = Globals::GetDevice()->GetDeviceD3D9();
	m_quad_mesh.reset(new QuadMesh);
	m_quad_mesh->Init(0);
	
	//fx
	m_QuadFxhandle = Globals::GetFxManager()->RequireEffectFormFile("../media/fx/terrain_patch.fx");
	m_QuadFxhandle ->SetTechnique("RenderSceneWithTexture1Light");
	
	//texture
	IDirect3DTexture9* p = 0;
	HRESULT v = D3DXCreateTextureFromFileA(device, "../media/tower/range.tga", &p);
	m_range_texture.reset(p,[&](IDirect3DTexture9* pT){pT->Release();});
}
Esempio n. 30
0
    bool setup( LPDIRECT3DDEVICE9 device )
    {
        bool result = false; // relayoutが必要かどうか

        for( dictionary_type::const_iterator i = dic_.begin() ;
             i != dic_.end() ;
             ++i ) {
            TextureHolder* p = (*i).second.get();
            if( !p->texture ) {
                D3DXCreateTextureFromFileA(
                    device, ( dir_ + p->filename ).c_str(), &p->texture );
                result = true;
            }
        }

        return result;
    }