Jump to content
  • Advertisement
Sign in to follow this  
Talib

VMR9 + fullscreen D3D9

This topic is 4866 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi This is an attempt to make my own cutscenes with VMR9 and D3D9 fullscreen. However, I think I have either totally misused or even abused DirectX and the fact that it even works might be a miracle. Anyway here is the code (won't be able to compile it):
#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");
	}
}

Ok I know the code is a bit messy, but this was retry after retry. The thing is, it is suppose to render, then if you press 'r' it should start the video, then after pressing 'r' again it should stop the video and continue rendering. Now the video does play (I hear the audio), but it only renders the video about 80% of the time, but the D3D rendering renders 100% of the time. Although it seems to me that I will end up using render to texture in the future for my cutscenes, I would love to know what is the reason why this isn't working.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Talib
I would love to know what is the reason why this isn't working.

So would I... I spent months trying to beat DirectShow and Direct3D until they played nicely together, but it never quite worked. Always had some sort of problem here-or-there [sad]

This thread contains a fair bit of information that you might find useful.

hth
Jack

Share this post


Link to post
Share on other sites
Yeah, saw that post, looks like render to texture is the only option. I wonder what technique the big game companies use (or if they use dshow at all)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!