Example #1
0
RageSurface* RageDisplay_D3D::CreateScreenshot()
{
#if defined(XBOX)
	return NULL;
#else
	RageSurface * result = NULL;

	// Get the back buffer.
	IDirect3DSurface9* pSurface;
	if( SUCCEEDED( g_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pSurface ) ) )
	{
		// Get the back buffer description.
		D3DSURFACE_DESC desc;
		pSurface->GetDesc( &desc );

		// Copy the back buffer into a surface of a type we support.
		IDirect3DSurface9* pCopy;
		if( SUCCEEDED( g_pd3dDevice->CreateOffscreenPlainSurface( desc.Width, desc.Height, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pCopy, NULL ) ) )
		{
			if( SUCCEEDED( D3DXLoadSurfaceFromSurface( pCopy, NULL, NULL, pSurface, NULL, NULL, D3DX_FILTER_NONE, 0) ) )
			{
				// Update desc from the copy.
				pCopy->GetDesc( &desc );

				D3DLOCKED_RECT lr;

				{
					RECT rect;
					rect.left = 0;
					rect.top = 0;
					rect.right = desc.Width;
					rect.bottom = desc.Height;

					pCopy->LockRect( &lr, &rect, D3DLOCK_READONLY );
				}

				RageSurface *surface = CreateSurfaceFromPixfmt( FMT_RGBA8, lr.pBits, desc.Width, desc.Height, lr.Pitch);
				ASSERT( surface != NULL );

				// We need to make a copy, since lr.pBits will go away when we call UnlockRect().
				result = 
					CreateSurface( surface->w, surface->h,
						surface->format->BitsPerPixel,
						surface->format->Rmask, surface->format->Gmask,
						surface->format->Bmask, surface->format->Amask );
				RageSurfaceUtils::CopySurface( surface, result );
				delete surface;

				pCopy->UnlockRect();
			}

			pCopy->Release();
		}

		pSurface->Release();
	}

	return result;
#endif
}
Example #2
0
bool Direct3D_Init(HWND window, int width, int height, bool fullscreen)
{
    //initialize Direct3D
    d3d = Direct3DCreate9(D3D_SDK_VERSION);
    if (!d3d) return false;

    //set Direct3D presentation parameters
    D3DPRESENT_PARAMETERS d3dpp; 
    ZeroMemory(&d3dpp, sizeof(d3dpp));
    d3dpp.hDeviceWindow = window;
    d3dpp.Windowed = (!fullscreen);
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.EnableAutoDepthStencil = 1;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
    d3dpp.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferCount = 1;
    d3dpp.BackBufferWidth = width;
    d3dpp.BackBufferHeight = height;

    //create Direct3D device
    d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
        D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
    if (!d3ddev) return false;


    //get a pointer to the back buffer surface
    d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);

    //create sprite object
    D3DXCreateSprite(d3ddev, &spriteobj);

    return 1;
}
int Init_Direct3D(HWND hwnd, int width, int height, int fullscreen)
{
    d3d = Direct3DCreate9(D3D_SDK_VERSION);

    D3DPRESENT_PARAMETERS d3dpp; 
    ZeroMemory(&d3dpp, sizeof(d3dpp));

    d3dpp.Windowed = (!fullscreen);
    d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferCount = 1;
    d3dpp.BackBufferWidth = 800;
    d3dpp.BackBufferHeight = 600;
    d3dpp.hDeviceWindow = hwnd;
    d3dpp.EnableAutoDepthStencil = TRUE;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
    d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;

    d3d->CreateDevice(
        D3DADAPTER_DEFAULT, 
        D3DDEVTYPE_HAL, 
        hwnd,
        D3DCREATE_SOFTWARE_VERTEXPROCESSING,
        &d3dpp, 
        &d3ddev);

    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);

    d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);

    return 1;
}
Example #4
0
/*
 * Game update function
 */
