#include ".\spacex.h"
D3D *cD3D = new D3D;
//TQuad *cQuad = new TQuad;
Splash *cSplashScreen = new Splash;
LPD3DXSPRITE pSprite = NULL;
LPDIRECT3DTEXTURE9 pTexture = NULL, pTexture2 = NULL;
LPD3DXFONT pFont = NULL;
BOOL bRender = TRUE;
static IGraphBuilder *pGB;
static IMediaControl *pMC;
static IMediaEventEx *pMe;
static IBaseFilter *pVMR9;
static IVMRFilterConfig9 *pConfig;
static IVMRWindowlessControl9 *pWC;
LRESULT __stdcall WndProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
/*if (cQuad->IsInit())
{
Render();
ValidateRect( hWnd, NULL );
}*/
break;
case WM_CHAR:
if (wParam == 'l')
{
cD3D->LightState = !cD3D->LightState;
cD3D->SetLighting(cD3D->LightState);
}
if (wParam == 'r')
{
bRender = !bRender;
if (!bRender)
{
pMC->Run();
}else{
pMC->StopWhenReady();
}
}
break;
//TODO WM_PAINT message handling when Render() is complete;
default: break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
LPDIRECT3DVERTEXBUFFER9 pD3D9VertexBuffer = NULL;
if (FAILED(cD3D->Init(hInstance, WndProc)))
return E_FAIL;
SplashScreen->Init(cD3D->pD3D9Device,"Images\\space_x_");
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder, (void **)&pGB);
CoCreateInstance(CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC, IID_IBaseFilter, (void **)&pVMR9);
pGB->AddFilter(pVMR9, L"Video");
pVMR9->QueryInterface(IID_IVMRFilterConfig9, (void **) &pConfig);
pConfig->SetRenderingMode(VMR9Mode_Windowless);
pVMR9->QueryInterface(IID_IVMRWindowlessControl9, (void **) &pWC);
RECT vwRect;
GetClientRect(cD3D->hWnd, &vwRect);
pWC->SetVideoPosition(NULL, &vwRect);
pWC->SetVideoClippingWindow(cD3D->hWnd);
pGB->QueryInterface(IID_IMediaControl, (void **)&pMC);
pGB->RenderFile(L"blaupunkt.wmv", NULL);
ZeroMemory( &Msg, sizeof(Msg) );
while( Msg.message!=WM_QUIT )
{
if( PeekMessage( &Msg, NULL, NULL, NULL, PM_REMOVE ) )
{
TranslateMessage( &Msg );
DispatchMessage( &Msg );
}
else
{
if (bRender)
{
switch (cD3D->pD3D9Device->TestCooperativeLevel())
{
case D3D_OK:
Render();
break;
case D3DERR_DEVICELOST: if (cSplashScreen != NULL)
{
cSplashScreen->Release(); // Release D3DPOOL_DEFAULT resources
cSplashScreen = NULL;
}
break;
case D3DERR_DEVICENOTRESET: cD3D->pD3D9Device->Reset(&cD3D->d3dpp);
cSplashScreen = new Splash;
cSplashScreen->Init(cD3D->pD3D9Device,"Images\\space_x_"); //Recreate resource
cD3D->SetLighting(cD3D->LightState);
DEBUGOUT("Device Reset.\n");
break;
case D3DERR_DRIVERINTERNALERROR: PostQuitMessage(NULL);
break;
default: DEBUGOUT("Unknown TestCooperativeLevel error\n");
return E_FAIL;
}
}
}
}
Cleanup();
return (int)Msg.wParam;
}
HRESULT Render()
{
cD3D->pD3D9Device->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
if( SUCCEEDED( cD3D->pD3D9Device->BeginScene() ) )
{
D3DXVECTOR3 Vector = D3DXVECTOR3(0,0,0);
cSplashScreen->Render();
cD3D->pD3D9Device->EndScene();
}
cD3D->pD3D9Device->Present( NULL, NULL, NULL, NULL );
return S_OK;
}
void Cleanup()
{
//pVW->put_Visible(OAFALSE);
//pVW->put_Owner(NULL);
if (pFont != NULL)
pFont->Release();
if (pSprite != NULL)
pSprite->Release();
if (pTexture != NULL)
pTexture->Release();
if (pTexture2 != NULL)
pTexture2->Release();
if (cSplashScreen != NULL)
{
cSplashScreen->Release();
cSplashScreen = NULL;
DEBUGOUT("SplashScreen Successfully released\n");
}
//pVW->Release();
pMC->Release();
pWC->Release();
pConfig->Release();
if (pVMR9)
{
pVMR9->Release();
pVMR9 = NULL;
}
if (pGB)
{
pGB->Release();
pGB = NULL;
}
CoUninitialize();
if (cD3D != NULL)
{
cD3D->Release();
cD3D = NULL;
DEBUGOUT("D3D Class Successfully released\n");
}
}
DirectShow