• Advertisement

Archived

This topic is now archived and is closed to further replies.

DIRECTX IN 21 DAYS

This topic is 5042 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

can someone refer me to a directx tutorial site which is somewhat like a Sam Teach Yourself in 21 Days. Coz all the site I know doesnt explain DirectX that much.. Ive been to Nexe, andypike, gametutorials, drunken hyena. I still need a good tutorial of DirectX using C++, I understand DirectX the tutorials but I doubt it I can code on my own, so please can you refer a good tutorial site to me? thanks Above them all is Truth and Truth must be set free. If the wings of Truth are unclipped, the voices will fall silent

Share this post


Link to post
Share on other sites
Advertisement
What don''t you know about DirectX? I think you would learn it better if you create a small example game, and asked some nice folks for help along the way if you get stuck.

Cheers.

Share this post


Link to post
Share on other sites
im asking around, yet want i really need is a good tutorial, coz i would always be stuck if most of the tutorials online doesnt give that much explanation, and i dont want asking questions all the time. ryt now im kinda finding solutions about the problem ive encountered, when you minimize the window with DX, i receive an error about my adapter.. thanks for the reply

Share this post


Link to post
Share on other sites
when you fail when minimizing the window, you''are problably in a lost state.

i have -never- seen a site or a doc that explains clearly the misc initialisation of DirectX.

what you should know (ie i have learned):

in windowed mode, when the desktop has a video mode change (ie 32bpp to 16bpp), device is lost.

when fullscreen, having the app minimized cause a device lost.

so what to do when a device is lost ?

first test your adapter state with TestCooperativeLevel()
- if D3D_OK you can draw

- if different from D3D_OK, you''re probably in lost state, so:

1) wait that TestCooperativeLevel() return you D3DERR_DEVICENOTRESET

2) when D3DERR_DEVICENOTRESET is there:

a) destroy every DEFAULT_POOL ressources (textures/buggers)

b) do ->OnLostDevice() on all resources that expose a OnLostDevice()

c) if windowed: fix formats (ie desktop mode change) in your D3DPRESENT_PARAMETERS
if fullscreen: nothing to do
THEN call ->Reset() your Direct3D Device.

d) do ->OnResetDevice() on all ressources

e) recreate all your DEFAULT_POOL ressources

it''s the way i do it, now my engine is rock stable. (switching window/fullscreen, ALT-TABbing while windowed/fullscreen, changing deskop mode while windowed)

Share this post


Link to post
Share on other sites
quote:
Original post by bjone
i have -never- seen a site or a doc that explains clearly the misc initialisation of DirectX.

The documentation and the sample framework that comes with the SDK clearly state how to handle device loss correctly. You must''ve missed it

quote:
in windowed mode, when the desktop has a video mode change (ie 32bpp to 16bpp), device is lost.

when fullscreen, having the app minimized cause a device lost.

You don''t need to care about the scenarios of device loss, because it''s - by design - not limited to a fixed set. If a fullscreen application launches, for example, you''ll get a lost device. If power saving mode goes on, you''ll get a lost device, ...etc

quote:
first test your adapter state with TestCooperativeLevel()

Just to clarify: This is done every frame, before rendering. The call is pretty light, don''t be afraid of performance hits or anything.

quote:
b) do ->OnLostDevice() on all resources that expose a OnLostDevice()

Just to clarify, this destroys the D3DPOOL_DEFAULT resources of the relevant object.

quote:
c) if windowed: fix formats (ie desktop mode change) in your D3DPRESENT_PARAMETERS

Naturally, you do a GetAdapterDesktopMode (or some similar function name, I don''t recall) that returns the new display format.

Muhammad Haggag,
Optimize
Bitwise account: MHaggag -

Share this post


Link to post
Share on other sites
some implementation if it can help you:


while( msg.message!=WM_QUIT )
{
// engine PAUSED or window iconified =>

// process messages without drawing or else

// => minimal CPU usage (ie Outlook is asking you something

// while you were playing in fullscreen)

// using GetMessage so that kernel can allocate timeslices

// for other process

while( ( rGame->Pause || IsIconic(hWnd) ) && GetMessage( &msg, NULL, 0U, 0U ) && msg.message!=WM_QUIT )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}

// not pause or whatever, full blow CPU usage, max fps

while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) && msg.message!=WM_QUIT )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}

// if resetting, don't try anything

