コード例 #1
0
//===============================================================
//	ポリゴン初期化
//===============================================================
void InitFade(){
	LPDIRECT3DDEVICE9 pDevice = GetDevice();

	//頂点情報の作成
	MakeVertexFade(pDevice);

	//PlaySound(SOUND_LABEL_BGM001);

	g_nPatternAnime = 0;	////0から数えて

	g_bFadeChange = false;
	g_eFade = FADE_NONE;
	g_tFade.nFadeAlpha = 0;

	//テクスチャの読み込み
	D3DXCreateTextureFromFile(pDevice, FADE_TEX_NAME, &g_pTextureFade);
	
	g_tFade.fTexPosX  = FADE_TEX_POS_X;
	g_tFade.fTexPosY  = FADE_TEX_POS_Y;
	g_tFade.nTexSizeX = FADE_TEX_SIZE_X;
	g_tFade.nTexSizeY = FADE_TEX_SIZE_Y;
	g_tFade.nFadeAlpha         = 0;
	g_tFade.nFadeVol		   = FADE_VOLUME;



}
コード例 #2
0
ファイル: Particles.cpp プロジェクト: Khrijunk/CatSunBeam
void Particles::intBuffers(LPDIRECT3DDEVICE9 d3ddev){
	D3DXCreateTextureFromFile(d3ddev,"white.png",&texture);

	struct CUSTOMVERTEX1 t_vert[] =
    {
		{-.05f, .05f, 0.0f, D3DCOLOR_XRGB(255, 255, 255), 1, 0,},
        {-0.05f, -.05f, 0.0f, D3DCOLOR_XRGB(255, 255, 255), 0, 0,},
        {.05f, .05f, 0.0f, D3DCOLOR_XRGB(255, 255, 255), 1, 1,},
        {.05f, -.05f, 0.0f, D3DCOLOR_XRGB(255, 255, 255), 0, 1,},
    };

    // create a vertex buffer interface called t_buffer
    d3ddev->CreateVertexBuffer(4*sizeof(CUSTOMVERTEX1),
                               0,
                               CUSTOMFVF,
                               D3DPOOL_MANAGED,
                               &t_buffer,
                               NULL);

    VOID* pVoid;    // a void pointer

    // lock t_buffer and load the vertices into it
    t_buffer->Lock(0, 0, (void**)&pVoid, 0);
    memcpy(pVoid, t_vert, sizeof(t_vert));
    t_buffer->Unlock();

}
コード例 #3
0
ファイル: snowParticle.cpp プロジェクト: yingyuewuhen/D3D
bool SnowParticle::Init()
{
	//创建顶点数据
	if (FAILED(m_device->CreateVertexBuffer(m_numSnow * sizeof(POINTVERTEX),
		D3DUSAGE_POINTS | D3DUSAGE_WRITEONLY,
		D3DFVF_POINTVERTEX, D3DPOOL_MANAGED,
		&m_vb, 0)))
		return false;

	//加载纹理
	std::string resoursePath = Resourse::GetResoursePath();

	IDirect3DTexture9 *tex = 0;
	for (std::vector<std::string>::iterator it = m_textureNames.begin();
		it != m_textureNames.end();
		it++)
	{
		if (FAILED(D3DXCreateTextureFromFile(m_device, Convert::str2Wstr(resoursePath + *it).c_str(),
			&tex)))
			return false;
		m_snowTextures.push_back(tex);
	}

	for (int i = 0; i < m_numSnow; i++)
	{
		AddParticle();
	}
	return true;
}
コード例 #4
0
ファイル: Texture.cpp プロジェクト: goldenpython/ObjLoader
CTexture::CTexture(CDisplayDevice *pDevice, char *szFileName) {
	bool bResult;

#if (RENDER == DX9)
	bResult = D3DXCreateTextureFromFile(pDevice->m_pDevice, szFileName, &m_poTexture) == D3D_OK;
#endif
}
コード例 #5
0
ファイル: font.cpp プロジェクト: Thyfate/melax
HRESULT CD3DFont::InitDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice )
{
    HRESULT hr;

    // Keep a local copy of the device
    m_pd3dDevice = pd3dDevice;


    // Large fonts need larger textures
	//m_dwTexWidth  = m_dwTexHeight = 256;

	xmlNode *node = XMLParseFile("textures/font.xml");
	assert(node);
	int count = node->attribute("count").Asint();
	m_dwSpacing  = node->attribute("spacing").Asint() ;
	m_dwTexWidth = node->attribute("width").Asint();
	m_dwTexHeight= node->attribute("height").Asint();
	String imagefile = "textures/font.png";
	StringIter p(node->body);
    for( int i=0;i<count;i++)
    {
		int c;
        p >> c;
		p >> m_fTexCoords[c-32][0] >> m_fTexCoords[c-32][1] >> m_fTexCoords[c-32][2] >> m_fTexCoords[c-32][3];
    }
	hr=D3DXCreateTextureFromFile(m_pd3dDevice,(const char*)imagefile,&m_pTexture);
	LPD3DXBUFFER error;
	extern String effectpath;
	D3DXCreateEffectFromFile(m_pd3dDevice,effectpath + "/font.fx",NULL,NULL,0,NULL,&effect,&error)  && VERIFY_RESULT;
	assert(effect);
	diffusemap = effect->GetParameterByName(NULL,"diffusemap");
	assert(diffusemap);
	effect->SetTexture(diffusemap,m_pTexture) && VERIFY_RESULT;
    return S_OK;
}
コード例 #6
0
void TextureImpl_DirectX9::Load(const char *filename)
{
    char *convertedFilename = ResourceManager::GetConvertedPath(filename);

    LPDIRECT3DDEVICE9 device = NULL;
    if (device = DrawManager::GetDeviceHandle())
    {
        if(D3DXCreateTextureFromFile(device, convertedFilename, &_texture) != S_OK) {
            Debug::Error("[Texture] Fail to load %s...", filename);
        }
    }

    if (!_texture)
    {
        MemoryAllocator::Free(convertedFilename);    
        return;
    }

    D3DSURFACE_DESC desc;
    _texture->GetLevelDesc(0, &desc);
    _size.width = desc.Width;
    _size.height = desc.Height;
    _format = desc.Format;

    MemoryAllocator::Free(convertedFilename);    
}
コード例 #7
0
void PointSprite::Load( const std::string _fileName )
{
	HRESULT hr ;

	hr = GlobalD3DDevice::m_pd3dDevice->CreateVertexBuffer( sizeof(POINTSPRITE),
		D3DUSAGE_NPATCHES | D3DUSAGE_POINTS | D3DUSAGE_DYNAMIC,
		D3DFVF_XYZ | D3DFVF_PSIZE | D3DFVF_DIFFUSE,
		D3DPOOL_DEFAULT, &m_VB, NULL ) ;

	if( !FAILED( hr ) ) 
	{
		POINTSPRITE *pV ;
		hr = m_VB->Lock( sizeof( POINTSPRITE ), sizeof(POINTSPRITE),(void**)&pV,D3DLOCK_DISCARD ) ;
		if( !FAILED( hr ) )
		{
			pV->vPos = D3DXVECTOR3(2.0f,2.0f,1.0f) ;
			pV->fSize = 1.0f ;
			pV->dwColor = 0xffffffff ;
		}
		m_VB->Unlock() ;
	}

	WCHAR wcBuff[ 255 ] = { 0 } ;
	DXconvAnsiToWide::Change( wcBuff, _fileName.c_str(), 255 ) ;

	D3DXCreateTextureFromFile( GlobalD3DDevice::m_pd3dDevice, wcBuff, &m_Texture ) ;

}
コード例 #8
0
ファイル: Psystem.cpp プロジェクト: huanzheWu/3D-Tank-Battle
//初始化函数
bool PSystem:: init (IDirect3DDevice9 * device,wchar_t *texFileName)
{
	_device = device; 
	HRESULT hr=0;
	//创建顶点缓存
	hr=device->CreateVertexBuffer (
		_vbSize* sizeof(Particle),
		D3DUSAGE_DYNAMIC|D3DUSAGE_POINTS|D3DUSAGE_WRITEONLY,
		D3DFVF_XYZ|D3DFVF_DIFFUSE,
		D3DPOOL_DEFAULT, 
		&_vb,
		0
		);
	if(FAILED(hr))
	{
		::MessageBox(0, L"CreateVertexBuffer() - FAILED", L"PSystem", 0);
		return false;
	}
	//创建纹理
	hr=D3DXCreateTextureFromFile(
		device,
		texFileName,
		&_tex);
	if(FAILED(hr))
	{
		::MessageBox(0, L"CreateTextureFromFile - FAILED", L"PSystem", 0);
		return false;
	}
}
コード例 #9
0
 managed_texture2d::managed_texture2d(const boost::shared_ptr<device_services> & device,
                     const platform::tstring & src_file)
     : device(device)
 {
     HRESULT r = D3DXCreateTextureFromFile(device->get(), src_file.c_str(), &texture);
     check_failure(r, platform::narrow(LOCI_TSTR("Failed to load texture from file: ") + src_file).c_str(), "D3DXCreateTextureFromFile");
 }
