Archived

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

DDraw init fails - help me!?

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

My DDraw initialization works fine and dandy on my computer, and several others, but on many systems it crashes on load. Could someone post their bare-bones DDraw initialization routines here for reference? Not that I want to cut-and-paste (steal) your code, just I really think I''m doing something wrong at the basic level. Thanks, ~BenDilts( void );

Share this post


Link to post
Share on other sites
It''s probably because they don''t have support for the screen resolution you''ve requested. You have to enumerate all the devices available and then choose the one that best suits your needs before calling SetDisplayMode().

-------------------------------------
That's just my 200 bucks!

..-=gLaDiAtOr=-..

Share this post


Link to post
Share on other sites
int InitDDraw(HWND hwnd, LPDIRECTDRAW7 &DDraw, LPDIRECTDRAWSURFACE7 &Primary, LPDIRECTDRAWSURFACE7 &Back, int xSize, int ySize, int bpp)
{
HRESULT ddrval;
DDSCAPS2 ddscaps;
DDSURFACEDESC2 ddsd;
ddrval = DirectDrawCreateEx(NULL, (VOID**)&DDraw, IID_IDirectDraw7, NULL);
if (ddrval!=DD_OK)
return 1;
ddrval = DDraw->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT);
if (ddrval!=DD_OK)
return 2;
ddrval = DDraw->SetDisplayMode(xSize, ySize, bpp, 0, 0);

if (ddrval!=DD_OK)
return 3;
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY;
ddsd.dwBackBufferCount = 1;

ddrval = DDraw->CreateSurface(&ddsd, &Primary, NULL);
if (ddrval!=DD_OK)
return 4;
ZeroMemory(&ddscaps, sizeof(ddscaps));
ddscaps.dwCaps = DDSCAPS_BACKBUFFER | DDSCAPS_VIDEOMEMORY;
ddrval = Primary->GetAttachedSurface(&ddscaps, &Back);
if (ddrval!=DD_OK)
return 5;

return 0;
}

Shouldn''t this work? Or maybe it''s the flipping routine:

void FlipMain(LPDIRECTDRAWSURFACE7 &Primary)
{
HRESULT ddrval;
while(1)
{
ddrval = Primary->Flip(NULL, 0);
if(ddrval == DD_OK)
{
break;
}
if(ddrval == DDERR_SURFACELOST)
{
ddrval = Primary->Restore();
if(ddrval != DD_OK)
{
break;
}
}
if(ddrval != DDERR_WASSTILLDRAWING)
{
break;
}
}
}

Thx.

Share this post


Link to post
Share on other sites
Also, if u have time, my D3D (I started 2day, give me a break) init:

int InitD3D(LPDIRECTDRAW7 DDraw, LPDIRECT3D7 D3D, LPDIRECT3DDEVICE7 D3DDevice, LPDIRECTDRAWSURFACE7 d3dsurface,
int xs, int ys)
{
DDSURFACEDESC2 ddsd;
HRESULT hr;

DDraw->QueryInterface( IID_IDirect3D7, (VOID**)&D3D );

// Check the display mode, and
ddsd.dwSize = sizeof(DDSURFACEDESC2);
DDraw->GetDisplayMode( &ddsd );
if( ddsd.ddpfPixelFormat.dwRGBBitCount <= 8 )
return DDERR_INVALIDMODE;

// The GUID here is hard coded. In a real-world application
// this should be retrieved by enumerating devices.
hr = D3D->CreateDevice( IID_IDirect3DHALDevice, d3dsurface,
&D3DDevice );
if( FAILED( hr ) )
{
// If the hardware GUID doesn''t work, try a software device.
hr = D3D->CreateDevice( IID_IDirect3DRGBDevice, d3dsurface,
&D3DDevice );
if( FAILED( hr ) )
return 0;
}
D3DVIEWPORT7 vp = { 0, 0, xs, ys, 0.0f, 1.0f };

hr = D3DDevice->SetViewport( &vp );
if( FAILED( hr ) )
return 0;

D3DMATERIAL7 mtrl;
ZeroMemory( &mtrl, sizeof(mtrl) );
mtrl.ambient.r = 1.0f;
mtrl.ambient.g = 1.0f;
mtrl.ambient.b = 0.0f;
D3DDevice->SetMaterial( &mtrl );

// The ambient lighting value is another state to set. Here, we are turning
// ambient lighting on to full white.
D3DDevice->SetRenderState( D3DRENDERSTATE_AMBIENT, 0xffffffff );

// Start by setting up an identity matrix.
D3DMATRIX mat;
mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;

// The world matrix controls the position and orientation
// of the polygons in world space. We''ll use it later to
// spin the triangle.
D3DMATRIX matWorld = mat;
D3DDevice->SetTransform( D3DTRANSFORMSTATE_WORLD, &matWorld );

// The view matrix defines the position and orientation of
// the camera. Here, we are just moving it back along the z-
// axis by 10 units.
D3DMATRIX matView = mat;
matView._43 = 10.0f;
D3DDevice->SetTransform( D3DTRANSFORMSTATE_VIEW, &matView );

// The projection matrix defines how the 3-D scene is "projected"
// onto the 2-D render target surface. For more information,
// see "What Is the Projection Transformation?"

// Set up a very simple projection that scales x and y
// by 2, and translates z by -1.0.
D3DMATRIX matProj = mat;
matProj._11 = 2.0f;
matProj._22 = 2.0f;
matProj._34 = 1.0f;
matProj._43 = -1.0f;
matProj._44 = 0.0f;
D3DDevice->SetTransform( D3DTRANSFORMSTATE_PROJECTION, &matProj );

return 1;
}