void Game_Run(HWND hwnd)
{
    //make sure the Direct3D device is valid
    if (!d3ddev) return;

    //create pointer to the back buffer
    d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);

    //start rendering
    if (d3ddev->BeginScene())
    {
		RECT rect; 
		rect.top = NULL;
		rect.left = NULL;
		rect.right = 950;
		rect.bottom = 768;

		RECT rect2;
		rect2.top = 270;
		rect2.left = 110;
		rect2.right = 900;
		rect2.bottom = 768;

        d3ddev->StretchRect(surface, &rect2
			, backbuffer, &rect, D3DTEXF_NONE);
     
        //stop rendering
        d3ddev->EndScene();
        d3ddev->Present(NULL, NULL, NULL, NULL);
    }

    //check for escape key (to exit program)
    if (KEY_DOWN(VK_ESCAPE))
        PostMessage(hwnd, WM_DESTROY, 0, 0);
}
Example #5
0
/**
 ** Direct3D initialization
 **/
bool Direct3D_Init(HWND window, int width, int height, bool fullscreen)
{
    //initialize Direct3D
    d3d = Direct3DCreate9(D3D_SDK_VERSION);
    if (!d3d) return false;

    //set Direct3D presentation parameters
    D3DPRESENT_PARAMETERS d3dpp; 
    ZeroMemory(&d3dpp, sizeof(d3dpp));
    d3dpp.Windowed = (!fullscreen);
    d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferCount = 1;
    d3dpp.BackBufferWidth = width;
    d3dpp.BackBufferHeight = height;
    d3dpp.hDeviceWindow = window;

    //create Direct3D device
    d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
        D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);

    if (!d3ddev) return false;

    //get a pointer to the back buffer surface
    d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);

    return true;
}
HRESULT InitD3D( HWND hWnd ) 
{ 
	HRESULT hr ;

	// Create the D3D object, which is needed to create the D3DDevice. 
	if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ) 
	{ 
		MessageBox(NULL, "Create D3D9 object failed!", "Error", 0) ; 
		return E_FAIL; 
	} 

	D3DDISPLAYMODE	ddm;
	hr = g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&ddm) ;
	if(FAILED(hr))
	{
		MessageBox(NULL, "Unable to Get Adapter Display Mode", "Error", 0) ; 
		return E_FAIL;
	}

	ZeroMemory( &d3dpp, sizeof(d3dpp) ); 

	d3dpp.Windowed = TRUE;  
	d3dpp.BackBufferCount = 1 ;
	d3dpp.BackBufferWidth = ddm.Width ;
	d3dpp.BackBufferHeight = ddm.Height ;
	d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP; 
	d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; 

	// Create device 
	if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, 
		D3DCREATE_SOFTWARE_VERTEXPROCESSING, 
		&d3dpp, &g_pd3dDevice ) ) ) 
	{ 
		MessageBoxA(NULL, "Create D3D9 device failed!", "Error", 0) ; 
		return E_FAIL; 
	} 

	// Create Semaphore variable
	g_hMutex = CreateMutex(NULL,FALSE,NULL);
	g_hFullSemaphore = CreateSemaphore(NULL, g_PoolSize - 1, g_PoolSize - 1, NULL);
	g_hEmptySemaphore = CreateSemaphore(NULL, 0, g_PoolSize - 1, NULL);

	// Get back buffer
	g_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &g_pBackBuffer) ;

	// Create surface
	for (int i = 0; i < g_PoolSize; ++i)
	{
		g_SurfPool[i] = NULL ;
		if (FAILED(hr = g_pd3dDevice->CreateOffscreenPlainSurface(d3dpp.BackBufferWidth, 
			d3dpp.BackBufferHeight, d3dpp.BackBufferFormat, D3DPOOL_SYSTEMMEM, &g_SurfPool[i], NULL)))
		{
			return hr;
		}
	}

	return S_OK; 
} 
Example #7
0
HRESULT HookIDirect3DDevice9::GetBackBuffer(LPVOID _this,
											UINT iSwapChain,
											UINT iBackBuffer,
											D3DBACKBUFFER_TYPE Type,
											IDirect3DSurface9** ppBackBuffer)
{
	LOG_API();
	return pD3Dev->GetBackBuffer(iSwapChain, iBackBuffer, Type, ppBackBuffer);
}
Example #8
0
void Background::render(LPDIRECT3DDEVICE9 Device)
{
	destRect.bottom = destRect.top + (int)(height * (imageScale / 100));
	destRect.right = destRect.left + (int)(width * (imageScale / 100));

	IDirect3DSurface9	*backBuffer = NULL;
	Device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer);
	Device->StretchRect(background, &scrRect, backBuffer, &destRect, D3DTEXF_NONE);

}
Example #9
0
void Surface::render(LPDIRECT3DDEVICE9 pDevice)
{

	//Scale the destination based on current imageScale
	destRect.bottom = destRect.top + (int)(height * (imageScale / 100));
	destRect.right = destRect.left + (int)(width * (imageScale / 100));

	IDirect3DSurface9* backbuffer = NULL;
	pDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &backbuffer);
	
	pDevice->StretchRect(surface, &srcRect, backbuffer, &destRect, D3DTEXF_NONE);
}
Example #10
0
//==============================================================
// 백 버퍼의 사이즈 취득
static SIZE GetBackBufferSize(LPDIRECT3DDEVICE9 device) {
	LPDIRECT3DSURFACE9 back_buffer;
	D3DSURFACE_DESC desc;
	SIZE size={0, 0};
	if (SUCCEEDED(device->GetBackBuffer(
			0, 0, D3DBACKBUFFER_TYPE_MONO, &back_buffer))
	) {
		if (SUCCEEDED(back_buffer->GetDesc(&desc))) {
			size.cx=desc.Width; size.cy=desc.Height;	
		}
		back_buffer->Release();
	}
	return size;
}
Example #11
0
	bool restore_objects()
	{
		if ( retry_count )
		{
			if ( --retry_count ) return false;

			release_objects();
			if ( lpdev->Reset( &dpp ) != D3D_OK ) return false;
		}

		retry_count = 0;

		LPDIRECT3DSURFACE9 lpbb;
		HRESULT hr;
		if( SUCCEEDED( hr = lpdev->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, & lpbb ) ) ) {
			lpbb->GetDesc( & d3dsd );
			lpbb->Release();
		}

		lpdev->SetTextureStageState(0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1);
		lpdev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
		lpdev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);

		lpdev->SetTextureStageState(0, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG1);
		lpdev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
		lpdev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);

		lpdev->SetRenderState(D3DRS_LIGHTING, false);
		lpdev->SetRenderState(D3DRS_ZENABLE,  false);
		lpdev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

		lpdev->SetRenderState(D3DRS_SRCBLEND,  D3DBLEND_SRCALPHA);
		lpdev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
		lpdev->SetRenderState(D3DRS_ALPHABLENDENABLE, false);

		lpdev->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);

		if ( lpdev->CreateVertexBuffer( sizeof(d3dvertex) * 4, flags.v_usage, D3DFVF_XYZRHW | D3DFVF_TEX1, (D3DPOOL)flags.v_pool, &lpvbuf, NULL ) != D3D_OK )
			return false;

		update_filtering( 1 );

		lpdev->SetRenderState( D3DRS_DITHERENABLE,   TRUE );

		if ( lpdev->CreateTexture( surface_width, surface_height, 1, flags.t_usage, D3DFMT_X8R8G8B8, (D3DPOOL)flags.t_pool, &lptex, NULL ) != D3D_OK )
			return false;

		return true;
	}
