HRESULT InitD3D( HWND hWnd ) { // Create the D3D object. if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) return E_FAIL; // Set up the structure used to create the D3DDevice D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof( d3dpp ) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; // Create the D3DDevice if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice ) ) ) { return E_FAIL; } g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE); g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); // Create a dynamic texture if( FAILED( D3DXCreateTexture(g_pd3dDevice,g_ogg.width(),g_ogg.height(),1,D3DUSAGE_DYNAMIC,D3DFMT_X8B8G8R8,D3DPOOL_DEFAULT,&g_pTexture))) { return E_FAIL; } float x1 = 0; float y1 = 0; float x2 = g_ogg.width(); float y2 = g_ogg.height(); // Initialize three vertices for rendering a quad CUSTOMVERTEX vertices[] = { // x, y, z, color, tu, tv { x1, y1, 0.0f, 1.0f, 0xffffffff, 0.0f, 0.0f }, { x2, y1, 0.0f, 1.0f, 0xffffffff, 1.0f, 0.0f }, { x2, y2, 0.0f, 1.0f, 0xffffffff, 1.0f, 1.0f }, { x1, y2, 0.0f, 1.0f, 0xffffffff, 0.0f, 1.0f }, }; if( FAILED( g_pd3dDevice->CreateVertexBuffer( 4 * sizeof( CUSTOMVERTEX ), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL ) ) ) { return E_FAIL; } VOID* pVertices; if( FAILED( g_pVB->Lock( 0, sizeof( vertices ), ( void** )&pVertices, 0 ) ) ) return E_FAIL; memcpy( pVertices, vertices, sizeof( vertices ) ); g_pVB->Unlock(); return S_OK; }
INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT ) { g_ogg.open("../sample video/trailer_400p.ogg",AF_S16,2,44100,VF_BGRA); if(g_ogg.fail()) { return -1; } // Register the window class WNDCLASSEX wc = { sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle( NULL ), NULL, NULL, NULL, NULL, L"liboggstream", NULL }; RegisterClassEx( &wc ); int width=g_ogg.width(); int height=g_ogg.height(); // Create the application's window RECT rect; rect.left = 100; rect.top = 100; rect.right = width+rect.left; rect.bottom = height+rect.top; AdjustWindowRect(&rect,WS_OVERLAPPEDWINDOW,FALSE); HWND hWnd = CreateWindow( L"liboggstream", L"D3D9 Theora Player", WS_OVERLAPPEDWINDOW, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, NULL, NULL, wc.hInstance, NULL ); // Initialize Direct3D and OpenAL if( SUCCEEDED( InitD3D( hWnd ) ) && InitAL()) { // Show the window ShowWindow( hWnd, SW_SHOWDEFAULT ); UpdateWindow( hWnd ); // Start the playback g_ogg.play(); // Run MixAudio in another thread HANDLE h_mixaudio= CreateThread(NULL,0,MixAudio,NULL,0,NULL); // Enter the message loop MSG msg; ZeroMemory( &msg, sizeof( msg ) ); while( msg.message != WM_QUIT && g_ogg.playing() ) { if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); }else { Render(); Sleep(0); } } g_ogg.close(); WaitForSingleObject(h_mixaudio,INFINITE); alutExit(); } UnregisterClass( L"liboggstream", wc.hInstance ); return 0; }