Esempio n. 1
0
void	cTexBuf::Create( int nWidthSize, int nHeightSize )
{
	m_nWidth	=	nWidthSize;
	m_nHeight	=	nHeightSize;

	
	D3DXCreateTexture( DXUTGetD3D9Device()
		, m_nWidth
		, m_nHeight
		, 1
		, D3DUSAGE_RENDERTARGET
		, D3DFMT_A8R8G8B8
		, D3DPOOL_DEFAULT
		, &m_pTexture );

	m_pTexture->GetSurfaceLevel( 0, &m_pRenderTarget );

	DXUTGetD3D9Device()->GetRenderTarget( 0, &m_pOriRenderTarget );
	DXUTGetD3D9Device()->GetDepthStencilSurface( &m_pOriDepthSurface );

	D3DSURFACE_DESC dsc;
	m_pOriDepthSurface->GetDesc( &dsc );

	DXUTGetD3D9Device()->CreateDepthStencilSurface(
		  m_nWidth
		, m_nHeight
		, dsc.Format
		, D3DMULTISAMPLE_NONE
		, 0
		, true
		, &m_pDepthSurface
		, NULL );
}
Esempio n. 2
0
//--------------------------------------------------------------------------------------
// Create any D3D9 resources that will live through a device reset (D3DPOOL_MANAGED)
// and aren't tied to the back buffer size
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc,
                                 void* pUserContext )
{
	if ( FAILED( DXUTCreateD3D9Sprite( pd3dDevice )))
		 WARN( L"Failed to create sprite device." );

	DXUTGetD3D9Device( )->SetRenderState( D3DRS_ANTIALIASEDLINEENABLE, TRUE );
	DXUTGetD3D9Device( )->SetRenderState( D3DRS_MULTISAMPLEANTIALIAS, TRUE );

	DXUTGetD3D9Device( )->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
	DXUTGetD3D9Device( )->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATER );
	DXUTGetD3D9Device( )->SetRenderState( D3DRS_ALPHAREF, 0 );
	DXUTGetD3D9Device( )->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
	DXUTGetD3D9Device( )->SetRenderState( D3DRS_BLENDOP, D3DBLENDOP_ADD );
	DXUTGetD3D9Device( )->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
	DXUTGetD3D9Device( )->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
	DXUTGetD3D9Device( )->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
	
	// Manager
	Fade.Initialize( );
	Scene.Initialize( );
	Font.Initialize( 1280 );

	g_pNonClient = std::auto_ptr<CNonClient>( new CNonClient );
    
	return S_OK;
}
Esempio n. 3
0
// 
// BitmapSprite::VOnRestore - Chapter 10, page 322
//
HRESULT BitmapSprite::VOnRestore()
{
	if (FAILED (Sprite::VOnRestore() ) )
	{
		return E_FAIL;
	}

	SAFE_RELEASE(m_pTexture);

    D3DXIMAGE_INFO imageInfo;
	ZeroMemory(&imageInfo, sizeof(D3DXIMAGE_INFO));

	if (m_bInCache)
	{
		Resource resource(m_fileName.c_str());
		shared_ptr<ResHandle> texture = g_pApp->m_ResCache->GetHandle(&resource);
		if ( FAILED ( D3DXCreateTextureFromFileInMemoryEx( 
			DXUTGetD3D9Device(), // device
			texture->Buffer(),		// source data
			texture->Size(),	// source data size
			D3DX_DEFAULT,		// width - get it from the file
			D3DX_DEFAULT,		// height - get it from the file
			D3DX_DEFAULT,		// miplevels - get it from the file
			0,					// useage - default (not a render target or dynamic)
			D3DFMT_UNKNOWN,		// format - get it from the file
			D3DPOOL_DEFAULT,	// pool - use default
			D3DX_FILTER_NONE,	// filter - don't use any filter
			D3DX_DEFAULT,		// mip filter - use default
			g_Transparent,		// color key - use our transparent color
			&imageInfo,			// grab the source info
			NULL,				// palleteindex - we don't need it
			&m_pTexture ) ) )	// the texture pointer
			return false;
	}
	else
	{
		if ( FAILED ( D3DXCreateTextureFromFileExA ( 
			DXUTGetD3D9Device(), 
			m_fileName.c_str(),	// source file name
			D3DX_DEFAULT,		// width - get it from the file
			D3DX_DEFAULT,		// height - get it from the file
			D3DX_DEFAULT,		// miplevels - get it from the file
			0,					// useage - default (not a render target or dynamic)
			D3DFMT_UNKNOWN,		// format - get it from the file
			D3DPOOL_DEFAULT,	// pool - use default
			D3DX_FILTER_NONE,	// filter - don't use any filter
			D3DX_DEFAULT,		// mip filter - use default
			g_Transparent,		// color key - use our transparent color
			&imageInfo,			// grab the source info
			NULL,				// palleteindex - we don't need it
			&m_pTexture ) ) )	// the texture pointer
			return false;
	}

	m_TextureWidth = m_Width = imageInfo.Width;
	m_TextureHeight = m_Height = imageInfo.Height / m_NumFrames;
	GCC_ASSERT(m_Height * m_NumFrames == imageInfo.Height && _T("Sprite height error"));

	return true;
}
Esempio n. 4
0
//--------------------------------------------------------------------------------------
// Handles the GUI events
//--------------------------------------------------------------------------------------
void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext )
{

    switch( nControlID )
    {
        case IDC_TOGGLEFULLSCREEN:
            DXUTToggleFullScreen(); break;
        case IDC_TOGGLEREF:
            DXUTToggleREF(); break;
        case IDC_CHANGEDEVICE:
            g_SettingsDlg.SetActive( !g_SettingsDlg.IsActive() ); break;

        case IDC_ENABLE_PRESHADER:
        {
            g_bEnablePreshader = g_SampleUI.GetCheckBox( IDC_ENABLE_PRESHADER )->GetChecked();

            if( DXUTGetD3D9Device() != NULL )
            {
                OnLostDevice( NULL );
                OnDestroyDevice( NULL );
                OnCreateDevice( DXUTGetD3D9Device(), DXUTGetD3D9BackBufferSurfaceDesc(), NULL );
                OnResetDevice( DXUTGetD3D9Device(), DXUTGetD3D9BackBufferSurfaceDesc(), NULL );
            }
            break;
        }

        case IDC_ACTIVE_LIGHT:
            if( !g_LightControl[g_nActiveLight].IsBeingDragged() )
            {
                g_nActiveLight++;
                g_nActiveLight %= g_nNumActiveLights;
            }
            break;

        case IDC_NUM_LIGHTS:
            if( !g_LightControl[g_nActiveLight].IsBeingDragged() )
            {
                WCHAR sz[100];
                swprintf_s( sz, 100, L"# Lights: %d", g_SampleUI.GetSlider( IDC_NUM_LIGHTS )->GetValue() );
                g_SampleUI.GetStatic( IDC_NUM_LIGHTS_STATIC )->SetText( sz );

                g_nNumActiveLights = g_SampleUI.GetSlider( IDC_NUM_LIGHTS )->GetValue();
                g_nActiveLight %= g_nNumActiveLights;
            }
            break;

        case IDC_LIGHT_SCALE:
            g_fLightScale = ( float )( g_SampleUI.GetSlider( IDC_LIGHT_SCALE )->GetValue() * 0.10f );

            WCHAR sz[100];
            swprintf_s( sz, 100, L"Light scale: %0.2f", g_fLightScale );
            g_SampleUI.GetStatic( IDC_LIGHT_SCALE_STATIC )->SetText( sz );
            break;
    }

}
Esempio n. 5
0
//
// MeshNode::VOnRestore				-  3rd Edition, Chapter 14, page 506
//
// This function loads the Mesh and ensures the Mesh has normals; it also optimizes the 
// Mesh for the graphics card's vertex cache, which improves performance by organizing 
// the internal triangle list for less cache misses.
//
HRESULT D3DMeshNode9::VOnRestore(Scene *pScene)
{
	if (m_XFileName.empty())
	{
		SetRadius(CalcBoundingSphere());
		return D3DSceneNode9::VOnRestore(pScene);
	}

	// Change post press - release the Mesh only if we have a valid Mesh file name to load.
	// Otherwise we likely created it on our own, and needs to be kept.
	SAFE_RELEASE(m_pMesh);

    WCHAR str[MAX_PATH];
    HRESULT hr;

    // Load the Mesh with D3DX and get back a ID3DXMesh*.  For this
    // sample we'll ignore the X file's embedded materials since we know 
    // exactly the model we're loading.  See the Mesh samples such as
    // "OptimizedMesh" for a more generic Mesh loading example.
	V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, m_XFileName.c_str() ) );

    V_RETURN( D3DXLoadMeshFromX(str, D3DXMESH_MANAGED, DXUTGetD3D9Device(), NULL, NULL, NULL, NULL, &m_pMesh) );

    DWORD *rgdwAdjacency = NULL;

    // Make sure there are normals which are required for lighting
    if( !(m_pMesh->GetFVF() & D3DFVF_NORMAL) )
    {
        ID3DXMesh* pTempMesh;
        V( m_pMesh->CloneMeshFVF( m_pMesh->GetOptions(), 
                                  m_pMesh->GetFVF() | D3DFVF_NORMAL, 
                                  DXUTGetD3D9Device(), &pTempMesh ) );
        V( D3DXComputeNormals( pTempMesh, NULL ) );

        SAFE_RELEASE( m_pMesh );
        m_pMesh = pTempMesh;
    }

    // Optimize the Mesh for this graphics card's vertex cache 
    // so when rendering the Mesh's triangle list the vertices will 
    // cache hit more often so it won't have to re-execute the vertex shader 
    // on those vertices so it will improve perf.     

    rgdwAdjacency = GCC_NEW DWORD[m_pMesh->GetNumFaces() * 3];
    if( rgdwAdjacency == NULL )
        return E_OUTOFMEMORY;
    V( m_pMesh->ConvertPointRepsToAdjacency(NULL, rgdwAdjacency) );
    V( m_pMesh->OptimizeInplace(D3DXMESHOPT_VERTEXCACHE, rgdwAdjacency, NULL, NULL, NULL) );
    
	SAFE_DELETE_ARRAY(rgdwAdjacency);

	SetRadius(CalcBoundingSphere());

    return D3DSceneNode9::VOnRestore(pScene);
}
HRESULT D3DSkyNode9::Render(Scene* pScene)
{
	// blend the texture with the color of the vertices

	DXUTGetD3D9Device()->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
	DXUTGetD3D9Device()->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
	DXUTGetD3D9Device()->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);

	DXUTGetD3D9Device()->SetStreamSource(0, m_pVerts, 0, sizeof(D3D9Vertex_ColoredTextured));
	DXUTGetD3D9Device()->SetFVF(D3D9Vertex_ColoredTextured::FVF);

	for (DWORD side = 0; side < m_Sides; side++)
	{
		std::string name = GetTextureName(side);

		Resource resource(name);
		shared_ptr<ResHandle> texture = g_pApp->m_ResCache->GetHandle(&resource);
		shared_ptr<D3DTextureResourceExtraData9> extra = static_pointer_cast<D3DTextureResourceExtraData9>(texture->GetExtra());
		
		DXUTGetD3D9Device()->SetTexture(0, extra->GetTexture());
		DXUTGetD3D9Device()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 4 * side, 2);
	}

	DXUTGetD3D9Device()->SetTexture(0, NULL);
	return S_OK;
}
void DisplayObject::Render(){
			
    //Meshes are divided into subsets, one for each material. Render them in
    //a loop
	DXUTGetD3D9Device()->SetTransform(D3DTS_WORLD, &(m_world));	//Set world matrix
    for( DWORD i = 0; i < m_numMaterials; i++ )
    {
        // Set the material and texture for this subset
        DXUTGetD3D9Device()->SetMaterial( &m_meshMaterials[i] );
        DXUTGetD3D9Device()->SetTexture( 0, m_meshTextures[i] );

        // Draw the mesh subset
        m_mesh->DrawSubset( i );
    }
}
Esempio n. 8
0
void CShowPoints9::Draw(const D3DXMATRIX& WorldMatrix)
{
    HRESULT hr = S_OK;

    if(!SkinnedVB)
        return;

    IDirect3DDevice9* device = DXUTGetD3D9Device();


    V( Effect->SetMatrix( "World", &WorldMatrix) );
    V( Effect->SetMatrix( "View", DXVGetCamera().GetViewMatrix() ));
    V( Effect->SetMatrix( "Projection", DXVGetCamera().GetProjMatrix() ));
    V( Effect->SetVector( "Color", &D3DXVECTOR4(1.0f,1.0f,0.0f,1.0f)) );

    V( Effect->SetTechnique( Effect->GetTechnique(0)) );

    UINT numPasses;
    V( Effect->Begin( &numPasses, 0 ));

    for( UINT iPass = 0; iPass < numPasses; iPass++ )
    {
        V( Effect->BeginPass( iPass ) );

        V( device->SetVertexDeclaration( Declaration ) );
        V( device->SetStreamSource(0, SkinnedVB, 0 , Stride ) );

        V( device->DrawPrimitive( D3DPT_POINTLIST, 0, NumPoints) );

        V( Effect->EndPass() );
    }
    V( Effect->End() );
}
Esempio n. 9
0
/**
 * @brief 敵を描画する
 *
 */
