Bshivam Advanced DirectX Framework[v1.3]

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Chili Advanced DirectX Framework[UPDATE]

Post by LuX » February 1st, 2014, 12:39 am

Probably DirectX loses the device, thus the device and all stuff that needs to be loaded with the device, like Dx images etc. have to be reset. Just make a function the initializes everything again once the game gains focus.
ʕ •ᴥ•ʔ

User avatar
bshivam2001
Posts: 214
Joined: July 27th, 2013, 6:57 am
Location: India

Re: Chili Advanced DirectX Framework[UPDATE]

Post by bshivam2001 » February 1st, 2014, 5:49 am

Pindrought wrote:
bshivam2001 wrote: I figured out the code:
Change the following things in D3DGraphics::D3DGraphics Function D3DGraphics.cpp:

Code: Select all

d3dpp.Windowed = FALSE;  //Set to false to make it fullscreen and not windowed
d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; //Make sure you change this, or you get assertion error
d3dpp.BackBufferWidth = 1366; //Your screen width
d3dpp.BackBufferHeight = 768; //Your screen width
Awesome thanks Bshivam. Only one problem i'm running into. If I minimize while in full screen, and restore the game window, it doesn't seem to work. I just get a black screen for my window after minimizing. Any idea what i'm doing wrong?
Yeah....You have to reset everything bcoz when you restrore from full screen to window, DirectX loses the control from the window and deletes all the data saved, as if the window has been closed. As a result you get a black screen!
So you need to create a Reset() Function in that case...
'If you can't make it good, at least make it look good'

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Chili Advanced DirectX Framework[UPDATE]

Post by LuisR14 » February 1st, 2014, 11:43 am

yea, those 4 lines are what you need to change to initialize DX to fullscreen :)

well anyways here's basically what i had given to thetoddfather :)

Code: Select all

void D3DGraphics::ToggleFull()
{
	d3dpp.Windowed = !d3dpp.Windowed;
	if( !d3dpp.Windowed ) {   // this is just same as d3dpp.Windowed == FALSE
		d3dpp.BackBufferWidth = 1920;   // your screenwidth
		d3dpp.BackBufferHeight = 1080;  // your screenheight
 		SetWindowLongPtr( d3dpp.hDeviceWindow, GWL_STYLE, WS_POPUPWINDOW );
		SetWindowPos( d3dpp.hDeviceWindow, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED );    // everything set to 0 since IDirect3DDevice9::Reset() can set it
 	} else {
		d3dpp.BackBufferWidth = 0;    // again like above
		d3dpp.BackBufferHeight = 0;    // and again :P
		SetWindowLongPtr( d3dpp.hDeviceWindow, GWL_STYLE, WS_OVERLAPPEDWINDOW );
		SetWindowPos( d3dpp.hDeviceWindow, HWND_NOTOPMOST, <window pos x>, <window pos y>, <window width>, <window height>, SWP_SHOWWINDOW|SWP_FRAMECHANGED );
	}
	Reset();
}
Reset() above is basically:

Code: Select all

bool D3DGraphics::Reset()
{
	// Release D3DPOOL_DEFAULT resources, and resources that don't have a pool param
	// ReleaseRes();
	// basically in its own function it is
	if( pBackBuffer )
		pBackBuffer->Release(), pBackBuffer = nullptr;

	HRESULT result = pDevice->Reset( &d3dpp );
	if( FAILED(result) )  // can just check for D3DERR_DEVICELOST || D3DERR_DEVICENOTRESET
		return false;

	// ReCreate released resources above
	// CreateRes();
	// and basically the below in its own function
	result = pDevice->GetBackBuffer( 0,0,D3DBACKBUFFER_TYPE_MONO,&pBackBuffer );
	assert( !FAILED( result ) );

	return true;
}
for the code above you would have to move the D3DPRESENT_PARAMETERS variable declaration from the ctor to the header file and set hDeviceWindow :)

as for the losing of device aside from the above you would do the following to the BeginFrame and EndFrame funcs

Code: Select all

void D3DGraphics::BeginFrame()
{
    HRESULT result;

    result = pDevice->TestCooperativeLevel();
    if( result == D3DERR_DEVICELOST )
        return;
    else if( result == D3DERR_DEVICENOTRESET ) {
        if ( !Reset() )
            return;
    }

    result = pDevice->Clear( 0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,0),1.0f,0 );
    assert( !FAILED( result ) );

    result = pBackBuffer->LockRect( &backRect,NULL,NULL );
    assert( !FAILED( result ) );

    result = pDevice->BeginScene();
    assert(!FAILED(result));
}

void D3DGraphics::EndFrame()
{
    HRESULT result;

    result = pDevice->TestCooperativeLevel();
    if( result == D3DERR_DEVICELOST )
        return;
    else if( result == D3DERR_DEVICENOTRESET ) {
        Reset()
        return;
    }

    result = pDevice->EndScene();;
    assert(!FAILED(result));

    result = pBackBuffer->UnlockRect();
    assert( !FAILED( result ) );

    result = pDevice->Present( NULL,NULL,NULL,NULL );
    assert( !FAILED( result ) );
}
 
also you would call Reset whenever you receive a WM_SIZE message (which means you can remove the Reset() call in the ToggleFull func since the SetWindowPos funcs will generate WM_SIZE messages, and would also mean you'd have to devise a way to call the ToggleFull func from windows.cpp, which in the group game i just have a man-in-the-middle func declared in the game class that calls the reset func :P)

but actually the reset routines wouldn't work with the "advanced" (... -_- lol) framework since it would require a bit of rewrite (it requires that the fonts and d3dxsprite objects be released b4 calling IDirect3DDevice9::Reset() and then recreated after :P), the textures would be fine since they're being created with POOL_DEFAULT :)
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat :mrgreen: --

User avatar
bshivam2001
Posts: 214
Joined: July 27th, 2013, 6:57 am
Location: India

Re: Chili Advanced DirectX Framework[v1.3]

Post by bshivam2001 » February 26th, 2014, 1:16 pm

Try out the v1.3!!!
'If you can't make it good, at least make it look good'

Pindrought
Posts: 432
Joined: September 26th, 2013, 4:57 pm
Location: Kentucky
Contact:

Re: Chili Advanced DirectX Framework[v1.3]

Post by Pindrought » April 14th, 2014, 7:41 pm

Bshivam nice work! Would you mind posting an example of how to load an mp3 using the DSOjbect? I wasn't sure what to pass for the length parameter.
PM me if you need to contact me. Thanks to all the helpful people on this forum especially to Chili.

Post Reply