if( !VideoSetup->PerformingReset )
{
// adapter OK ?

HRESULT hr=d3dDevice->TestCooperativeLevel();

if( hr == D3D_OK )
rGame->Render(); // ya let's rock & roll

// huhuh lost state, waiting for the 'yes' to reset

else if( hr == D3DERR_DEVICENOTRESET ) {
if( VideoSetup->ResetAfterLostState() != D3D_OK )
throw("Lost state recovery failed bail out."); }

// here we have everything OK

rGame->UpdateStates();

EngineTimer.Refresh();
RunningTime+=EngineTimer.ftime;
}
}


and so, the ResetAfterLostState():


HRESULT D3DSetup::ResetAfterLostState()
{
PerformingReset=true; // flag to say don't touch D3D i'm resetting


GlobalOnDestroyDefaultPool(); // destroy DEFAULT_POOL


GlobalOnLostDevice(); // say OnLostDevice to the crowd


// if windowed repair backbuffer format

if( PresentParms.Windowed == TRUE )
PresentParms.SetToAdapterFormat(Interface,Adapter);

// reset

HRESULT hr=Device->Reset(&PresentParms);

// say OnResetDevice to the crowd

GlobalOnResetDevice();

// recreate DEFAULT_POOL

GlobalOnCreateDefaultPool();

PerformingReset=false; // you can go baby


return hr;
}



note that most of functions called are mine (GlobalOn....), but the goal is to give an exemple of how to manage a lost state.

note that the PerformingReset bool trick was when i started with Dx8, with DX9 it doesn't seems to have the same problem i encountered with DX8 (having the Reset() being nonblockable, and so having messages processed while resetting)


[edited by - bjone on May 7, 2004 4:04:32 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Coder
quote:
Original post by bjone
i have -never- seen a site or a doc that explains clearly the misc initialisation of DirectX.

The documentation and the sample framework that comes with the SDK clearly state how to handle device loss correctly. You must've missed it

quote:
in windowed mode, when the desktop has a video mode change (ie 32bpp to 16bpp), device is lost.

when fullscreen, having the app minimized cause a device lost.

You don't need to care about the scenarios of device loss, because it's - by design - not limited to a fixed set. If a fullscreen application launches, for example, you'll get a lost device. If power saving mode goes on, you'll get a lost device, ...etc

quote:
first test your adapter state with TestCooperativeLevel()

Just to clarify: This is done every frame, before rendering. The call is pretty light, don't be afraid of performance hits or anything.

quote:
b) do ->OnLostDevice() on all resources that expose a OnLostDevice()

Just to clarify, this destroys the D3DPOOL_DEFAULT resources of the relevant object.

quote:
c) if windowed: fix formats (ie desktop mode change) in your D3DPRESENT_PARAMETERS

Naturally, you do a GetAdapterDesktopMode (or some similar function name, I don't recall) that returns the new display format.

Muhammad Haggag,
Optimize
Bitwise account: MHaggag -


i agree with you at 99%, i only disagree in the fact the SDK nor the samples/tutorials are crystal clear on the lost state and how to handle it.

only after experimentation things comes out to the mind.

[edited by - bjone on May 7, 2004 3:50:23 PM]

Share this post


Link to post
Share on other sites
Drunken Hyena explain this as well. If you are using C++ you can learn the basics from DH, and from there it''s mostly just reading the MSDN (or SDK) documentation or searching the forums.

As for Managed Direct X I find DH to be a little skimpy, try CraigBlog.

Cheers!

Share this post


Link to post
Share on other sites
There are no good comprehensive up to date tutorials on DirectX. You have to learn by using these various random tutorials or else you''ll be learning old directx (which isn''t entirely useless, a lot of it stays the same).

It''s slow unfortunately, but this is your only path really. Run example programs, learn as much as you can, go to forums like this to ask questions and repeat.

It would be nice if there were some great book or something, but directx changes to fast for the speed of books. There are great books on 3D graphics in general (real-time rendering second edition comes to mind), but it will teach you theory not how to get it working in directx.

Share this post


Link to post
Share on other sites
thanks for all the info... it will help me alot.. im really trying hard to learn DX thats for sure! Im trying to write a tutorial as i go, so i think when im fully furnished with DX, then I can have a good tutorial site, and that would be how many years from now? anyway, thanks again, i really have this project due december.. ill post my project one of these days.. when i get more acquainted with dX. thanks again.. ill try the testCooperativelevel on the code.

Ive tried something earlier, in the event loop, i tested if the window is minimized or moximized, when it is minimized i dont put the render(), only when it is maximized or normal.. will it work well?

Share this post


Link to post
Share on other sites

  • Advertisement