void Enemy::render()
{
    LPDIRECT3DDEVICE9 pDevice = DXUTGetD3D9Device();

    D3DXMATRIXA16 worldMatrix;
    D3DXMatrixTranslation(&worldMatrix, m_position.x, m_position.y, m_position.z);
    pDevice->SetTransform(D3DTS_WORLD, &worldMatrix);

    for (DWORD i = 0; i < s_numberOfMaterials; ++i) {
        if (this->isDead()) {
            if (m_dieOutTime <= 0) {
                return;
            }

            // 死亡時は、消滅するまで徐々に赤から色を黒くしていく
            D3DMATERIAL9 deadMaterial = s_deadMaterial;
            float red = m_dieOutTime / GameConfiguration::s_ENEMY_DIE_OUT_TIME;
            if (red < 0.50f) {
                red = 0.5f;
            }
            deadMaterial.Diffuse.r = deadMaterial.Ambient.r = red;
            pDevice->SetMaterial(&deadMaterial);
        }
        else {
            pDevice->SetMaterial(&s_meshMaterials.at(i));
        }
        pDevice->SetTexture(0, s_meshTexturePointers.at(i));

        s_pMesh->DrawSubset(i);
    }

#ifdef DEBUG
    s_debugCollision.render();
#endif
}
shared_ptr<SceneNode> SphereRenderComponent::CreateSceneNode()
{
	// get the transform
	shared_ptr<TransformComponent> pTransformComponent = MakeStrongPtr(m_pOwner->GetComponent<TransformComponent>(TransformComponent::g_Name));
	if (!pTransformComponent)
	{
		// can't render without a transform
		return shared_ptr<SceneNode>();
	}

	WeakBaseRenderComponentPtr weakThis(this);
	if (WindowsApp::GetRendererImpl() == WindowsApp::Renderer_D3D9)
	{
		// create the sphere Mesh
		ID3DXMesh* pSphereMesh;

		D3DXCreateSphere(DXUTGetD3D9Device(), m_Radius, m_Segments, m_Segments, &pSphereMesh, NULL);

		shared_ptr<SceneNode> sphere(CB_NEW D3DShaderMeshNode9(m_pOwner->GetId(), weakThis, pSphereMesh, "Effects\\Main.fx", RenderPass_Object, &pTransformComponent->GetTransform()));

		SAFE_RELEASE(pSphereMesh);
		return sphere;
	}
	else if (WindowsApp::GetRendererImpl() == WindowsApp::Renderer_D3D11)
	{
		shared_ptr<SceneNode> sphere(CB_NEW D3DShaderMeshNode11(m_pOwner->GetId(), weakThis, "art\\sphere.sdkmesh", RenderPass_Object, &pTransformComponent->GetTransform()));
		return sphere;
	}
	else
	{
		CB_ASSERT(0 && "Unknown Renderer Implementation in SphereRenderComponent::VCreateSceneNode");
		return shared_ptr<SceneNode>(NULL);
	}
}
Esempio n. 11
0
//-------------------------------------------------
// Name: MODIFIERS
// Desc:
//-------------------------------------------------
HRESULT cprimitive::SetLength(float g_fLength)
{
	HRESULT hr;
	LPDIRECT3DDEVICE9 pd3dDevice = DXUTGetD3D9Device();
	fLength = g_fLength;

	CUSTOMVERTEX vertices[] =
    {
		{ -fWidth, 0.0f, -fWidth, 0.f, 0.f,},
        { fWidth, 0.0f, -fWidth, 1.f, 0.f,},
        { fWidth, fLength, -fWidth, 1.f, 1.f,},
		{ -fWidth, fLength, -fWidth, 0.f, 1.f, },
		{ -fWidth, 0.0f, fWidth, 0.f, 0.f,},
        { fWidth, 0.0f, fWidth, 1.f, 0.f,},
        { fWidth, fLength, fWidth, 1.f, 1.f,},
		{ -fWidth, fLength, fWidth, 0.f, 1.f,},
		
    };
	m_numVertices = sizeof(vertices)/sizeof(CUSTOMVERTEX);


    // Create the vertex buffer	
	CUSTOMVERTEX* pVertices;
	pMesh->LockVertexBuffer(D3DLOCK_DISCARD, (void**)&pVertices);

    memcpy( pVertices, vertices, sizeof(vertices) );

	pMesh->UnlockVertexBuffer();

	return S_OK;

}
Esempio n. 12
0
void	cPostMgr::Render()
{
	BlurRender();
	this->BeginBulr();

	DXUTGetD3D9Device()->Clear( 0L, NULL
	,   D3DCLEAR_ZBUFFER
	, D3DCOLOR_ARGB( 256, 0, 0, 0 ), 1.0f, 0L );
	if( m_fBlurClearTime > 0.15f )
	{
		m_fBlurClearTime	= 0.0f	;
		DXUTGetD3D9Device()->Clear( 0L, NULL
		,  D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER
		, D3DCOLOR_ARGB( 256, 45, 50, 170 ), 1.0f, 0L );
	}
	this->EndBlur();
}
Esempio n. 13
0
//
// Frustum::Render					- Chapter 14, page 489
//
void Frustum::Render()
{
	COLORED_VERTEX verts[24];
	for (int i=0; i<8; ++i)
	{
		verts[i].color = g_White;
	}

	for (int i=0; i<8; ++i)
	{
		verts[i+8].color = g_Red;
	}

	for (int i=0; i<8; ++i)
	{
		verts[i+16].color = g_Blue;
	}


	// Draw the near clip plane
	verts[0].position = m_NearClip[0];	verts[1].position = m_NearClip[1];
	verts[2].position = m_NearClip[1];	verts[3].position = m_NearClip[2];
	verts[4].position = m_NearClip[2];	verts[5].position = m_NearClip[3];
	verts[6].position = m_NearClip[3];	verts[7].position = m_NearClip[0];

	// Draw the far clip plane
	verts[8].position = m_FarClip[0];	verts[9].position = m_FarClip[1];
	verts[10].position = m_FarClip[1];	verts[11].position = m_FarClip[2];
	verts[12].position = m_FarClip[2];	verts[13].position = m_FarClip[3];
	verts[14].position = m_FarClip[3];	verts[15].position = m_FarClip[0];

	// Draw the edges between the near and far clip plane
	verts[16].position = m_NearClip[0];	verts[17].position = m_FarClip[0];
	verts[18].position = m_NearClip[1];	verts[19].position = m_FarClip[1];
	verts[20].position = m_NearClip[2];	verts[21].position = m_FarClip[2];
	verts[22].position = m_NearClip[3];	verts[23].position = m_FarClip[3];

	DWORD oldLightMode;
	DXUTGetD3D9Device()->GetRenderState( D3DRS_LIGHTING, &oldLightMode );
	DXUTGetD3D9Device()->SetRenderState( D3DRS_LIGHTING, FALSE );

    DXUTGetD3D9Device()->SetFVF( COLORED_VERTEX::FVF );
	DXUTGetD3D9Device()->DrawPrimitiveUP( D3DPT_LINELIST, 12, verts, sizeof(COLORED_VERTEX) );

	DXUTGetD3D9Device()->SetRenderState( D3DRS_LIGHTING, oldLightMode );
}
Esempio n. 14
0
		bool CVideoDriverDX9::initDriver( const core::dimension2d<u32>& screenSize, HWND hwnd, u32 bits, bool fullScreen, bool pureSoftware, bool highPrecisionFPU, bool vsync, u8 antiAlias )
		{
			DXUTSetCursorSettings( true, true );
			DXUTCreateDevice( !fullScreen, screenSize.Width,screenSize.Height );
			this->pID3D=DXUTGetD3D9Object();
			this->pID3DDevice=DXUTGetD3D9Device();
			pID3DDevice->SetFVF(D3DFVF_XYZ);
			return true;
		}