bool InitDirect3D (HWND hWnd, int width, int height, bool fullScreen) {
    d3d = Direct3DCreate9(D3D_SDK_VERSION);
    if (d3d == NULL)
        return false;

    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));

    d3dpp.Windowed = !fullScreen;
    d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferCount = 1;
    d3dpp.BackBufferWidth = width;
    d3dpp.BackBufferHeight = height;
    d3dpp.hDeviceWindow = hWnd;
    d3dpp.EnableAutoDepthStencil = TRUE;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;

    d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3dDev);
    if (d3dDev == NULL)
        return false;

    d3dDev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    d3dDev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer);

    // Create font 
    /*
            INT Height;
            UINT Width;
            UINT Weight;
            UINT MipLevels;
            BOOL Italic;
            BYTE CharSet;
            BYTE OutputPrecision;
            BYTE Quality;
            BYTE PitchAndFamily;
            CHAR FaceName[LF_FACESIZE];
    */
    D3DXFONT_DESC fontDesc = {24, 0, 400, 0, false, DEFAULT_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_PITCH, "Arial"};
    RECT fontPos = { 0, 0, width, height };
    D3DXCreateFontIndirect(d3dDev, &fontDesc, &d3dFont);

    return true;
}
void SRRasterization::CopyToScreen()
{
	g_pd3dDevice->BeginScene();

	LPDIRECT3DSURFACE9 backBuffer;
	HRESULT ret = g_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer);

	D3DSURFACE_DESC surfacedesc;
	HRESULT ret2 = backBuffer->GetDesc(&surfacedesc);
	const TCHAR * message1 = DXGetErrorString(ret2);
	const TCHAR * message2 = DXGetErrorDescription(ret2);

	m_colorBuffer->CopyBufferToSurface(backBuffer);

	g_pd3dDevice->EndScene();

	// Present the backbuffer contents to the display
	g_pd3dDevice->Present(NULL, NULL, NULL, NULL);
}
Example #14
0
String screengrab(String filename)
{
	if(filename=="" || filename == " () ")
	{
		filename.sprintf("%s_%5.5d_.png",(const char*)screengrabprefix,screengrabcount);		
		screengrabcount++;
	}
	if(!IsOneOf('.',filename)) 
		filename << ".png";
	HRESULT hr;
	// get display dimensions
	// this will be the dimensions of the front buffer
	D3DDISPLAYMODE mode;
	if (FAILED(hr=g_pd3dDevice->GetDisplayMode(0,&mode)))
	{
		return "fail getdisplaymode";
	}
	// create the image surface to store the front buffer image
	// note that call to GetFrontBuffer will always convert format to A8R8G8B8
	static LPDIRECT3DSURFACE9 surf=NULL;
	if (!surf && FAILED(hr=g_pd3dDevice->CreateOffscreenPlainSurface(mode.Width,mode.Height,
		D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&surf,NULL)))
	{
		return "fail createimagesurface";
	}
 	// Next, this surface is passed to the GetFrontBuffer() method of the device, which will copy the entire screen into our image buffer:
	// read the front buffer into the image surface
	if (FAILED(hr=g_pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&surf))) 
	{
		surf->Release();
		return "fail getfrontbuffer";
	}
	//Finally, we call D3DXSaveSurfaceToFile() to create the BMP file, and release the temporary image surface:
	// write the entire surface to the requested file
	hr=D3DXSaveSurfaceToFile(filename,D3DXIFF_PNG,surf,NULL,NULL);
	// release the image surface
	// surf->Release();
	// return status of save operation to caller
	return (hr==D3D_OK)? filename + " exported!" : "something failed";
}
Example #15
0
static HRESULT GetBackBufferDesc(LPDIRECT3DDEVICE9 pd3dDevice, D3DSURFACE_DESC* pBackBufferSurfaceDesc)
{
    HRESULT hr = E_FAIL;
    HRESULT hrResult = E_FAIL;
    LPDIRECT3DSURFACE9 pBackBuffer = NULL;

    KGLOG_PROCESS_ERROR(pd3dDevice);
    KGLOG_PROCESS_ERROR(pBackBufferSurfaceDesc);

    hr = pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);
    KGLOG_COM_PROCESS_ERROR(hr);

    memset(pBackBufferSurfaceDesc, 0, sizeof(D3DSURFACE_DESC));

    hr = pBackBuffer->GetDesc(pBackBufferSurfaceDesc);
    KGLOG_COM_PROCESS_ERROR(hr);

    hrResult = S_OK;
