Skip to main content
gamedev.net
🔒 Locked

DirectX initialization?

Started by AJBats Apr 3, 2011 at 11:47 PM 9 replies 3.5k views
Original Post
AJBats
AJBats
I have a horribly newb question as I don't even know the proper terminology to describe my problem. Please bare with me .

I'm testing a simple game demo on different machines, one of them being 32bit windows XP SP3 that has never had a game loaded on it once. So its fairly untouched territory.

My game demo runs, but it very slowly. At first I put this down to simply the machine is old. However... (please bare with me with this circumstantial evidence)... I loaded a simple 2D game onto the machine (Cave Story) and that ran fine. I noticed that if I left Cave Story running in the background, then my game demo ran at full speed no problem. And of course when Cave Story was closed my game slowed down.

This seems like I'm missing something in my setup code that, without causing either program to crash, the Cave Story instance is providing that my game demo is benefiting from. Maybe it's enabling some resources that are not turned on by default? I should mention that my game demo runs at full speed on my PC where I develop, which is 64bit win7 with game hardware.

Here is the directX init code I'm using (lifted from a directX sample):


HRESULT SCEngine::initDirect3D(HWND hWnd)
{
if ((screenWidth == 0) || (screenHeight == 0)) return S_FALSE;

direct3D = Direct3DCreate9( D3D_SDK_VERSION );

D3DCAPS9 d3dCaps;
direct3D->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps );

D3DDISPLAYMODE d3ddm;
direct3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm );

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

if( windowed == true )
{
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
}
else
{
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferWidth = screenWidth;
d3dpp.BackBufferHeight = screenHeight;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
}

d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
//d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // Do NOT sync to vertical retrace
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; // Sync to vertical retrace
d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;

direct3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3dDevice );

D3DXMATRIX matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian( 45.0f ), (float)(screenWidth / screenHeight), 0.1f, 100.0f );
d3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

d3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
d3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

D3DXCreateSprite(d3dDevice, &d3dXSprite );

return S_OK;
}



Hopefully someone can tell me I'm missing something simple?
DrunkMonkey25
DrunkMonkey25
Strange problem, indeed...

What are the mahcine specs? Are the drivers up to date? Your init code looks nearly identical to mine (except I use shaders) so I don't think you are doing anything wrong there (unless we both are...)

If you would like to send me the executable I could test it. I run XP SP3, an Intel 1.6 GHz single core with a GeForece Ti 6200 (fully DX9 compliant).
AJBats
AJBats

Strange problem, indeed...

What are the mahcine specs? Are the drivers up to date? Your init code looks nearly identical to mine (except I use shaders) so I don't think you are doing anything wrong there (unless we both are...)

If you would like to send me the executable I could test it. I run XP SP3, an Intel 1.6 GHz single core with a GeForece Ti 6200 (fully DX9 compliant).



Sure thing here it is. Arrows to move and Z to jump/float. It's supose to run at 60fps.

The machine I tested it with was intentionally left alone, as I'm trying to produce a highly compatible exe that can be distributed as a demo to anyone. I read that winXP SP2 comes with full DirectX 9.0c, so for my demo builds I use that SDK so there's no need for a redist. At least that's the idea.

The test PC is fast enough to run it full speed, since it did pull it off after all. But it only did it when another game was running in the background. If there's something I can do to make it run properly in any environment, I'd love to incorporate that code.
DrunkMonkey25
DrunkMonkey25
That archive is corrupted. Both WinRAR and Windows' internal method give errors.

Buckeye
Buckeye
First, in the code you've posted, you're not doing any error checking. Every DirectX function gives some indication of success or failure. If you're looking for problems, give yourself a chance to find them! If the remainder of your code has the same lack of error checking, you're asking people to look for problems you could be looking for yourself.

Does the Debug Runtime provide information? I realize that may not be convenient on a non-development machine.

Also, you're using software vertex processing which could make a difference in performance between different CPUs.

EDIT: If I had to guess, I'd say you picked up the code at DirectXTutorial.com. If so, you may want to see some comments about the site. A lot of beginning programmers had picked up some bad habits from that site. As an alternative, the SDK provides examples written by Microsoft, the people who also wrote the API.
Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly. You don't forget how to play when you grow old; you grow old when you forget how to play.
AJBats
AJBats

That archive is corrupted. Both WinRAR and Windows' internal method give errors.


That's odd. I've given this to a few people and the had no issues. Perhaps the upload went wrong? If your still interested I'll put it on a free hosting site.

@tempBuckeye
Using the hardware vertex processing didn't help. I'll try one of these empty starter projects in the DirectX samples to see if that does it.

Thanks for the tips.
DrunkMonkey25
DrunkMonkey25

That's odd. I've given this to a few people and the had no issues. Perhaps the upload went wrong? If your still interested I'll put it on a free hosting site.


Sure I'll try it out. Did it run full speed on other peoples' machines?
AJBats
AJBats

Sure I'll try it out. Did it run full speed on other peoples' machines?


http://www.sendspace.com/file/x4pers

For the people I gave it to they said it ran full speed. They all had either vista or win7 machines.
DrunkMonkey25
DrunkMonkey25
Its "smoothly choppy" on my machine. I'd say the framerate is well below 60, and there is lots of tearing while moving. I tried starting my current project in the background, as well as Fallout 2 and there was no speed increase in either case.

I wish I could give you an idea of where to start, but if it runs fine on Vista/7 then I don't have a clue. Sorry and good luck

AJBats
AJBats

Its "smoothly choppy" on my machine. I'd say the framerate is well below 60, and there is lots of tearing while moving. I tried starting my current project in the background, as well as Fallout 2 and there was no speed increase in either case.

I wish I could give you an idea of where to start, but if it runs fine on Vista/7 then I don't have a clue. Sorry and good luck




Thanks, at least I know its consistent. I'm sure the solution is in those directx samples.
unbird
unbird
Win XP 32 bit, 2GHz Intel, Geforce 8500 GT. Runs at smooth 60 Hz, neither CPU nor GPU go over 10%.

This one caught my eye:


d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;

Never used this flag but it's probably only useful when doing software rendering and using DirectX to "blit". You render the usual way, so I wonder if you need this flag. The docs state:


Lockable back buffers incur a performance cost on some graphics hardware configurations.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.