//=============================================================================
// 終了処理
//=============================================================================
void UninitBillboard(void)
{
	if(g_pD3DTextureBillboard != NULL)
	{// テクスチャの開放
		g_pD3DTextureBillboard->Release();
		g_pD3DTextureBillboard = NULL;
	}

	if(g_pD3DVtxBuffBillboard != NULL)
	{// 頂点バッファの開放
		g_pD3DVtxBuffBillboard->Release();
		g_pD3DVtxBuffBillboard = NULL;
	}
}
Beispiel #2
0
//-----------------------------------------------------------------------------
// Desc: 释放创建的对象
//-----------------------------------------------------------------------------
VOID Cleanup()
{
	//释放顶点缓冲区对象
	if( g_pVB != NULL )
		g_pVB->Release();

	//释放Direct3D设备对象
	if( g_pd3dDevice != NULL )
		g_pd3dDevice->Release();

	//释放Direct3D对象
	if( g_pD3D != NULL )
		g_pD3D->Release();
}
VOID Cleanup()
{
	if( g_pVB != NULL )        
		g_pVB->Release();

	if(g_pCubeTexture != NULL)
		g_pCubeTexture->Release();

	if( g_pd3dDevice != NULL ) 
		g_pd3dDevice->Release();

	if( g_pD3D != NULL )       
		g_pD3D->Release();
}
//=============================================================================
// 終了処理
//=============================================================================
void UninitExplosion(void)
{
	if(g_pD3DTextureExplosion != NULL)
	{// テクスチャの開放
		g_pD3DTextureExplosion->Release();
		g_pD3DTextureExplosion = NULL;
	}

	if(g_pD3DVtxBuffExplosion != NULL)
	{// 頂点バッファの開放
		g_pD3DVtxBuffExplosion->Release();
		g_pD3DVtxBuffExplosion = NULL;
	}
}
Beispiel #5
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);  
}
void TriangleExercise::setupPipeline() {
	// create the vertices using the CUSTOMVERTEX struct
	CUSTOMVERTEX vertices[] =
	{
		{ 400.0f, 62.5f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
		{ 650.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },
		{ 150.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
	};

	// create a vertex buffer interface called v_buffer
	d3ddev->CreateVertexBuffer(3 * sizeof(CUSTOMVERTEX),
		0,
		CUSTOMFVF,
		D3DPOOL_MANAGED,
		&v_buffer,
		NULL);

	VOID* pVoid;    // a void pointer

	// lock v_buffer and load the vertices into it
	v_buffer->Lock(0, 0, (void**)&pVoid, 0);
	memcpy(pVoid, vertices, sizeof(vertices));
	v_buffer->Unlock();
}
Beispiel #7
0
VOID Cleanup()
{
	if( g_pVB != NULL )
		g_pVB->Release();

	if( g_pd3dDevice != NULL )
		g_pd3dDevice->Release();

	if( g_pD3D != NULL )
		g_pD3D->Release();
	if(Objects != NULL){
		Objects->Release();
	}

}
Beispiel #8
0
HRESULT CreateVertex()
{
	POINTVERTEX points[] = 
	{
		{-5.0f, 5.0f, 0.0f, 0xffff0000},
		{ 0.0f, 5.0f, 0.0f, 0xffff0000},
		{ 5.0f, 5.0f, 0.0f, 0xffff0000},

		{-5.0f, 0.0f, 0.0f, 0xff00ff00},
		{ 0.0f, 0.0f, 0.0f, 0xff00ff00},
		{ 5.0f, 0.0f, 0.0f, 0xff00ff00},

		{-5.0f, -5.0f, 0.0f, 0xff0000ff},
		{ 0.0f, -5.0f, 0.0f, 0xff0000ff},
		{ 5.0f, -5.0f, 0.0f, 0xff0000ff}
	} ;

	// Create vertex buffer
	if (FAILED(g_pd3dDevice->CreateVertexBuffer(
		NUM_VERTEX * sizeof(POINTVERTEX), 
		D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY | D3DUSAGE_POINTS, 
		D3DFVF_POINTVERTEX, 
		D3DPOOL_DEFAULT, 
		&g_pVB,
		NULL)))
	{
		return E_FAIL ;
	}

	// Copy vertex data
	VOID* pVertices;
	if( FAILED( g_pVB->Lock( 0, sizeof(points), (void**)&pVertices, 0 ) ) )
		return E_FAIL;
	memcpy( pVertices, points, sizeof(points) );
	g_pVB->Unlock();
}
VOID Cleanup()
{
	// meshes 
	if ( g_pMeshMaterials != NULL )
		delete[] g_pMeshMaterials;

	if ( g_pMeshTextures )
	{
		for ( DWORD i = 0; i < g_dwNumMaterials; ++i )
		{
			if ( g_pMeshTextures[i] )
				g_pMeshTextures[i]->Release();
		}
		delete[] g_pMeshTextures;
	}

	if ( g_pMesh != NULL )
		g_pMesh->Release();

	if ( g_pMeshMaterialsSecond != NULL )
		delete[] g_pMeshMaterialsSecond;

	if ( g_pMeshTexturesSecond )
	{
		for ( DWORD i = 0; i < g_dwNumMaterialsSecond; ++i )
		{
			if ( g_pMeshTexturesSecond[i] )
				g_pMeshTexturesSecond[i]->Release();
		}
		delete[] g_pMeshTexturesSecond;
	}

	if ( g_pMeshSecond != NULL )
		g_pMeshSecond->Release();

	// cylinder
	if ( g_pTexture != NULL )
		g_pTexture->Release();

	if ( g_pVB != NULL )
		g_pVB->Release();

	if ( g_pd3dDevice != NULL )
		g_pd3dDevice->Release();

	if ( g_pD3D != NULL )
		g_pD3D->Release();
}
VOID shutDown() {
	if (d3dDevice != NULL) {
		d3dDevice->Release();
		d3dDevice = NULL;
	}

	if (d3dManager != NULL) {
		d3dManager->Release();
		d3dManager = NULL;
	}

	if (d3dVertexBuf != NULL) {
		d3dVertexBuf->Release();
		d3dVertexBuf = NULL;
	}
}
//////////////////////////////////////////////////////////////////////////
// 객체 정리 - 순서 주의!
//////////////////////////////////////////////////////////////////////////
VOID Cleanup()
{
	if ( g_pVB != NULL )
	{
		g_pVB->Release();
	}

	if ( g_pd3dDevice != NULL )
	{
		g_pd3dDevice->Release();
	}

	if ( g_pD3D != NULL )
	{
		g_pD3D->Release();
	}
}
Beispiel #12
0
void ReleaseD3D()
{
	if (g_pVB) g_pVB->Release();

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

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

}
Beispiel #13
0
// this is the function that cleans up Direct3D and COM
void cleanD3D(void) {
	if (d3ddev != NULL) {
		d3ddev->Release();
	}
	if (d3ddev != NULL) {
		d3d->Release();
	}
	if (tx != NULL) {
		tx->Release();
	}
	if (vb != NULL) {
		vb->Release();
	}
	if (font != NULL) {
		font->Release();
	}
}
Beispiel #14
0
//=============================================================================
// 終了処理
//=============================================================================
void UninitBotton(void)
{
	for(int nCntTex = 0; nCntTex < MAX_BOTTON; nCntTex++)
	{
		if(g_apD3DTextureBotton[nCntTex] != NULL)
		{// テクスチャの開放
			g_apD3DTextureBotton[nCntTex]->Release();
			g_apD3DTextureBotton[nCntTex] = NULL;
		}
	}

	if(g_pD3DVtxBuffBotton != NULL)
	{// 頂点バッファの開放
		g_pD3DVtxBuffBotton->Release();
		g_pD3DVtxBuffBotton = NULL;
	}
}
Beispiel #15
0
//=============================================================================
// 終了処理
//=============================================================================
void UninitPlaybar(void)
{
	for(int nCntTex = 0; nCntTex < MAX_PLAYBAR; nCntTex++)
	{
		if(g_apD3DTexturePlaybar[nCntTex] != NULL)
		{// テクスチャの開放
			g_apD3DTexturePlaybar[nCntTex]->Release();
			g_apD3DTexturePlaybar[nCntTex] = NULL;
		}
	}

	if(g_pD3DVtxBuffPlaybar != NULL)
	{// 頂点バッファの開放
		g_pD3DVtxBuffPlaybar->Release();
		g_pD3DVtxBuffPlaybar = NULL;
	}
}
//-----------------------------------------------------------------------------
// Name: VertexData::AddVertexStream()
//-----------------------------------------------------------------------------
VOID VertexData::AddVertexStream( LPDIRECT3DVERTEXBUFFER9 pBuffer, DWORD Stride, DWORD NumVerts, DWORD Divider )
{
    // vertex buffers are assumed to have the correct bound
    assert( pBuffer );

    DWORD dwStreamIndex = (DWORD)m_VertexStreams.size();
    assert( dwStreamIndex < MaxStreamCount );
    m_dwStreamStrides[dwStreamIndex] = Stride;

    VertexStream Stream;
    Stream.pVertexBuffer = pBuffer;
    Stream.Divider = Divider;
    Stream.Stride = Stride;
    m_VertexStreams.push_back( Stream );
    m_NumVertices += NumVerts;

    pBuffer->AddRef();
}
Beispiel #17
0
//-----------------------------------------------------------------------------
// Name: Cleanup()
// Desc: Releases all previously initialized objects
//-----------------------------------------------------------------------------
VOID Cleanup()
{
    if( g_pFont != NULL )
		g_pFont->Release();
	
	if( g_pVBCylinder != NULL )
        g_pVBCylinder->Release();

	if (g_pTexture != NULL )
		g_pTexture->Release();

	if (g_pTexture2 != NULL )
		g_pTexture2->Release();

    if( g_pd3dDevice != NULL )
        g_pd3dDevice->Release();

    if( g_pD3D != NULL )
        g_pD3D->Release();
}
	void release_objects()
	{
		if ( lpsurface )
		{
			lpsurface->Release();
			lpsurface = 0;
		}

		if ( lptex )
		{
			lptex->Release();
			lptex = 0;
		}

		if ( lpvbuf )
		{
			lpvbuf->Release();
			lpvbuf = 0;
		}
	}
Beispiel #19
0
VOID Cleanup()
{
	// Release vertex buffer
	if (g_pVB != NULL)
	{
		g_pVB->Release() ;
		g_pVB = NULL ;
	}

	// Release teapot mesh
	if(g_pTeapotMesh != NULL)
		g_pTeapotMesh->Release() ;

	// Release D3D
	if( g_pD3D != NULL)
		g_pD3D->Release();

	// Release device
	if( g_pd3dDevice != NULL) 
		g_pd3dDevice->Release();
}
//-----------------------------------------------------------------------------
// Name: Cleanup()
// Desc: Releases all previously initialized objects
//-----------------------------------------------------------------------------
VOID Cleanup()
{
	if (g_pTexture[0] != NULL)
		g_pTexture[0]->Release();

	if (g_pTexture[1] != NULL)
		g_pTexture[1]->Release();

	if (g_pVB != NULL)
		g_pVB->Release();

	if (g_pMeshMaterials != NULL)
	{
		for (int loop = 0; loop < MESH_COUNT; ++loop)
			delete[] g_pMeshMaterials[loop];
	}
		
    if( g_pMeshTextures )
    {
		for (int loop = 0; loop < MESH_COUNT; ++loop)
		{
			for (DWORD i = 0; i < g_dwNumMaterials[loop]; i++)
			{
				if (g_pMeshTextures[loop][i])
					g_pMeshTextures[loop][i]->Release();
			}
		}
    }
	if (g_pMesh[0] != NULL)
		g_pMesh[0]->Release();

	if (g_pMesh[1] != NULL)
		g_pMesh[1]->Release();

    if( g_pd3dDevice != NULL )
        g_pd3dDevice->Release();

    if( g_pD3D != NULL )
        g_pD3D->Release();
}
Beispiel #21
0
//-----------------------------------------------------------------------------
// Name: Cleanup()
// Desc: Releases all previously initialized objects
//-----------------------------------------------------------------------------
VOID Cleanup()
{
    CleanupDShow();

    if( g_pTexture != NULL )   
        g_pTexture->Release();
        
    if( g_pVB != NULL )
        g_pVB->Release();
        
    if( g_pd3dDevice != NULL ) 
        g_pd3dDevice->Release();
        
    if( g_pD3D != NULL )
        g_pD3D->Release();

    if( g_pFont )
    {
        delete g_pFont;
        g_pFont = NULL;
    }
}
Beispiel #22
0
void ReleaseImg()
{
	// 释放贴图列表
	for(int i=0;i<65535;i++)
	{
		texlist *sch = texlist_headp[i];
		while(sch)
		{
			sch->tex->tex->Release();
			texlist *tmp = sch;
			sch = sch->next;
			delete tmp;
		}
	}

	// 释放顶点缓存
	if( lpVB != NULL )
		lpVB->Release();

	// 释放化着色器资源
	ReleaseEffect();
}
Beispiel #23
0
//-----------------------------------------------------------------------------
// Desc: 释放除创建的对象
//-----------------------------------------------------------------------------
VOID Cleanup()
{
	//释放纹理对象1
	if( g_pTexture1 != NULL )        
		g_pTexture1->Release();

	//释放纹理对象2
	if( g_pTexture2 != NULL ) 
		g_pTexture2->Release();

	//释放顶点缓冲区对象
	if( g_pVB != NULL )        
		g_pVB->Release();

	//释放Direct3D设备对象
	if( g_pd3dDevice != NULL ) 
		g_pd3dDevice->Release();

	//释放Direct3D对象
	if( g_pD3D != NULL )       
		g_pD3D->Release();
}
HRESULT ResetDevice(D3DPRESENT_PARAMETERS d3dpp)
{
	// Check device state
	HRESULT hr = g_pd3dDevice->TestCooperativeLevel() ;

	// Device can be reset now
	if (SUCCEEDED(hr) || hr == D3DERR_DEVICENOTRESET)
	{
		// Release resource allocated as D3DPOOL_DEFAULT
		g_pVB->Release();

		// Reset device
		HRESULT hr = g_pd3dDevice->Reset(&d3dpp) ;
		if (FAILED(hr))
		{
			const CHAR* errorString = DXGetErrorString(hr) ;
			DXTRACE_ERR_MSGBOX(errorString, hr) ;
		}

		// Recreate the vertex buffer, since it is create by using
		// D3DPOOL_DEFAULT, the function MUST placed here!!! why?
		// you cann't place it before the return clause of this function
		// what's the inner cause?
		InitVB();
	}
	// Device is still in lost state, wait
	else if (hr == D3DERR_DEVICELOST)
	{
		Sleep(25) ;
	}
	else // Other error, Show error box
	{
		const CHAR* errorString = DXGetErrorString(hr) ;
		DXTRACE_ERR_MSGBOX(errorString, hr) ;
	}

	return hr ;
}
void ImGui_ImplDX9_InvalidateDeviceObjects()
{
    if (!g_pd3dDevice)
        return;
    if (g_pVB)
    {
        g_pVB->Release();
        g_pVB = NULL;
    }
    if (g_pIB)
    {
        g_pIB->Release();
        g_pIB = NULL;
    }

    // At this point note that we set ImGui::GetIO().Fonts->TexID to be == g_FontTexture, so clear both.
    ImGuiIO& io = ImGui::GetIO();
    IM_ASSERT(g_FontTexture == io.Fonts->TexID);
    if (g_FontTexture)
        g_FontTexture->Release();
    g_FontTexture = NULL;
    io.Fonts->TexID = NULL;
}
Beispiel #26
0
VOID cleanup(){
	if(g_pMeshMaterials != NULL)
		delete [] g_pMeshMaterials;

	if(g_pMeshTextures){
		for(DWORD i=0; i<g_dwNumMaterials; ++i){
			if(g_pMeshTextures[i])
				g_pMeshTextures[i]->Release();
		}
		delete [] g_pMeshTextures;
	}

	if(g_pMesh != NULL)
		g_pMesh->Release();

	if(g_pShutter != NULL)
		g_pShutter->Release();

	if(g_pDevice != NULL)
		g_pDevice->Release();

	if(g_pD3D != NULL)
		g_pD3D->Release();
}
/************************************************************
Render

Renders the water to the screen relative to the currect origin.
Doesnt do any translations on the matrix.  Each row is done
in one individual triangular strip (so all interior vertices are
done twice :-|  I do not believe it is possible to do it all
as one triangular strip (and have every vertex specified once).
************************************************************/
void WaterField::Render()
{
	int i, j, k;
  
  if (!m_textureMode)
  {
	  COLORVERTEX* pVertices;
    //for(int l=0;l<2;l++)
	  for(i=0; i<myXdivs-1; i++)
	  {
		  //Get a pointer to the vertex buffer vertices and lock the vertex buffer
		  g_pVertexBuffer->Lock(0, 2 * myYdivs*  sizeof(COLORVERTEX), (void **) &pVertices, 0);

		  for(j=0; j<myYdivs; j++)
		  {
			  for (k=0; k<2; k++)
			  {
			    pVertices[2*j+k].x = myXmin + (float)((i+k)*m_xdivdist);//+ (float)((j)*m_xdivdist)/2.0f;
			    pVertices[2*j+k].y = myYmin + (float)(j*m_ydivdist);
			    pVertices[2*j+k].z = (float)(myPoints[i+k][j].height);
          pVertices[2*j+k].nx = myPoints[i+k][j].normal.x;
          pVertices[2*j+k].ny = myPoints[i+k][j].normal.y;
          pVertices[2*j+k].nz = myPoints[i+k][j].normal.z;
          pVertices[2*j+k].color = *((DWORD*)&(myPoints[i+k][j].color));
			  }
		  }
		  //Unlock the vertex buffer
		  g_pVertexBuffer->Unlock();
			// Draw it
      g_pd3dDevice->SetFVF(D3DFVF_COLORVERTEX);
      g_pd3dDevice->SetStreamSource(0, g_pVertexBuffer, 0, sizeof(COLORVERTEX));
		  g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2*(myYdivs-1));
      //g_pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2*(myYdivs-1), g_pVertexBuffer, sizeof(COLORVERTEX));
	  }
  }
  else
  {
    TEXTUREDVERTEX* pVertices;
    //for(int l=0;l<2;l++)
	  for(i=0; i<myXdivs-1; i++)
	  {
		  //Get a pointer to the vertex buffer vertices and lock the vertex buffer
		  g_pVertexBuffer->Lock(0, 2 * myYdivs*  sizeof(TEXTUREDVERTEX), (void**)&pVertices, 0);

		  for(j=0; j<myYdivs; j++)
		  {
			  for (k=0; k<2; k++)
			  {
			    pVertices[2*j+k].x = myXmin + (float)((i+k)*m_xdivdist);//+ (float)((j)*m_xdivdist)/2.0f;
			    pVertices[2*j+k].y = myYmin + (float)(j*m_ydivdist);
			    pVertices[2*j+k].z = (float)(myPoints[i+k][j].height);
          pVertices[2*j+k].nx = myPoints[i+k][j].normal.x;
          pVertices[2*j+k].ny = myPoints[i+k][j].normal.y;
          pVertices[2*j+k].nz = myPoints[i+k][j].normal.z;
          pVertices[2*j+k].tu = 0.0f+1.0f*(float)(i+k)/(float)myXdivs + 0.5f*myPoints[i+k][j].normal.x;
          pVertices[2*j+k].tv = 0.0f+1.0f*(float)j/(float)myYdivs + 0.5f*myPoints[i+k][j].normal.y;
			  }
		  }
		  //Unlock the vertex buffer
		  g_pVertexBuffer->Unlock();
			// Draw it
      g_pd3dDevice->SetFVF(D3DFVF_TEXTUREDVERTEX);
      g_pd3dDevice->SetStreamSource(0, g_pVertexBuffer, 0, sizeof(TEXTUREDVERTEX));
		  g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2*(myYdivs-1));
	  }
  }
}
WaterField::~WaterField()
{
	g_pVertexBuffer->Release();
}
 ~PMDDataDx9()
 {
     if(m_Material) delete[] m_Material;
     if(m_IndexBuffer)  m_IndexBuffer->Release();
     if(m_VertexBuffer) m_VertexBuffer->Release();
 }