Exit0:
    SAFE_RELEASE(pBackBuffer);

    return hrResult;
}
Example #16
0
	bool InitGraphics(HWND hWnd, int width, int height, bool fullscreen,
										int colordepth) {
		ambientcolor = D3DCOLOR_RGBA(255, 255, 255, 0);
		clearColor = D3DCOLOR_RGBA(0, 0, 0, 255);
		d3d = Direct3DCreate9(D3D_SDK_VERSION);
		if(d3d == NULL) {
			return false;
		}

		//get default display-adapter
		D3DDISPLAYMODE dm;
		d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dm);

		//setup present-parameters
		D3DPRESENT_PARAMETERS d3dpp;
		ZeroMemory(&d3dpp, sizeof(d3dpp));
		d3dpp.Windowed = !fullscreen;
		d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
		d3dpp.EnableAutoDepthStencil = TRUE;
		d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
		d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
		d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
		d3dpp.BackBufferCount = 1;
		d3dpp.BackBufferWidth = width;
		d3dpp.BackBufferHeight = height;
		d3dpp.hDeviceWindow = hWnd;

		//create device
		HRESULT result = d3d->CreateDevice(
			D3DADAPTER_DEFAULT,
			D3DDEVTYPE_HAL,
			hWnd,
			D3DCREATE_SOFTWARE_VERTEXPROCESSING,
			&d3dpp,
			&device);

		if(result != D3D_OK) {
			return false;
		}

		device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
		device->Clear(0, NULL, D3DCLEAR_TARGET, 0xFAFF, 1.0f, 0);

		//create font (arial)
		D3DXFONT_DESC FontDesc = { 24,
			0,
			400,
			0,
			false,
			DEFAULT_CHARSET,
			OUT_TT_PRECIS,
			CLIP_DEFAULT_PRECIS,
			DEFAULT_PITCH,
			"Arial"
		};

		D3DXCreateFontIndirect(device, &FontDesc, &font);

		//Create sprite-handler
		D3DXCreateSprite(device, &spriteHandler);
		if(result != D3D_OK) {
			return false;
		}

		return true;
	}
