GFx 阅读摘要


The first step in the integration process is to render a Flash animation on top of the 3D background. 
This involves instantiating:
GFx::Loader object to manage loading of all Flash content globally for the application;
GFx::MovieDef to contain the Flash content;
GFx::Movie to represent a single playing instance of the movie;
Render::Renderer2D and Render::HAL object will be instantiated to act as the interface between GFx and the implementation-specific rendering API



Step #1: Add Header Files
#include "GFx_Kernel.h"
#include "GFx.h"
#include "GFx_Renderer_D3D9.h"

// One GFx::Loader per application
Loader gfxLoader;
// One GFx::MovieDef per SWF/GFx file
Ptr<MovieDef> pUIMovieDef;
// One GFx::Movie per playing instance of movie
Ptr<Movie> pUIMovie;
// Renderer data
Ptr<Render::D3D9::HAL> pRenderHAL; 
Ptr<Render::Renderer2D> pRenderer;
MovieDisplayHandle hMovieDisplay;

Step #2: Initialize GFx::System
// One GFx::System per application
GFx::System gfxInit;

Step #3: Loader and Renderer Creation
gfx = new GFxTutorial();
assert(gfx != NULL);
if(!gfx->InitGFx())
assert(0);

// Initialize logging -- GFx will print errors to the log stream.
gfxLoader->SetLog(Ptr<Log>(*new Log()));

// Give the loader the default file opener
Ptr<FileOpener> pfileOpener = *new FileOpener;
gfxLoader->SetFileOpener(pfileOpener);

pRenderHAL = *new Render::D3D9::HAL();
if (!(pRenderer = *new Render::Renderer2D(pRenderHAL.GetPtr())))
return false;

Step #4: Load a Flash Movie
// Load the movie
pUIMovieDef = *gfxLoader.CreateMovie(UIMOVIE_FILENAME,  Loader::LoadKeepBindData | Loader::LoadWaitFrame1, 0);     Step #5: Movie Instance Creation pUIMovie = *pUIMovieDef->CreateInstance(true, 0, NULL);
assert(pUIMovie.getPtr() != NULL);  

// Advance the movie to the first frame
pUIMovie->Advance(0.0f, 0, true);
// Note the time to determine the amount of time elapsed between this frame and the next
MovieLastTime = timeGetTime();  

pUIMovie->SetBackgroundAlpha(0.0f);  

Step #6: Device Initialization
HWND hWND = DXUTGetHWND();
pRenderHAL->SetDependentVideoMode(pd3dDevice, &presentParams, 0, Render::D3D9::HAL::VMConfig_NoSceneCalls, hWND);

Step #7: Lost Devices
pRenderHAL->ResetVideoMode();

Step #8: Resource Allocation and Cleanup
delete gfx;
gfx = NULL;

Step #9: Setting the Viewport
// Use the window client rect size as the viewport.
RECT windowRect = DXUTGetWindowClientRect();
DWORD windowWidth = windowRect.right - windowRect.left;
DWORD windowHeight = windowRect.bottom - windowRect.top;
pUIMovie->SetViewport(windowWidth, windowHeight, 0, 0, windowWidth, windowHeight);

Step #10: Rendering into the DirectX Scene
void AdvanceAndRender(void)
{
DWORD mtime = timeGetTime();
float deltaTime = ((float)(mtime - MovieLastTime)) / 1000.0f;
MovieLastTime = mtime;
pUIMovie->Advance(deltaTime, 0);
pRenderer->BeginFrame();
if (hMovieDisplay.NextCapture(pRenderer->GetContextNotify()))
{
pRenderer->Display(hMovieDisplay);
}
pRenderer->EndFrame();
}

Step #11: Preserving Rendering States
// Save DirectX state before calling GFx
g_pStateBlock->Capture();
// Render the frame and advance the time counter
gfx->AdvanceAndRender();
// Restore DirectX state to avoid disturbing game render state
g_pStateBlock->Apply();


Step #12: Disable Default UI
// Disable default UI
...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值