Then I draw:

if( FAILED( D3DDevice->BeginScene() ) )
Ending = true;

D3DVECTOR p1( 0.0f, 3.0f, 0.0f );
D3DVECTOR p2( 3.0f,-3.0f, 0.0f );
D3DVECTOR p3(-3.0f,-3.0f, 0.0f );

D3DVECTOR vNormal( 0.0f, 0.0f, 1.0f );
D3DVERTEX tv[6];
// Initialize the 3 vertices for the front of the triangle
tv[0] = D3DVERTEX( p1, vNormal, 0, 0 );
tv[1] = D3DVERTEX( p2, vNormal, 0, 0 );
tv[2] = D3DVERTEX( p3, vNormal, 0, 0 );

// Initialize the 3 vertices for the back of the triangle
tv[3] = D3DVERTEX( p1, -vNormal, 0, 0 );
tv[4] = D3DVERTEX( p3, -vNormal, 0, 0 );
tv[5] = D3DVERTEX( p2, -vNormal, 0, 0 );

D3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, D3DFVF_VERTEX,
tv, 6, NULL );

D3DDevice->EndScene();

This dies on the BeginScene()! Must be in the init.

Share this post


Link to post
Share on other sites
I just saw what is wrong with your code.
You are trying to create the DirectDraw object with a LPDIRECTDRAW4 interface.

When you create a DirectDraw object you always create it with a LPDIRECTDRAW interface and then you quarry for the LPDIRECTDRAW4 interface.

Some source of how to do it:
            //Create a DirectDraw interface

if( FAILED( DirectDrawCreate(NULL, &lpdd, NULL)))
Error("Couldn't create temporary DirectDraw interface");
logis.Log("klarade 6%d", i);

//Query for the latest interface

if( FAILED( lpdd->QueryInterface(IID_IDirectDraw4, (void**)&lpdd4)))
Error("Couldn't query for DirectDraw4 interface for temporary use");
logis.Log("klarade 7%d", i);


Note:
This is for version 6 of the DirectX sdk.

Edited by - Mr Cucumber on July 18, 2000 2:00:46 PM

Share this post


Link to post
Share on other sites
Mr Cucumber: In DX7, you don''t do that. You call DirectDrawCreateEx, and give it an IID_DirectDraw7 pointer, and it fills it with a DD7 instance pointer.

Funky, eh?

TheTwistedOne
http://www.angrycake.com

Share this post


Link to post
Share on other sites
Sorry.

I am a little behind when it comes to DirectX development.

One more thing that might be the error is that you send references for the DirectDraw and the surface object.

They are already pointers so there is no point to send them as references. Try removing the '&'.

Edited by - Mr Cucumber on July 19, 2000 1:53:21 PM

Share this post


Link to post
Share on other sites
The following issue might be the problem:

The backbuffer is not created during the call to GetAttachedSurface(). It is created as part of the COMPLEX|FLIPPING primary surface.

Therefore, when specifying DDSDCAPS_VIDEOMEMORY in the call to CreateSurface(), the backbuffer is already created in videomemory. The call to GetAttachedSurface() only retreives a pointer to the backbuffer, so there''s no need to include the DDSDCAPS_VIDEOMEMORY flag.

I don''t think this will solve your problem though, because I tried including the flag, and it was simply ignored...

As far as I know, the primary- and backbuffer are always located in the same type of memory. Can anyone confirm this?

Share this post


Link to post
Share on other sites
I didn''t read any of the replies, but this might be the answer: Since you say that the code works fine on your computer but not on others'' computers, maybe you should try to set the ACTIVE CONFIGURATION in Vc++ to RELEASE. Build-Set Active Configuration.

Hope that helped,
Martin

Share this post


Link to post
Share on other sites
quote:

As far as I know, the primary- and backbuffer are always located in the same type of memory. Can anyone confirm this?



If it can fit, it is.
In Mr. Cucomber''s case, he''ll need a 2 mb video card for both surfaces to be in video memory.


Share this post


Link to post
Share on other sites