HRESULT CreateCube()
{
    // The vertex order in each face is in the following order when you
    // look at the face perpendicular against it's normal
    // bottom left -> bottom right -> top right -> top left
    // So you need to set the cull mode as D3DCULL_CW, since the default mode is D3DCULL_CCW
    Vertex vertices[] =
    {
        // Front face
        { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f }, // 0
        { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f }, // 1
        { 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f }, // 2
        { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f }, // 3

        // Back face
        { 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f },
        { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f },
        { 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f },
        { 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f },

        // Left face
        { 0.0f, 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f },
        { 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f },
        { 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f },
        { 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f },

        // Right face
        { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f },
        { 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f },
        { 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f },
        { 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f },

        // Top face
        { 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f },
        { 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f },
        { 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f },
        { 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f },

        // Bottom face
        { 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f },
        { 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f },
        { 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f },
        { 1.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f },
    } ;

    // Index buffer
    WORD indices[] =
    {
        // Front side
        0, 1, 2, 0, 2, 3,

        // Back side
        4, 5, 6, 4, 6, 7,

        // Top side
        8, 9, 10, 8, 10, 11,

        // Bottom side
        12, 13, 14, 12, 14, 15,

        // Left side
        16, 17, 18, 16, 18, 19,

        // Right side
        20, 21, 22, 20, 22, 23,
    } ;

    // Create vertex buffer
    if( FAILED( g_pd3dDevice->CreateVertexBuffer( sizeof(vertices) * sizeof(Vertex),
                D3DUSAGE_WRITEONLY,
                VERTEX_FVF,
                D3DPOOL_MANAGED,
                &g_pVB,
                NULL ) ) )
    {
        return E_FAIL;
    }

    // Copy vertex data
    VOID* pVertices;
    if( FAILED( g_pVB->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) )
        return E_FAIL;
    memcpy( pVertices, vertices, sizeof(vertices) );
    g_pVB->Unlock();

    // Create index buffer
    if( FAILED( g_pd3dDevice->CreateIndexBuffer( sizeof(indices) * sizeof(WORD),
                D3DUSAGE_WRITEONLY,
                D3DFMT_INDEX16,
                D3DPOOL_MANAGED,
                &g_pIB,
                0) ) )
    {
        return E_FAIL ;
    }

    // Copy index data
    VOID *pIndices;
    if( FAILED( g_pIB->Lock( 0, sizeof(indices), (void **)&pIndices, 0) ) )
        return E_FAIL;
    memcpy(pIndices, indices, sizeof(indices) );
    g_pIB->Unlock() ;
}