//Game Initialization Function
bool Game_Init(HWND hwnd)
{
	//Initialize Direct3D
	d3d = Direct3DCreate9(D3D_SDK_VERSION);
	if (d3d == NULL)
	{
		MessageBox(hwnd, "Error Initializing Direct3D", "Error", MB_OK);
		return false;
	}

	//set Direct3D presentation parameters
	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.Windowed = TRUE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
	d3dpp.BackBufferCount = 1;
	d3dpp.BackBufferWidth = SCREENW;
	d3dpp.BackBufferHeight = SCREENH;
	d3dpp.hDeviceWindow = hwnd;

	//create Direct3D device
	d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);

	if(!d3ddev)
	{
		MessageBox(hwnd, "Error creating Direct3D device", "Error", MB_OK);
		return false;
	}

	//set random number seed
	srand(time(NULL));

	//clear the backbuffer to black
	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);

	//create surface
	HRESULT result = d3ddev->CreateOffscreenPlainSurface(
		SCREENW,					//width of the surface
		SCREENH,					//height of the surface
		D3DFMT_X8R8G8B8,			//surface format
		D3DPOOL_DEFAULT,			//memory pool to use
		&surface,					//pointer to the surface
		NULL);						//reserved (always NULL)

	if (!SUCCEEDED(result)) return false;

	//load surface from file into newly created surface
	result = D3DXLoadSurfaceFromFile(
		surface,					//destination surface
		NULL,						//destination palette
		NULL,						//destination rectangle
		"legotron.bmp",				//source filename
		NULL,						//source rectangle
		D3DX_DEFAULT,				//controls how image is filtered
		0,							//for transparency (0 for none)
		NULL);						//source image info (usually NULL)

	//make sure the image was loaded okay
	if(!SUCCEEDED(result)) return false;

	//create pointer to the back buffer
	d3ddev->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &backbuffer);

	rect.left = 0;
	rect.right = SCREENW / 2;
	rect.top = 0;
	rect.bottom = SCREENH / 2;

	return true;
}
void clsDXDevice::CreateBackBuffer(LPDIRECT3DDEVICE9 ldd)
{
	ldd->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&backbuffer);
}
Example #19
0
void BackBuffer()
{
	IDirect3DSurface9 *ppBackBuffer, *ppOffScreen;
	HRESULT back;
D3DXIMAGE_INFO pSrcInfo;
	if (SUCCEEDED(back = g_pd3dDevice->CreateOffscreenPlainSurface(
		256, 256, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &ppOffScreen, NULL)))    	
	{	
		
		if (SUCCEEDED( back = D3DXLoadSurfaceFromFile(
			ppOffScreen,
			NULL,
			NULL,
			"bana.bmp",
			NULL,
			D3DX_FILTER_TRIANGLE,
			0,
			&pSrcInfo)))
		{
			back = NULL;
		}
		else if (back == D3DERR_INVALIDCALL)
		{
			back = 0;
		}
		else if (back == D3DXERR_INVALIDDATA)
		{
			pSrcInfo.Width;
			back = 1;
		}
		else
		{
			back = 2;
		}
	}

	//if (SUCCEEDED(g_pd3dDevice->GetRenderTarget(0, &ppBackBuffer)))
	if (SUCCEEDED(g_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &ppBackBuffer)))
	{
		D3DSURFACE_DESC pDesc;
		ppBackBuffer->GetDesc(&pDesc);
		POINT pDestinationPoint;
	
		for (int i=0; i<4; i++)
		{
			pDestinationPoint.x = i*pSrcInfo.Width;
			for (int j=0; j<4; j++)
			{
				pDestinationPoint.y = j*pSrcInfo.Height;


				if (SUCCEEDED(back = g_pd3dDevice->UpdateSurface(ppOffScreen, NULL, ppBackBuffer, &pDestinationPoint)))
				{
					back = 0;
				}	
			}
		}
	}
	ppBackBuffer->Release();
	ppOffScreen->Release();
	

	

	/*
	if (SUCCEEDED(back =  g_pd3dDevice->CreateRenderTarget(
		256,
		256,
		D3DFMT_R8G8B8,
		D3DMULTISAMPLE_NONE,
		0,
		true,
		&ppBackBuffer,
		NULL)))
		*/

	/*if (SUCCEEDED(back = g_pd3dDevice->CreateDepthStencilSurface(
		256,
		256,
		D3DFMT_D16,
		D3DMULTISAMPLE_NONE,
		0,
		true,
		&ppBackBuffer,
		NULL)))*/
	//if (SUCCEEDED(g_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &ppBackBuffer)))
/*

		
		D3DLOCKED_RECT pLockedRect;
		if (SUCCEEDED(back = ppBackBuffer->LockRect(&pLockedRect, NULL, D3DLOCK_READONLY)))
		{
			back=1;
		}
		
		

*/




				
/*

		HDC phdc;

		if (SUCCEEDED(back = ppBackBuffer->GetDC(&phdc)))

		//if (SUCCEEDED(back = ppBackBuffer->LockRect(&pLockedRect, NULL, D3DLOCK_READONLY)))
		{
			BYTE* pSrcTopRow = (BYTE*)pLockedRect.pBits;
			DWORD dwSrcPitch = (DWORD)pLockedRect.Pitch;
			*pSrcTopRow =1;
			//for(int i=0;i<1;i++)
			//	*(pSrcTopRow+(i*dwSrcPitch)) = 1;

		}
		else if (back == D3DERR_INVALIDCALL)
		{
			back = 0;
		}
		else if(back == D3DERR_WASSTILLDRAWING)
		{
			back = 0;
		}

*/
//		ppBackBuffer->UnlockRect();


}