Esempio n. 15
0
//
// ShaderMeshNode::VOnRestore					- very similar to MeshNode::VOnRestore
//
HRESULT D3DShaderMeshNode9::VOnRestore(Scene *pScene)
{
	SAFE_RELEASE(m_pEffect);

	DWORD dwShaderFlags = D3DXFX_NOT_CLONEABLE | D3DXSHADER_DEBUG | D3DXSHADER_NO_PRESHADER;
	HRESULT hr;

    Resource resource(m_fxFileName);
    shared_ptr<ResHandle> pResourceHandle = g_pApp->m_ResCache->GetHandle(&resource);  // this actually loads the XML file from the zip file
	V ( D3DXCreateEffect( DXUTGetD3D9Device(), pResourceHandle->Buffer(), pResourceHandle->Size(), NULL, NULL, dwShaderFlags, NULL, &m_pEffect, NULL ) );
	return D3DMeshNode9::VOnRestore(pScene);
}
Esempio n. 16
0
//--------------------------------------------------------------------------------------
// Create any D3D9 resources that will live through a device reset (D3DPOOL_MANAGED)
// and aren't tied to the back buffer size
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D9CreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc,
                                     void* pUserContext )
{
    HRESULT hr;

	D3DXCreateSprite( DXUTGetD3D9Device(), &g_pSprite9 );

    V_RETURN( g_DialogResourceManager.OnD3D9CreateDevice( pd3dDevice ) );
    V_RETURN( g_SettingsDlg.OnD3D9CreateDevice( pd3dDevice ) );

	g_pMain	=	new	cMain;
	g_pMain->Init();
	
    return S_OK;
}
Esempio n. 17
0
//
// D3DSkyNode9::VRender				- Chapter 14, page 502
//
HRESULT D3DSkyNode9::VRender(Scene *pScene)
{

	// Setup our texture. Using textures introduces the texture stage states,
    // which govern how textures get blended together (in the case of multiple
    // textures) and lighting information. In this case, we are modulating
    // (blending) our texture with the diffuse color of the vertices.

    DXUTGetD3D9Device()->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
    DXUTGetD3D9Device()->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
    DXUTGetD3D9Device()->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

	DXUTGetD3D9Device()->SetStreamSource( 0, m_pVerts, 0, sizeof(D3D9Vertex_ColoredTextured) );
	DXUTGetD3D9Device()->SetFVF( D3D9Vertex_ColoredTextured::FVF );

	for (DWORD side = 0; side < m_sides; side++)
	{
		// FUTURE WORK: A good optimization would be to transform the camera's
		// world look vector into local space, and do a dot product. If the
		// result is positive, we shouldn't draw the side since it has to be
		// behind the camera!

		// Sky boxes aren't culled by the normal mechanism

		std::string name = GetTextureName(side);

		/***
		// [mrmike] - This was slightly changed post press, look at the lines below this commented out code
		const char *suffix[] = { "_n.jpg", "_e.jpg",  "_s.jpg",  "_w.jpg",  "_u.jpg" };
		name += suffix[side];
		****/
		
		Resource resource(name);
		shared_ptr<ResHandle> texture = g_pApp->m_ResCache->GetHandle(&resource);
		shared_ptr<D3DTextureResourceExtraData9> extra = static_pointer_cast<D3DTextureResourceExtraData9>(texture->GetExtra());

		DXUTGetD3D9Device()->SetTexture( 0, extra->GetTexture() );
		DXUTGetD3D9Device()->DrawPrimitive( D3DPT_TRIANGLESTRIP , 4 * side, 2);
	}

	DXUTGetD3D9Device()->SetTexture (0, NULL);
	return S_OK;
}
Esempio n. 18
0
void CALLBACK MouseProc(bool bLeftButtonDown, bool bRightButtonDown, bool bMiddleButtonDown, bool bSideButton1Down, bool bSideButton2Down, int nMouseWheelDelta, int xPos, int yPos, void* pUserContext)
{
    if(bLeftButtonDown)
    {
        NsCell cell = g_Board.GetCellAtPoint(DXUTGetD3D9Device(), xPos, yPos);

        g_Board.PerformMove(g_Board.GetActiveColor(), cell.iRow, cell.iColumn);

		if(g_Board.pRenjuGame->bGameIsFinished)
		{
			g_HUD.GetButton(IDC_RESETGAME)->SetText(L"Start");

			g_SampleUI.GetRadioButton(IDC_GAMEMODE_HUMAN_HUMAN_RADIO)->SetVisible(true);
			g_SampleUI.GetRadioButton(IDC_GAMEMODE_AI_IS_BLACK_RADIO)->SetVisible(true);
			g_SampleUI.GetRadioButton(IDC_GAMEMODE_AI_IS_WHITE_RADIO)->SetVisible(true);
		}
    }
}
Esempio n. 19
0
	/**
	 * @brief メッシュの読み込み
	 *
	 */
	void AnimationManager::loadMeshHierarchyFromX(const acut::TString& meshFilePath)
	{
		try {
			// mesh 読み込み
			V_THROW(D3DXLoadMeshHierarchyFromX(
				meshFilePath.c_str(),
				D3DXMESH_MANAGED,
				DXUTGetD3D9Device(),
				&m_allocateHierarchy,
				NULL,
				reinterpret_cast<LPD3DXFRAME*>(&m_pRootFrame),
				&m_pAnimationController
			));

			// ボーン変換行列へのポインタをセット
			V_THROW(this->setupBoneMatrixPointers(m_pRootFrame));

			// animation controller の trackを全てFALSEにする
			DWORD numTracks = m_pAnimationController->GetMaxNumTracks();
			DEBUG_OUTPUTF("m_pAnimationController->GetMaxNumTracks() : %d\n", numTracks);
			for (DWORD i = 0; i < numTracks; ++i) {
				V_THROW(m_pAnimationController->SetTrackEnable(i, FALSE));
			}

			V_THROW(this->createAnimationSetList());

			try {
				// tyny_4anim.xの場合
				// 0: 手を振る Wave
				// 1: 走る Jog
				// 2: 歩く Walk
				// 3: ふらふらする Loiter
				V_THROW(m_pAnimationController->SetTrackAnimationSet(0, m_animationSetList.at(1)));
				V_THROW(m_pAnimationController->SetTrackEnable(0, TRUE));
			} catch (std::out_of_range& ex) {
				acut::ExceptionHandler::handleException(ex);
				throw acut::Exception(__FILEW__, __LINE__, __FUNCTIONW__);
			}
		} catch (acut::Exception& ex) {
			acut::ExceptionHandler::handleException(ex);
			this->cleanup();
			throw;
		}
	}
