Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Мультимедия, OpenGL/DirectX > Получить BitMap из поверхности Direct3D


Автор: Sartorius 27.1.2007, 08:21
 Всем привет smile 
Пытаюсь записать avi-ку из сцены Direct3D. Для этого необходимо получать битмапы и присоединять их к avi-файлу. Вот с этим то и проблема(((

Делаю так:
Получаю поверхность и контекст от нее
Код

g_pd3dDevice->CreateOffscreenPlainSurface(WINDOW_WIDTH, WINDOW_HIGHT,D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &_surface, 0); 

// Получаем описание поверхности
_surface->GetDesc(&surfaceDesc);
_surface->GetDC(&hdcsceen);


далее создаю совместимый контекст в памяти
Код

hdcscreen = CreateCompatibleDC(hdcsceen);


и DIB секцию под него

Код

            BITMAPINFO bi; ZeroMemory(&bi,sizeof(bi)); BITMAPINFOHEADER &bih = bi.bmiHeader;
            bih.biSize=sizeof(bih);
            bih.biWidth=WINDOW_WIDTH;
            bih.biHeight=WINDOW_HIGHT;
            bih.biPlanes=1;
            bih.biBitCount=24; //???
            bih.biCompression=BI_RGB;
            bih.biSizeImage = ((bih.biWidth*bih.biBitCount/8+3)&0xFFFFFFFC)*bih.biHeight;
            bih.biXPelsPerMeter=10000;
            bih.biYPelsPerMeter=10000;
            bih.biClrUsed=0;
            bih.biClrImportant=0;
            
            hbm=CreateDIBSection(hdcscreen,(BITMAPINFO*)&bih,DIB_RGB_COLORS,&bits,NULL,NULL);
            HGDIOBJ holdb=SelectObject(hdcscreen,hbm);


потом просто 
Код

BitBlt(hdcscreen, 0, 0, WINDOW_WIDTH, WINDOW_HIGHT, hdcsceen, 0, 0, SRCCOPY); 


Но сцены в итоге там нет. Все что рисуешь на hdcsceen GDI есть, а Direct3D нет...
Кто может че нить посоветовать?

Автор: Sartorius 27.1.2007, 15:14
 Ну хоть какой-нить пример захвата 3D сцены, чтоб DIB потом можно было в памяти получить.... smile 
Нигде не могу найти  smile 

Во... кое чего нашел на sourcecodeplanet: мало ли кому пригодиться (сейчас возможности прикрутить к своей проге нет)
Код


/*
//    Take screenshots in DirectX apps, Fast!!
//    deja_vu [ 11:46 PM 9/5/2003 ]
//    comments to : [email protected]
*/


/*
// This tutorial assumes that you have pretty basic knowledge of DirectX..
// how to initialise DirectX and create a Direct3D device. it is assumed that 
// a Direct3D device called "g_pd3dDevice" has been created..
*/

void TakeScreenShot(char* filename)
{
    /*
        we create a pointer to the IDirect3DSurface8 interface.. this is to store the
        actual Direct3D surface thats being used as the render target..
    */
    LPDIRECT3DSURFACE8 surf = NULL;

    /*
        we then get the current render target from the Direct3D device.. here 
        g_pd3dDevice is the Direct3D device which I assume was created earlier.. 
        The GetRenderTarget() function retrieves a pointer to the current Direct3D 
        surface thats being used as a render target..
    */
    if(g_pd3dDevice->GetRenderTarget(&surf) == D3D_OK)
    {
    /*
        The D3DXSaveSurfaceToFile() function takes in 5 parameters,
        1st param    -  filename to save the surface to..

        2nd param    -  is a D3DXIMAGE_FILEFORMAT flag, D3DXIFF_BMP
                   and D3DXIFF_DDS seems to be the only two 
                   supported.. for now!?

        3rd param    -  is the pointer to the Direct3DSurface( the one we
                   want to save)

        4th param    -  this is a pointer to PALETTEENTRY structure. we are 
                   not using it so, NULL..

        5th param    -  this is a rect specifing the area to be saved.. the 
                   total area is saved if this is NULL is passed..
    */
        D3DXSaveSurfaceToFile(filename,D3DXIFF_BMP,surf,NULL,NULL);
    }

    //    to prevent any memory leaks we release the surface after we use it..
    if(surf != NULL)
        surf->Release();
}


Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)