コード例 #10
0
ファイル: DX9Render.cpp プロジェクト: stopiccot/googlecode
Texture *DX9Render::loadTextureFromFile(const wchar_t *file)
{
	DX9Texture *result = new DX9Texture();

	HRESULT hr = D3DXCreateTextureFromFile(device, file, &result->texture);
	if (FAILED(hr))
	{
		switch (hr)
		{
			case D3DXERR_INVALIDDATA:
			{
				//log() << "Texture file \"" << file << "\" does not exists" << std::endl;
				break;
			}
			default:
			{
				//log() << "Failed to load texture \"" << file << "\" does not exists" << std::endl; 
				break;
			}
		}

		delete result;
		return NULL;
	}

	return result;
}
コード例 #11
0
/**-----------------------------------------------------------------------------
 * 기하정보 초기화
 *------------------------------------------------------------------------------
 */
HRESULT InitGeometry()
{
	InitMatrix();
	// 빌보드로 사용할 텍스처 이미지
	D3DXCreateTextureFromFile( g_pd3dDevice, "tree01S.dds", &g_pTexBillboard[0] );
	D3DXCreateTextureFromFile( g_pd3dDevice, "tree02S.dds", &g_pTexBillboard[1] );
	D3DXCreateTextureFromFile( g_pd3dDevice, "tree35S.dds", &g_pTexBillboard[2] );
	D3DXCreateTextureFromFile( g_pd3dDevice, "tex.jpg", &g_pTexBillboard[3] );
	
	// 최초의 마우스 위치 보관
	POINT	pt;
	GetCursorPos( &pt );
	g_dwMouseX = pt.x;
	g_dwMouseY = pt.y;
	return S_OK;
}
コード例 #12
0
//=============================================================================
// 初期化処理
//=============================================================================
HRESULT InitExplosion(LPDIRECT3DDEVICE9 pDevice)
{
	// 頂点情報の作成
	MakeVertexExplosion(pDevice);

	// テクスチャの読み込み
	D3DXCreateTextureFromFile(pDevice,						// デバイスへのポインタ
								TEXTURE_EXPLOSION,			// ファイルの名前
								&g_pD3DTextureExplosion);	// 読み込むメモリー

	for(int nCntExplosion = 0; nCntExplosion < MAX_EXPLOSION; nCntExplosion++)
	{
		g_aExplosion[nCntExplosion].pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
		g_aExplosion[nCntExplosion].rot = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
		g_aExplosion[nCntExplosion].scale = D3DXVECTOR3(1.0f, 1.0f, 1.0f);
		g_aExplosion[nCntExplosion].fSizeX = BULLET_SIZE_X;
		g_aExplosion[nCntExplosion].fSizeY = BULLET_SIZE_Y;
		g_aExplosion[nCntExplosion].nCounter = 0;
		g_aExplosion[nCntExplosion].nPattern = 0;
		g_aExplosion[nCntExplosion].fAlpha = 1.0f;
		g_aExplosion[nCntExplosion].bUse = false;
	}

	return S_OK;
}
コード例 #13
0
void cMainGame::Setup()
{
	//폰트 생성
	D3DXFONT_DESC fd;
	ZeroMemory(&fd,sizeof(D3DXFONT_DESC));
	fd.Height			= 45;
	fd.Width			= 28;
	fd.Weight			= FW_MEDIUM;
	fd.Italic			= false;
	fd.CharSet			= DEFAULT_CHARSET;
	fd.OutputPrecision  = OUT_DEFAULT_PRECIS;
	fd.PitchAndFamily   = FF_DONTCARE;
	//strcpy_s(fd.FaceName, "궁서체");	//글꼴 스타일
	AddFontResource("umberto.ttf");
	strcpy(fd.FaceName, "umberto");

	D3DXCreateFontIndirect(g_pD3DDevice, &fd, &m_pFont);

	m_pCamera = new cCamera;
	m_pCamera->Setup(NULL);

	m_pGrid = new cGrid;
	m_pGrid->Setup(15, 1.0f);
	LPDIRECT3DTEXTURE9	pTexture = NULL;
	D3DXCreateTextureFromFile(g_pD3DDevice, "Batman.png", &pTexture);

	cBody* pBody = new cBody;
	pBody->Setup();
	pBody->SetTexture(pTexture);
	m_pRoot = pBody;

	cHead* pHead = new cHead;
	pHead->Setup();
	pHead->SetTexture(pTexture);
	m_pRoot->AddChild(pHead);

	cLeftArm* pLeftArm = new cLeftArm;
	pLeftArm->Setup();
	pLeftArm->SetTexture(pTexture);
	m_pRoot->AddChild(pLeftArm);

	cRightArm* pRightArm = new cRightArm;
	pRightArm->Setup();
	pRightArm->SetTexture(pTexture);
	m_pRoot->AddChild(pRightArm);

	cLeftLeg* pLeftLeg = new cLeftLeg;
	pLeftLeg->Setup();
	pLeftLeg->SetTexture(pTexture);
	m_pRoot->AddChild(pLeftLeg);

	cRightLeg* pRightLeg = new cRightLeg;
	pRightLeg->Setup();
	pRightLeg->SetTexture(pTexture);
	m_pRoot->AddChild(pRightLeg);

	SAFE_RELEASE(pTexture);

	SetLight();
}
コード例 #14
0
ファイル: Particle.cpp プロジェクト: Dimiondark/testxo
void CException::Init( IDirect3DDevice9* D3DDevice )
{		
	if ( D3DDevice )
		m_D3DDevice = D3DDevice;
	else
	{
		Log( "error: No init Explosion" );
		return;	
	}	
	// создаЄм буфер вершин
	if ( FAILED( m_D3DDevice->CreateVertexBuffer( m_Size * 4 * sizeof( CVertexFVF ), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &m_VertexBuffer, 0 ) ) )		
		Log( "error create vertex buffer Explosion" );

	// создаЄм буфер индексов
	if ( FAILED( m_D3DDevice->CreateIndexBuffer( m_Size * 6 * sizeof( short ), 0, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &m_IndexBuffer, 0 ) ) )  		
		Log( "error create index buffer Explosion" );

	for ( int i = 0; i < m_Size; ++i )
	{
		//------задаЄм случайное направление-----------------
		m_Particles[i].m_Direct = D3DXVECTOR3( rand()/float(RAND_MAX)*2-1, 0, rand()/float(RAND_MAX)*2-1 );		
		D3DXVec3Normalize( &m_Particles[i].m_Direct, &m_Particles[i].m_Direct );		
	}
	std::string FileName = "model\\Explosion.tga";
	//------загружаем текстуру-----
	if ( FAILED( D3DXCreateTextureFromFile( m_D3DDevice, FileName.c_str(), &m_TextureExp )))	
		Log( "error load texture Exception" );	
	
	Log( "Init Explosion" );
}
コード例 #15
0
ファイル: Terrain.cpp プロジェクト: GdLinkLock/DXGameDemo
bool Terrian::LoadTerrainFromFile(const char* rawFileName,const char* textureName)
{
	//读文件
	std::ifstream inFile;
	inFile.open(rawFileName,std::ios::binary);
	//得到文件大小
	inFile.seekg(0,std::ios::end);
	std::vector<BYTE> fileData(inFile.tellg());
	inFile.seekg(0,std::ios::beg);
	inFile.read((char*)&fileData[0],fileData.size());
	inFile.close();

	//保存高度信息
	m_HeightInfo.resize(fileData.size());
	for (size_t i=0;i<fileData.size();i++)
		m_HeightInfo[i]=fileData[i];

	//加载纹理
	HRESULT hr=D3DXCreateTextureFromFile(m_pDevice,textureName,&m_pTexture);
	if (FAILED(hr))
	{
		PopupError("Create texture in Terrain!");
		return false;
	}
	return true;
}
コード例 #16
0
ファイル: GUI.cpp プロジェクト: SinYocto/Zee
void ButtonStyle::CreateTextures()
{
	IDirect3DDevice9* d3dDevice = gEngine->GetDriver()->GetD3DDevice();

	if(normalTex)
		SAFE_RELEASE(normalTex);
	D3DXCreateTextureFromFile(d3dDevice, normalTexFilePath, &normalTex);
	
	if(hoverTex)
		SAFE_RELEASE(hoverTex);
	D3DXCreateTextureFromFile(d3dDevice, hoverTexFilePath, &hoverTex);
	
	if(activeTex)
		SAFE_RELEASE(activeTex);
	D3DXCreateTextureFromFile(d3dDevice, activeTexFilePath, &activeTex);
}
コード例 #17
0
ファイル: DummyFace.cpp プロジェクト: 7zhang/studies
DummyFace::DummyFace() {
    m_pMesh = NULL;
    m_pTexture = NULL;

    D3DXLoadMeshFromX("resources/face01.x", D3DXMESH_MANAGED, g_pDevice, NULL, NULL, NULL, NULL, &m_pMesh);
    D3DXCreateTextureFromFile(g_pDevice, "resources/face.jpg", &m_pTexture);
}
コード例 #18
0
ファイル: HUD.cpp プロジェクト: dimroc/homeworkjunkie_egp
////////////////////////////// CStaticHUDItem Functions //////////////////////////
CHUD::CStaticHUDItem::CStaticHUDItem(D3DXVECTOR2 botleftPos, float _height, float _width, LPCWSTR texFileName, IDirect3DDevice9* pd3dDevice) :
    m_pVB(NULL), m_pTex(NULL), height(_height), width(_width), pos(botleftPos)
{
    HRESULT hr;
    // Create texture.
    V(D3DXCreateTextureFromFile(pd3dDevice, texFileName, &m_pTex) );
    // Create background polygon.

    int size  = 4*sizeof(BoxVertex);
    V( pd3dDevice->CreateVertexBuffer( size, D3DUSAGE_WRITEONLY, BoxVertex::FVF, D3DPOOL_MANAGED, &m_pVB, NULL) );

    // max tex coordinates
    float maxu = 1, maxv = 1;
    float zFar = 1;

    // Lock the buffer to gain access to the vertices
    BoxVertex* pVertices;
    V( m_pVB->Lock(0, size, (VOID**)&pVertices, 0 ) );

    pVertices[0] = BoxVertex(D3DXVECTOR3(pos.x, pos.y, zFar), 0, maxv);
    pVertices[1] = BoxVertex(D3DXVECTOR3(pos.x, pos.y+height, zFar), 0, 0);
    pVertices[2] = BoxVertex(D3DXVECTOR3(pos.x+width, pos.y, zFar), maxu, maxv);
    pVertices[3] = BoxVertex(D3DXVECTOR3(pos.x+width, pos.y+height, zFar), maxu, 0);

    V( m_pVB->Unlock() );
}
コード例 #19
0
ファイル: loadImport.cpp プロジェクト: tnbmi/ms_project
//=============================================================================
// 初期化
//=============================================================================
bool LoadImport::Initialize(LPDIRECT3DDEVICE9 device)
{
	HRESULT	hr;
	char	str[512];

	//----------------------------
	// テクスチャ
	//----------------------------
	for(int cnt = 1; cnt < TEX_MAX; ++cnt)
	{
		// パス連結
		memset(str, 0, sizeof(str));
		strcpy_s(str, TEXTURE_PATH);
		strcat_s(str, sizeof(str), _load_texture_name[cnt]);

		// テクスチャ読み込み
		hr = D3DXCreateTextureFromFile(device, str, &m_texture[cnt]);
		if(FAILED(hr))
		{
			MessageBox(NULL, "テクスチャ無し", "D3DXCreateTextureFromFile", MB_OK);
		}
	}

	return true;
}
コード例 #20
0
ファイル: HUD.cpp プロジェクト: dimroc/homeworkjunkie_egp
////////////////////////////// CVisionPlane Functions ///////////////////////////
CHUD::CVisionPlane::CVisionPlane(D3DXVECTOR2 screenDim, LPCWSTR texFileName, int _zOrder, IDirect3DDevice9* pd3dDevice) :
    m_pVB(NULL), m_pTex(NULL), pos(screenDim), zOrder(_zOrder)
{
    HRESULT hr;
    // Create texture.
    V(D3DXCreateTextureFromFile(pd3dDevice, texFileName, &m_pTex) );

    int size  = 4*sizeof(BoxVertex);
    V( pd3dDevice->CreateVertexBuffer( size, D3DUSAGE_WRITEONLY, BoxVertex::FVF, D3DPOOL_MANAGED, &m_pVB, NULL) );

    // max tex coordinates
    float w = 0.7f, h = 0.5f;
    float maxu = 1, maxv = 1;
    float zFar = 1;

    // Lock the buffer to gain access to the vertices
    BoxVertex* pVertices;
    V( m_pVB->Lock(0, size, (VOID**)&pVertices, 0 ) );

    pVertices[0] = BoxVertex(D3DXVECTOR3(-w, -h, zFar), 0, maxv);
    pVertices[1] = BoxVertex(D3DXVECTOR3(-w, h, zFar), 0, 0);
    pVertices[2] = BoxVertex(D3DXVECTOR3(w, -h, zFar), maxu, maxv);
    pVertices[3] = BoxVertex(D3DXVECTOR3(w, h, zFar), maxu, 0);

    V( m_pVB->Unlock() );
}
コード例 #21
0
//z 2015-07-07 13:20 从纹理中载入文件
// Loads the texture specified by "fileName".  Returns
// true on success, false otherwise
bool CD3DTexture::load(const char *fileName)
{
    // Error Check
    if(!fileName)
        return false;

    // Error Check -- If device isn't valid return false
    if(!CD3DObj::mDevice)
        return false;

    // If a texture is already loaded, free it before we load a new one
    if(mTexture)
    {
        mTexture->Release();
        mTexture = NULL;
    }

    //z 2015-07-07 13:22 D3DXCreateTextureFromFile 载入 texture 。
    //z 注意该函数将会创建一个 full mipmap chain 。
    // D3D makes it VERY EASY for us to load a texture.  Lets look at
    // this function by parameter:
    // CD3DObj::mDevice -- Pointer to a IDirect3DDevice9 (D3D display device)
    //					   that is to be associated with the texture
    // fileName -- The name of the texture file to load.  Valid texture file
    //			   extensions are:  .bmp, .dib, .dds, .jpg, .png, .tga
    // &mTexture -- The address of a pointer to a IDirect3DTexture9 (D3D texture
    //				   interface) that will be filled with the created texture resource
    return (D3DXCreateTextureFromFile(CD3DObj::mDevice, fileName, &mTexture) == D3D_OK);

    // **NOTE** This function creates a full mipmap chain.  So if your image, for instance, is
    // 128x128 this will produce mipmaps of sizes 64x64, 32x32, 16x16, 8x8, 4x4, 2x2, and 1x1.
}
コード例 #22
0
ファイル: GUIClass.cpp プロジェクト: whztt07/Ninth-World
//-------------------------------------------【AddBackground()函数】---------------------------------------------
// Desc:添加GUIClass对象的唯一背景图片
//---------------------------------------------------------------------------------------------------------------
BOOL GUIClass::AddBackground(TCHAR *  pBackgroundName)
{
	if (!pBackgroundName) return FALSE;
	IF(D3DXCreateTextureFromFile(m_pd3dDevice9, pBackgroundName, &m_pBackGround));

	IF(m_pd3dDevice9->CreateVertexBuffer(4 * sizeof(GUIVERTEX), D3DUSAGE_WRITEONLY, D3DFVF_GUI,
		 D3DPOOL_DEFAULT, &m_pBkBuffer, NULL));

	float w = (float)m_wBackgroundWidth;
	float h = (float)m_wBackgroundHeight;

	GUIVERTEX Vertices[] =
	{
		{ 0, h, 0.0f, 1.0f, 0.0f, 1.0f },
		{ 0, 0, 0.0f, 1.0f, 0.0f, 0.0f },
		{ w, h, 0.0f, 1.0f, 1.0f, 1.0f },
		{ w, 0, 0.0f, 1.0f, 1.0f, 0.0f }
	};

	VOID *pVertices = NULL;
	IF(m_pBkBuffer->Lock(0, 0, &pVertices, NULL));
	memcpy(pVertices, Vertices, sizeof(Vertices));
	m_pBkBuffer->Unlock();

	m_bIsBKBufferUsed = true;
	return TRUE;
}
コード例 #23
0
//=======================================================================
HRESULT init_geometry()
{
    LPD3DXBUFFER pD3DXMtrlBuffer;

    { // try load mesh from x-file
        HRESULT hr = D3DXLoadMeshFromX(g_xFname, D3DXMESH_SYSTEMMEM,
                                        g_pd3dDevice, NULL,
                                        &pD3DXMtrlBuffer, NULL, &g_materialNums,
                                        &g_pMesh);
        if ( FAILED( hr ) ) return E_FAIL;
    }

    // init material & texture
    D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
    g_pMeshMaterials            = new D3DMATERIAL9[g_materialNums];
    g_pMeshTextures             = new LPDIRECT3DTEXTURE9[g_materialNums];

    for (int i = 0; i < g_materialNums; ++i) {
        g_pMeshMaterials[i]         = d3dxMaterials[i].MatD3D;
        g_pMeshMaterials[i].Ambient = g_pMeshMaterials[i].Diffuse;
        g_pMeshTextures[i] = NULL;

        if (d3dxMaterials[i].pTextureFilename != NULL
            && lstrlen(d3dxMaterials[i].pTextureFilename) > 0 ) {
            HRESULT hr = D3DXCreateTextureFromFile( g_pd3dDevice, 
                                                d3dxMaterials[i].pTextureFilename, 
                                                &g_pMeshTextures[i]);
            if ( FAILED( hr ) ) return E_FAIL;
        }
    }

    pD3DXMtrlBuffer->Release();
    return S_OK;
}
コード例 #24
0
ファイル: Main.cpp プロジェクト: junglek/DirectX-Basic
HRESULT initGeometry(){
	LPD3DXBUFFER pD3DXMtrlBuffer;
	if(FAILED(D3DXLoadMeshFromX(L"Heli.x", D3DXMESH_MANAGED,
		g_pDevice, NULL, &pD3DXMtrlBuffer, NULL, &g_dwNumMaterials, &g_pMesh)))
		return E_FAIL;
	//Extract material & texture
	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;
	//Extract
	for(DWORD i=0; i<g_dwNumMaterials; ++i){
		g_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;
		g_pMeshMaterials[i].Ambient = g_pMeshMaterials[i].Diffuse;

		g_pMeshTextures[i] = NULL;
		if(d3dxMaterials[i].pTextureFilename != NULL && strlen(d3dxMaterials[i].pTextureFilename) > 0){
			WCHAR name[256];
			removePathFromFileName(d3dxMaterials[i].pTextureFilename, name);

			if(FAILED(D3DXCreateTextureFromFile(g_pDevice, name, &g_pMeshTextures[i]))){
				MessageBox(NULL, L"Cound not find texture file", L"initGeometry()", MB_OK);
			}
		}
	}
	pD3DXMtrlBuffer->Release();

	return S_OK;
};
コード例 #25
0
ファイル: particlesystem.cpp プロジェクト: reykjavix/Ace-Tres
//-----------------------------------------------------------------------------
// 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
    if( FAILED( D3DXCreateTextureFromFile( pd3dDevice, m_chTexFile, &m_ptexParticle ) ) )
        return E_FAIL;

    return S_OK;
}
コード例 #26
0
CTexturePtr Graphics::LoadTexture(const std::wstring& szFileName )
{
	// ищем текстуру среди уже загруженных
	vecTextures::iterator itr = m_vecTextures.begin();
	while(itr!=m_vecTextures.end())
	{
		if ( (*itr)->GetSrc().compare(szFileName)==0 )
			return *itr; // нашли
		itr++;
	}
	
	// не нашли, пробуем загрузить текстуру
	LPDIRECT3DTEXTURE9 pTex = NULL;
	if (FAILED(D3DXCreateTextureFromFile(m_pd3dDevice, szFileName.c_str(), &pTex)))
		return NULL;
	
	// создаЄм наш собственный обект текстуры
	CTexturePtr pTexPtr = new CTexture();
	pTexPtr->SetSrc(szFileName);
	pTexPtr->SetTexture(pTex);

	m_vecTextures.push_back(pTexPtr);
	
	return pTexPtr; // возвращаем (указатель на) новую текстуру
}
コード例 #27
0
//	生成
C3DTexture* C3DTexture::Create( std::string& _path ) 
{
	C3DTexture *pTex = NULL ;

	//	管理マップからすでにメモリ上に
	std::map< std::string, C3DTexture* >::iterator it = m_Textures.find( _path ) ;

	//	存在しなければ新しくロード
	if( it == m_Textures.end() ){
		pTex = new C3DTexture() ;
		pTex->m_Name = _path ;
		WCHAR wcBuff[ 255 ] = { 0 } ;
		DXconvAnsiToWide::Change( wcBuff, _path.c_str(), 255 ) ;
		D3DXCreateTextureFromFile( 
			GlobalD3DDevice::m_pd3dDevice,
			wcBuff, 
			&pTex->m_DirecxTex ) ;
		
		//	管理マップに登録
		m_Textures.insert( std::make_pair( _path, pTex ) ) ;

	//	既に存在するテクスチャを返す
	}else{
		pTex = it->second ;
	}	
	return pTex ;
}
コード例 #28
0
ファイル: XFileDemo.cpp プロジェクト: kasicass/introdx9
XFileDemo::XFileDemo(HINSTANCE hInstance, std::wstring winCaption)
	: D3DApp(hInstance, winCaption)
{
	InitAllVertexDeclarations();

	mGfxStats = new GfxStats();

	mCameraRadius    = 12.0f;
	mCameraRotationY = 1.2f * D3DX_PI;
	mCameraHeight    = 6.0f;

	mLight.dirW    = D3DXVECTOR3(0.0f, 1.0f, 2.0f);
	D3DXVec3Normalize(&mLight.dirW, &mLight.dirW);
	mLight.ambient = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
	mLight.diffuse = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);
	mLight.spec    = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);

	LoadXFile(L"../src/chap14/XFileDemo/Dwarf.x", &mMesh, mMtrl, mTex);
	D3DXMatrixIdentity(&mWorld);

	HR(D3DXCreateTextureFromFile(gd3dDevice, L"../src/chap14/XFileDemo/whitetex.dds", &mWhiteTex));

	mGfxStats->addVertices(mMesh->GetNumVertices());
	mGfxStats->addTriangles(mMesh->GetNumFaces());

	buildFX();
	
	onResetDevice();
}
コード例 #29
0
ファイル: Mesh.cpp プロジェクト: Nixxus/GamesDevelopment2
// Creates a DirectX specific material from an imported material
bool CMesh::CreateMaterialDX
(
	const SMeshMaterial& material,
	SMeshMaterialDX*     materialDX
)
{
	// Load shaders for render method
	materialDX->renderMethod = material.renderMethod;
	if (!LoadMethod( materialDX->renderMethod ))
	{
		return false;
	}

	// Copy colours and shininess from material
	materialDX->diffuseColour = D3DXCOLOR( material.diffuseColour.r, material.diffuseColour.g, 
	                                       material.diffuseColour.b, material.diffuseColour.a );
	materialDX->specularColour = D3DXCOLOR( material.specularColour.r, material.specularColour.g, 
	                                        material.specularColour.b, material.specularColour.a );
	materialDX->specularPower = material.specularPower;

	// Load material textures
	materialDX->numTextures = material.numTextures;
	for (TUInt32 texture = 0; texture < material.numTextures; ++texture)
	{
		string fullFileName = MediaFolder + material.textureFileNames[texture];
		if (FAILED(D3DXCreateTextureFromFile( g_pd3dDevice, fullFileName.c_str(),
											  &materialDX->textures[texture] )))
		{
			string errorMsg = "Error loading texture " + fullFileName;
			SystemMessageBox( errorMsg.c_str(), "CMesh Error" );
			return false;
		}
	}
	return true;
}
コード例 #30
0
ファイル: Mesh.cpp プロジェクト: patrickmortensen/theEngine
void Mesh::LoadTextureFromFile(char* filepath)
{
	RemoveTexture();
	if (!filepath)
		return;
	HRESULT result;
	result = D3DXCreateTextureFromFile(gfx.GetDevice(), filepath, &tex);
	
	int fileLen = 0;
	for (; filepath[fileLen] != '\0'; fileLen++);

	char* temp = new char[fileLen + 1];
	for (int i = 0; i < fileLen + 1; i++){ temp[i] = filepath[i]; }

	if (TextureFilePath)
		delete TextureFilePath;
	
	TextureFilePath = new char[fileLen + 1];
	for (int i = 0; i < fileLen + 1; i++)
	{
		TextureFilePath[i] = temp[i];
	}

	if (result != D3D_OK)
		MessageBox(NULL, "Failed To Create Texture \n(function: Mesh::LoadTextureFromFile File: Mesh.cpp)",
		"Error", MB_OK | MB_ICONEXCLAMATION);
}