Esempio n. 20
0
//
// TeapotMeshNode::VOnRestore						- Chapter X, page Y
//
HRESULT D3DTeapotMeshNode9::VOnRestore(Scene *pScene)
{
	HRESULT hr;

	IDirect3DDevice9 * pDevice = DXUTGetD3D9Device();

	SAFE_RELEASE(m_pMesh);
	V( D3DXCreateTeapot( pDevice, &m_pMesh, NULL ) );

	//Rotate the teapot 90 degrees from default so that the spout faces forward
	Mat4x4 rotateY90;
	rotateY90.BuildRotationY(-GCC_PI / 2.0f);
	IDirect3DVertexBuffer9* pVB = NULL;
	m_pMesh->GetVertexBuffer(&pVB);
	Vec3* pVertices = NULL;
	pVB->Lock( 0, 0, (void**)&pVertices, 0 );
	for (unsigned int i=0; i<m_pMesh->GetNumVertices(); ++i)
	{
		*pVertices = rotateY90.Xform(*pVertices);
		++pVertices;
		//The structs depicted in this vertex buffer actually store
		//information for normals in addition to xyz, thereby
		//making the vertices in pVB twice the size of the one described
		//by *pVertices.  So we address that here.
		*pVertices = rotateY90.Xform(*pVertices);	//rotate the normals, too
		++pVertices;
	}
	pVB->Unlock();
	SAFE_RELEASE( pVB );
	//...end rotation



	// Note - the Mesh is needed BEFORE calling the base class VOnRestore.
	V ( D3DShaderMeshNode9::VOnRestore ( pScene ) );
	return S_OK;
}
Esempio n. 21
0
void	cMainGame::Initialize()
{
	srand(GetTickCount());
	DXUTGetD3D9Device()->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	DXUTGetD3D9Device()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	DXUTGetD3D9Device()->SetRenderState(D3DRS_LIGHTING, false);
	DXUTGetD3D9Device()->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
	DXUTGetD3D9Device()->SetRenderState(D3DRS_FOGENABLE, true);
	DXUTGetD3D9Device()->SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_NONE);
	DXUTGetD3D9Device()->SetRenderState(D3DRS_FOGCOLOR, D3DCOLOR_XRGB( 0, 0, 0));
	DXUTGetD3D9Device()->SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);

	float	fStart = 15.0f;
	float	fEnd = 350.0f;
	float	fDesnity = 0.001f;
	DXUTGetD3D9Device()->SetRenderState(D3DRS_FOGSTART, *((LPDWORD)(&fStart)));
	DXUTGetD3D9Device()->SetRenderState(D3DRS_FOGEND, *((LPDWORD)(&fEnd)));
	DXUTGetD3D9Device()->SetRenderState(D3DRS_FOGDENSITY, *((LPDWORD)(&fDesnity)));

	
	_GETSINGLE(cResourceMgr)->AddAseFile("woman", "Data/woman.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("player", "Data/Player/player.ase");
//	_GETSINGLE(cResourceMgr)->AddAseFile("player_add1", "Data/Player/Add/add 1.ASE");
	_GETSINGLE(cResourceMgr)->AddAseFile("player_add2", "Data/Player/Add/add on 3.ASE");
	_GETSINGLE(cResourceMgr)->AddAseFile("enemy", "Data/Enemy/wjr1.ase");
	
	_GETSINGLE(cResourceMgr)->AddAseFile("enemy2", "Data/Enemy/wjr2.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("enemy3", "Data/Enemy/3/wjr3.ase");
	
	_GETSINGLE(cResourceMgr)->AddAseFile("miniboss", "Data/Enemy/Boss/wndrks boss 1.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("boss", "Data/Monster/boss1.ase");
	
	
	_GETSINGLE(cResourceMgr)->AddAseFile("plan", "Data/plan.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("car1", "Data/Temp/Car1 0.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("player_car", "Data/Car/Player/player car.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("player_car_wheel", "Data/Car/Player/qkznl.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("bullet", "Data/Bullet/chddkf1.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("bullet_enemy1", "Data/Bullet/EnemyBullet/rlqhs wjr attack.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("bullet_enemy2", "Data/Bullet/EnemyBullet/attack1.ase");
	
	_GETSINGLE(cResourceMgr)->AddAseFile("player_gun", "Data/Temp/player gun1.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("effect_boost", "Data/Effect/Boost/fever booster.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("effect_normal_boost", "Data/Effect/Boost/rlqhs booster.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("effect_laser", "Data/Effect/Laser/lazer.ase");
	
	_GETSINGLE(cResourceMgr)->AddTexture("effect_bullet", L"Data/Effect/Effect_Bullet%d.png", 4);
	_GETSINGLE(cResourceMgr)->AddTexture("effect_bomb", L"Data/Effect/Bomb/%d.png", 10);
	_GETSINGLE(cResourceMgr)->AddTexture("effect_item", L"Data/Effect/ItemEff/%d.png", 6);
	_GETSINGLE(cResourceMgr)->AddTexture("effect_shield", L"Data/Effect/shield.PNG" );
	
	
	_GETSINGLE(cResourceMgr)->AddSprite("ui_number", L"Data/Num/%d.png", 10);

	_GETSINGLE(cResourceMgr)->AddSprite("ui_background", L"Data/UI/back.png");
	_GETSINGLE(cResourceMgr)->AddSprite("ui_notice_add", L"Data/UI/add on.png");
	_GETSINGLE(cResourceMgr)->AddSprite("ui_notice_heal", L"Data/UI/HP UP.png");
	_GETSINGLE(cResourceMgr)->AddSprite("ui_notice_missle", L"Data/UI/missile.png");
	_GETSINGLE(cResourceMgr)->AddSprite("ui_notice_power", L"Data/UI/power up.png");
	_GETSINGLE(cResourceMgr)->AddSprite("ui_notice_shield", L"Data/UI/shield.png");
	_GETSINGLE(cResourceMgr)->AddSprite("ui_notice_speed", L"Data/UI/speed up.png");
	_GETSINGLE(cResourceMgr)->AddSprite("ui_notice_warning", L"Data/UI/warning.png");
	_GETSINGLE(cResourceMgr)->AddSprite("ui_notice_st1", L"Data/UI/stage1.png");
	_GETSINGLE(cResourceMgr)->AddSprite("ui_notice_st2", L"Data/UI/stage2.png");
	_GETSINGLE(cResourceMgr)->AddSprite("ui_bar_player", L"Data/UI/player hp.png");
	_GETSINGLE(cResourceMgr)->AddSprite("ui_bar_boss", L"Data/UI/boss hp.png");
	_GETSINGLE(cResourceMgr)->AddSprite("ui_back_hit", L"Data/Effect/Back/xkrur.png");
	_GETSINGLE(cResourceMgr)->AddSprite("ui_back_normal", L"Data/Effect/Back/rlqhs.png");

	_GETSINGLE(cResourceMgr)->AddSprite("ui_main_background", L"Data/UI/Main/main.png");
	_GETSINGLE(cResourceMgr)->AddSprite("ui_fade_background", L"Data/UI/fade.png");
	
	_GETSINGLE(cResourceMgr)->AddSprite("ui_main_about_button", L"Data/UI/Main/about%d.png", 3);
	_GETSINGLE(cResourceMgr)->AddSprite("ui_main_howto_button", L"Data/UI/Main/how to%d.png", 3);
	_GETSINGLE(cResourceMgr)->AddSprite("ui_main_rank_button", L"Data/UI/Main/ranking%d.png", 3);
	_GETSINGLE(cResourceMgr)->AddSprite("ui_main_start_button", L"Data/UI/Main/start%d.png", 3);
	_GETSINGLE(cResourceMgr)->AddSprite("ui_main_rank_bar", L"Data/UI/Main/rankbar.png");
	
	
	
	_GETSINGLE(cResourceMgr)->AddAseFile("structure_stone1", "Data/Strcture/ehf1.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("structure_stone2", "Data/Strcture/ehf2.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("structure_stone3", "Data/Strcture/ehf3.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("structure_stone4", "Data/Strcture/ehf4.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("structure_stone5", "Data/Strcture/ehf5.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("structure_stone6", "Data/Strcture/ehf6.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("structure_stone7", "Data/Strcture/ehf7.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("structure_cylinder1", "Data/Strcture/rlend1.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("structure_cylinder2", "Data/Strcture/rlend2.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("structure_side_stone", "Data/Strcture/side ehf.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("structure_up_stone1", "Data/Strcture/up stone1.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("structure_up_stone2", "Data/Strcture/up stone2.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("structure_box1", "Data/Strcture/st1/boxl.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("structure_box2", "Data/Strcture/st1/box ejal.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("structure_tree", "Data/Strcture/st1/skan.ase");

	_GETSINGLE(cResourceMgr)->AddAseFile("item_add", "Data/Item/item add on.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("item_missle", "Data/Item/item dbeh.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("item_heal", "Data/Item/item hill.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("item_upgrade", "Data/Item/item power up.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("item_shield", "Data/Item/item shield.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("item_speed", "Data/Item/item speed .ase");

	
	
	
	_GETSINGLE(cResourceMgr)->AddAseFile("map", "Data/map/map/map.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("map_left", "Data/map/map/map_left.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("map_right", "Data/map/map/map_right.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("map_under", "Data/map/map/map_under.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("map_up", "Data/map/map/map_up.ase");

	/*
	
	_GETSINGLE(cResourceMgr)->AddAseFile("map_s_front_floor", "Data/map/SectionMap/map floor.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("map_s_front", "Data/map/SectionMap/map.ase");
	
	_GETSINGLE(cResourceMgr)->AddAseFile("map_s_left_floor", "Data/map/SectionMap/map left floor.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("map_s_left", "Data/map/SectionMap/map left.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("map_s_right_floor", "Data/map/SectionMap/map right floor.ase");
	_GETSINGLE(cResourceMgr)->AddAseFile("map_s_right", "Data/map/SectionMap/map right.ase");
	*/

	_GETSINGLE(cResourceMgr)->AddShader(SI_CUSTOM, "SimpleSample.fx");
	_GETSINGLE(cResourceMgr)->AddShader(SI_CREATE, "CreateShadow.fx");
	_GETSINGLE(cResourceMgr)->AddShader(SI_APPLY, "ApplyShadow.fx");
	
	_GETSINGLE(cResourceMgr)->SetPlan(
		_GETSINGLE(cResourceMgr)->GetResource("plan"));
	

	_GETSINGLE(cSystemMgr)->Initialize();
	_GETSINGLE(cObjectMgr)->Initialize();

	_GETSINGLE(cSceneMgr)->Init();


	_GETS(cSceneMgr)->ChangeScene(SI_HOME);
}
HRESULT D3DSkyNode9::OnRestore(Scene* pScene)
{
	// call base class restore
	SceneNode::OnRestore(pScene);

	m_Camera = pScene->GetCamera();
	m_NumVerts = 20;

	CB_COM_RELEASE(m_pVerts);
	if (FAILED(DXUTGetD3D9Device()->CreateVertexBuffer(
		m_NumVerts * sizeof(D3D9Vertex_ColoredTextured),
		D3DUSAGE_WRITEONLY, D3D9Vertex_ColoredTextured::FVF,
		D3DPOOL_MANAGED, &m_pVerts, NULL)))
	{
		return E_FAIL;
	}

	// fill the vertex buffer -- we're setting the tu and tv texture coordinates (0.0 - 1.0)
	// this binds the m_pVerts d3d buffer to pVertices
	D3D9Vertex_ColoredTextured* pVertices;
	if (FAILED(m_pVerts->Lock(0, 0, (void**)&pVertices, 0)))
	{
		return E_FAIL;
	}

	// loop through the grid squares and calculate the values
	// of each index. each grid has two triangles:
	//
	//	A - B
	//	| / |
	//	C - D
	
	D3D9Vertex_ColoredTextured skyVerts[4];
	D3DCOLOR skyVertColor = 0xffffffff;
	float dim = 50.0f;

	skyVerts[0].position = Vec3(dim, dim, dim);
	skyVerts[0].color = skyVertColor;
	skyVerts[0].tu = 1.0f; // top right texture coord
	skyVerts[0].tv = 0.0f;

	skyVerts[1].position = Vec3(-dim, dim, dim);
	skyVerts[1].color = skyVertColor;
	skyVerts[1].tu = 0.0f; // top left texture coord
	skyVerts[1].tv = 0.0f;

	skyVerts[2].position = Vec3(dim, -dim, dim);
	skyVerts[2].color = skyVertColor;
	skyVerts[2].tu = 1.0f; // bottom right texture coord
	skyVerts[2].tv = 1.0f;

	skyVerts[3].position = Vec3(-dim, -dim, dim);
	skyVerts[3].color = skyVertColor;
	skyVerts[3].tu = 0.0f; // bottom left texture coord
	skyVerts[3].tv = 1.0f;

	// triangle
	//	   2
	//	 / |
	//  0--1
	Vec3 triangle[3];
	triangle[0] = Vec3(0.0f, 0.0f, 0.0f);
	triangle[1] = Vec3(5.0f, 0.0f, 0.0f);
	triangle[2] = Vec3(5.0f, 5.0f, 0.0f);
	
	Vec3 edge1 = triangle[1] - triangle[0];
	Vec3 edge2 = triangle[2] - triangle[0];

	Vec3 normal;
	normal = edge1.Cross(edge2);
	normal.Normalize();

	Mat4x4 rotY;
	rotY.BuildRotationY(CB_PI / 2.0f);
	Mat4x4 rotX;
	rotX.BuildRotationX(-CB_PI / 2.0f);

	m_Sides = 5;

	// loop through all the sides of a sky box and set the texture coords
	for (DWORD side = 0; side < m_Sides; side++)
	{
		for (DWORD v = 0; v < 4; v++)
		{
			Vec4 temp;
			if (side < m_Sides - 1)
			{
				temp = rotY.Transform(Vec3(skyVerts[v].position));
			}
			else
			{
				skyVerts[0].tu = 1.0f; skyVerts[0].tv = 1.0f;
				skyVerts[1].tu = 1.0f; skyVerts[1].tv = 0.0f;
				skyVerts[2].tu = 0.0f; skyVerts[2].tv = 1.0f;
				skyVerts[3].tu = 0.0f; skyVerts[3].tv = 0.0f;

				temp = rotX.Transform(Vec3(skyVerts[v].position));
			}
			skyVerts[v].position = Vec3(temp.x, temp.y, temp.z);
		}
		memcpy(&pVertices[side * 4], skyVerts, sizeof(skyVerts));
	}

	m_pVerts->Unlock();
	return S_OK;
}
Esempio n. 23
0
//--------------------------------------------------------------------------------------
// This function loads a new technique and all device objects it requires.
//--------------------------------------------------------------------------------------
HRESULT LoadTechniqueObjects( const char* szMedia )
{
    HRESULT hr = S_OK;

    if( NULL == g_pEffect )
        return D3DERR_INVALIDCALL;

    IDirect3DTexture9* pTexture = NULL;
    IDirect3DCubeTexture9* pCubeTexture = NULL;

    IDirect3DDevice9* pDevice = DXUTGetD3D9Device();

    WCHAR strFileName[MAX_PATH+1] = {0};
    WCHAR strPath[MAX_PATH+1] = {0};
    char strTechnique[MAX_PATH] = {0};

    // Make sure the technique works
    char* strComboTech = ( char* )g_SampleUI.GetComboBox( IDC_TECHNIQUE )->GetSelectedData();
    strcpy_s( strTechnique, MAX_PATH, strComboTech );
    bool bLDPRT = ( strTechnique && ( 0 == strcmp( strTechnique, "LDPRT" ) ) );

    // If we're not a signed format, make sure we use a technnique that will unbias
    if( D3DFMT_Q16W16V16U16 != g_fmtTexture && D3DFMT_Q8W8V8U8 != g_fmtTexture )
        strcat_s( strTechnique, MAX_PATH, "_Unbias" );

    D3DXHANDLE hTechnique = g_pEffect->GetTechniqueByName( strTechnique );
    V_RETURN( g_pEffect->SetTechnique( hTechnique ) );

    // Enable/disable LDPRT-only items
    g_SampleUI.GetStatic( IDC_ENV_LABEL )->SetEnabled( bLDPRT );
    g_SampleUI.GetSlider( IDC_ENV_SLIDER )->SetEnabled( bLDPRT );
    g_SampleUI.GetSlider( IDC_RED_TRANSMIT_SLIDER )->SetEnabled( bLDPRT );
    g_SampleUI.GetSlider( IDC_GREEN_TRANSMIT_SLIDER )->SetEnabled( bLDPRT );
    g_SampleUI.GetSlider( IDC_BLUE_TRANSMIT_SLIDER )->SetEnabled( bLDPRT );
    g_SampleUI.GetStatic( IDC_RED_TRANSMIT_LABEL )->SetEnabled( bLDPRT );
    g_SampleUI.GetStatic( IDC_GREEN_TRANSMIT_LABEL )->SetEnabled( bLDPRT );
    g_SampleUI.GetStatic( IDC_BLUE_TRANSMIT_LABEL )->SetEnabled( bLDPRT );

    // Load the mesh
    swprintf_s( strFileName, MAX_PATH, TEXT( "media\\%S" ), szMedia );
    V_RETURN( LoadLDPRTData( pDevice, strFileName ) );

    // Albedo texture
    swprintf_s( strFileName, MAX_PATH, TEXT( "media\\%SAlbedo.dds" ), szMedia );
    DXUTFindDXSDKMediaFileCch( strPath, MAX_PATH, strFileName );
    V( D3DXCreateTextureFromFile( pDevice, strPath, &pTexture ) );
    g_pEffect->SetTexture( "Albedo", pTexture );
    SAFE_RELEASE( pTexture );

    // Normal map 
    swprintf_s( strFileName, MAX_PATH, TEXT( "media\\%SNormalMap.dds" ), szMedia );
    DXUTFindDXSDKMediaFileCch( strPath, MAX_PATH, strFileName );
    V( D3DXCreateTextureFromFileEx( pDevice, strPath, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0,
                                    g_fmtTexture, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0,
                                    NULL, NULL, &pTexture ) );
    g_pEffect->SetTexture( "NormalMap", pTexture );
    SAFE_RELEASE( pTexture );

    // Spherical harmonic basic functions
    char* pNames[4] = {"YlmCoeff0","YlmCoeff4","YlmCoeff8","YlmCoeff12"};
    for( int i = 0; i < 4; i++ )
    {
        D3DXCreateCubeTexture( pDevice, 32, 1, 0, g_fmtCubeMap, D3DPOOL_MANAGED, &pCubeTexture );
        D3DXFillCubeTexture( pCubeTexture, myFillBF, ( LPVOID )( INT_PTR )( i * 4 ) );
        g_pEffect->SetTexture( pNames[i], pCubeTexture );
        SAFE_RELEASE( pCubeTexture );
    }

    return S_OK;
}
Esempio n. 24
0
HRESULT DisplayObject::LoadMesh(LPCTSTR fname)
{
	LPD3DXBUFFER		pD3DXMtrlBuffer;

	if (m_mesh)
		UnLoadMesh();
	m_numMaterials = 0L;  
	//LPDIRECT3DTEXTURE9* texture;    // a pointer to a texture


	//LPCTSTR tempstr = L m_meshFilePath.c_str();
    // Load the mesh from the specified file
    //if( FAILED( D3DXLoadMeshFromX( L"../assests/3dmodels/smalltank1-6.x", D3DXMESH_SYSTEMMEM,
	if (FAILED(D3DXLoadMeshFromX(fname, D3DXMESH_SYSTEMMEM,
                                   DXUTGetD3D9Device(), NULL,
                                   &pD3DXMtrlBuffer, NULL, &m_numMaterials,
                                   &m_mesh)))
    {
        // If model is not in current folder, try parent folder
        if (FAILED(D3DXLoadMeshFromX(L"..\\smalltank1-6.x", D3DXMESH_SYSTEMMEM,
                                       DXUTGetD3D9Device(), NULL,
                                       &pD3DXMtrlBuffer, NULL, &m_numMaterials,
                                       &m_mesh)))
        {
            MessageBox( NULL, L"Could not find .x file", L"Meshes.exe", MB_OK );
            return E_FAIL;
        }
    }
    // We need to extract the material properties and texture names from the 
    // pD3DXMtrlBuffer
    D3DXMATERIAL* d3dxMaterials = ( D3DXMATERIAL* )pD3DXMtrlBuffer->GetBufferPointer();
    m_meshMaterials = new D3DMATERIAL9[m_numMaterials];
    if( m_meshMaterials == NULL )
        return E_OUTOFMEMORY;
    m_meshTextures = new LPDIRECT3DTEXTURE9[m_numMaterials];
    if( m_meshTextures == NULL )
        return E_OUTOFMEMORY;

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

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

        m_meshTextures[i] = NULL;
        if( d3dxMaterials[i].pTextureFilename != NULL &&
            lstrlenA( d3dxMaterials[i].pTextureFilename ) > 0 )
        {
            // Create the texture
            if( FAILED( D3DXCreateTextureFromFileA( DXUTGetD3D9Device(),
                                                    d3dxMaterials[i].pTextureFilename,
                                                    &m_meshTextures[i] ) ) )
            {
                // If texture is not in current folder, try parent folder
                const CHAR* strPrefix = "../assests/3dmodels/";
                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( DXUTGetD3D9Device(),
                                                        strTexture,
                                                        &m_meshTextures[i] ) ) )
                {
                    MessageBox( NULL, L"Could not find texture map", L"Meshes.exe", MB_OK );
                }
            }
        }
    }

    // Done with the material buffer
    pD3DXMtrlBuffer->Release();
	return S_OK;
}
Esempio n. 25
0
HRESULT TextSprite::VOnRestore()
{
	// Two situations:
	// 1) String should be broken into a multiline entity to fit into a specific area
	// 2) String sent it need should take up as much space H&V that it needs

	// Set the width and height
	CSize sizeText;
	CSize sizeTotal;

	std::wstring multiline;

	if ( m_size.valid() )
	{
		// This is the total to fit into	
		sizeTotal = *m_size;

		// Fit the original text inside the bounds
		multiline = g_pApp->GetFontHandler()->ParseMessage( m_text, m_style, sizeTotal);
		sizeText = g_pApp->GetFontHandler()->GetStringSize(multiline, m_style);
	}
	else
	{
		// Set the width and height
		sizeText = g_pApp->GetFontHandler()->GetStringSize(m_text, m_style);
        sizeTotal = sizeText;

		multiline = m_text;
	}

	int numLines = CountLines(multiline);

	GCC_ASSERT(sizeTotal.cx > 0 && sizeTotal.cy > 0 && "About to create sprite with no width or height, is this what you want?");

	m_TextureWidth = m_Width = sizeTotal.cx;
	m_TextureHeight = m_Height = sizeTotal.cy;
	
	UINT texW = static_cast<UINT>(m_TextureWidth);
	UINT texH = static_cast<UINT>(m_TextureHeight);
	UINT numMipLevels = D3DX_DEFAULT;
	D3DFORMAT format = D3DFMT_UNKNOWN;
	
	// This call will reset width, height, and miplevels to the 
	// correct values.
	if (FAILED (D3DXCheckTextureRequirements(
		DXUTGetD3D9Device(), 
		&texW,
		&texH,
		&numMipLevels,
		0,
		&format,
		D3DPOOL_DEFAULT	) ) )
	{
		return false;
	}

	// Create the texture
	SAFE_RELEASE(m_pTexture);
	if ( FAILED ( DXUTGetD3D9Device()->CreateTexture(
		texW,		// width 
		texH,	// height 
		numMipLevels,		// miplevels - use default
		0,					// useage - default (not a render target or dynamic)
		format,				// format - unknown format
		D3DPOOL_DEFAULT,	// pool - use default
		&m_pTexture,		// the texture pointer
		NULL ) ) )
	{
		return false;
	}

	m_TextureWidth = texW;
	m_TextureHeight = texH;

	// Reinitialize the utility string to count the line breaks
	std::wstring utilString = multiline;

	// Size of border
	CSize sizeBorder( sizeTotal - sizeText );

	int initialX = sizeBorder.cx / 2;
	int initialY = sizeBorder.cy / 2;
	int deltaY = sizeText.cy / numLines;
	
	if (m_isCentered)
	{	
		// Determine how the lines will be spaced vertically
		std::wstring firstLine;
		RemoveFirstLine(utilString, firstLine);
		CSize const firstLineSize = g_pApp->GetFontHandler()->GetStringSize( firstLine, m_style );
		CSize printArea = sizeTotal - sizeBorder;
		bool const fitsVertically = printArea.cy >= firstLineSize.cy * numLines;

		if (fitsVertically)
		{	// Enough room, place lines in the center of the print area
			initialY += (printArea.cy - firstLineSize.cy * numLines) / 2;
			deltaY = firstLineSize.cy;
		}
		else
		{	// Not enough room, squeeze lines on top of each other
			deltaY = printArea.cy / numLines;
			initialY += (deltaY - firstLineSize.cy) / 2;
		}
	}
	else
	{
		deltaY = g_pApp->GetFontHandler()->GetHeight( m_style );
	}

	//Draw each line one at a time
	for(int i=0; i<numLines; ++i)
	{
		std::wstring line;
		RemoveFirstLine(multiline, line);
		
		int x = initialX;
		int y = initialY + i * deltaY;

		if (line.length())
		{
			if ( m_isCentered )
			{
				CSize sizeText = g_pApp->GetFontHandler()->GetStringSize( line, m_style );
				x = x + ( sizeTotal.cx - sizeBorder.cx - sizeText.cx ) / 2;
			}

			if(FAILED(g_pApp->GetFontHandler()->DrawText( this, line, m_style, CPoint( x, y ) ) ) )
				return false;
		}
	}

    return true;
}
Esempio n. 26
0
IDirect3DDevice9* RenderWin32DX9Imp::getD3D9Device() {
    return DXUTGetD3D9Device();
}
Esempio n. 27
0
// 
// Sprite::VOnRestore - Chapter 10, page 315
//
HRESULT Sprite::VOnRestore()
{
	SAFE_RELEASE(m_d3dSprite);
	return (D3DXCreateSprite(DXUTGetD3D9Device(), &m_d3dSprite)==S_OK);
}
Esempio n. 28
0
void	cTexBuf::BeginScene()
{
	DXUTGetD3D9Device()->SetRenderTarget( 0, m_pRenderTarget );
	DXUTGetD3D9Device()->SetDepthStencilSurface( m_pDepthSurface );
}
Esempio n. 29
0
void	cTexBuf::EndScene()
{
	DXUTGetD3D9Device()->SetRenderTarget( 0, m_pOriRenderTarget );
	DXUTGetD3D9Device()->SetDepthStencilSurface( m_pOriDepthSurface );	
}
Esempio n. 30
0
void CShowPoints9::SetMesh(LPD3DXMESH pNewMesh, LPD3DXSKININFO pNewSkin)
{
    HRESULT hr = S_OK;

    NumPoints = 0;
    
    UnskinnedVB.resize(0);
    SAFE_RELEASE(SkinnedVB);
    SAFE_RELEASE(Skin);

    if(pNewMesh == NULL)
        return;

    IDirect3DDevice9* device = DXUTGetD3D9Device();

    {//EFFECT
     V( device->CreateVertexDeclaration( Elements, &Declaration ) );

     ID3DXBuffer* pErrors = NULL;
     V( SASCreateEffectFromResource(
             device, 
             NULL, MAKEINTRESOURCE(IDR_SHOWLINES9FX), MAKEINTRESOURCE(RT_RCDATA),
             NULL, 
             NULL, 
             0,
             NULL, 
             &Effect, 
             &pErrors));
    if(pErrors)
         DXVGetApp().OutputA( (const char*)pErrors->GetBufferPointer() );
    SAFE_RELEASE(pErrors);

    }//EFFECT



    D3DVERTEXELEMENT9 declIn[ MAX_FVF_DECL_SIZE ];
    V( pNewMesh->GetDeclaration(declIn) );

    int iPos= -1;
    int iNorm= -1;
    for( int i = 0 ; 
        declIn[i].Stream != 255 && i < MAX_FVF_DECL_SIZE;
        i++)
    {
        if(declIn[i].Usage == D3DDECLUSAGE_POSITION && declIn[i].UsageIndex == 0)
            iPos = i;
        if(declIn[i].Usage == D3DDECLUSAGE_NORMAL && declIn[i].UsageIndex == 0)
            iNorm = i;
    }

    if(iPos == -1 || iNorm == -1)
        return;

    if( (( declIn[iPos].Type & (D3DDECLTYPE_FLOAT3|D3DDECLTYPE_FLOAT4)) == 0  ) ||
        (( declIn[iNorm].Type & (D3DDECLTYPE_FLOAT3|D3DDECLTYPE_FLOAT4)) == 0  ) )
        return;

    NumPoints = pNewMesh->GetNumVertices();

    int MeshStride = pNewMesh->GetNumBytesPerVertex();


    if(pNewSkin)
    {
        V( pNewSkin->Clone( &Skin ) ); 
        V( Skin->SetDeclaration(Elements) );
    }


    //GET VERTEX DATA

    BYTE* pSrcVB= NULL;
    V(  pNewMesh->LockVertexBuffer( D3DLOCK_READONLY, (LPVOID*)&pSrcVB ) );
    UnskinnedVB.resize(pNewMesh->GetNumVertices());
    for( DWORD iVert = 0; iVert < pNewMesh->GetNumVertices(); iVert++)
    {
        Vertex& v0 = UnskinnedVB[iVert];

        v0.Position = *(D3DXVECTOR3*) (pSrcVB+(MeshStride*iVert)+declIn[iPos].Offset);
    }
    V( pNewMesh->UnlockVertexBuffer() );

    V( device->CreateVertexBuffer( NumPoints*Stride , D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &SkinnedVB, NULL) );
    //Fill in with initial values so unskinned meshes do not have to do this every render.
    pSrcVB=(BYTE*)(void*)&UnskinnedVB.front();
    BYTE* pDstVB=NULL;
    V( SkinnedVB->Lock(0, 0, (void**)&pDstVB, 0 ) );
    {
        memcpy( pDstVB, pSrcVB, Stride*pNewMesh->GetNumVertices() );
    }
    V( SkinnedVB->Unlock() );
}