Jump to content
  • Advertisement

Archived

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

Coaster Kev

Direct Draw Initilization....

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

Here is the problem, I''ve been trying for hours to get this code to work, but I keep getting an error. Here is the DirectDraw Initilization code:
  
// Attempt to create a Direct Draw interface

	if ((DirectDrawCreateEx(NULL, (void **) &lpDD, IID_IDirectDraw7, NULL)) != DD_OK) 
	{
		MessageBox(NULL, "Create Error", "ERROR", MB_OK);
		return false;
	}
	// Attempt to take full control of the system

	if ((lpDD->SetCooperativeLevel(hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE)) != DD_OK) 
	{
		MessageBox(NULL, "Co-Op Error", "ERROR", MB_OK);
		return false;
	}
	// Attempt to change the screen resolution

	if ((lpDD->SetDisplayMode(800, 600, 16, 0, 0)) !=DD_OK) 
	{
		MessageBox(NULL, "Display Error", "ERROR", MB_OK);
		return false;
	}
	
	// Prepare to create the primary Direct Draw surface

	DDSURFACEDESC2 ddsd;
	ZeroMemory(&ddsd, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags =	DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
    ddsd.ddsCaps.dwCaps =	DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | 
		DDSCAPS_3DDEVICE | DDSCAPS_COMPLEX;
    ddsd.dwBackBufferCount = 1;
	
	
	// Attempt to create the primary Direct Draw surface

	if ((lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL)) != DD_OK) 
	{
		MessageBox(NULL, "Surface Error", "ERROR", MB_OK);
		return false;
	}
	
	// Prepare to retrieve the back buffer surface

	DDSCAPS2 ddscaps;
	ZeroMemory(&ddscaps, sizeof(ddscaps));
	ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
	
	// Attempt to retrieve the back buffer surface

	if ((lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBackBuffer)) != DD_OK) 
	{
		MessageBox(NULL, "Get Surface Error", "ERROR", MB_OK);
		return false;
	}

  
I get the "Co-Op Error", and I can''t figure out why? I tried setting it to normal, but then I get the "Surface Error". Thanks alot.

Share this post


Link to post
Share on other sites
Advertisement
can''t see anything wrong with the code..
Check the return value, it can be one of the following values:
DDERR_EXCLUSIVEMODEALREADYSET
DDERR_HWNDALREADYSET
DDERR_HWNDSUBCLASSED
DDERR_INVALIDOBJECT
DDERR_INVALIDPARAMS
DDERR_OUTOFMEMORY

Share this post


Link to post
Share on other sites
Not sure, but I need to QueryInterface() when I initialize... I think that''s for a different version of DirectX though

Share this post


Link to post
Share on other sites
Coaster Kev....are you SURE you''re passing it a VALID window handle?? I''ve had many problems in the past, only to discover my
window handle was crapola...

the easiest way is a:

if(hwnd == NULL){
MessageBox(NULL, "Beefcake! Beeeefcake!", "ERROR", MB_OK);
return FALSE;
}

Otherwise, your code looks okay..

Wazoo

Share this post


Link to post
Share on other sites
Wazoo, you were right. My window handle had nothing in it. Now I''m confused. How do I fill it or what do I fill it with? At least I know what the problem is...

Share this post


Link to post
Share on other sites
hurrah! I''m actually right!

Well Coaster Kev...in all windows platform programs, you MUST create a window handle which you can then use in your DirectX stuff...BUT before you can create a window handle you must first
register your class with Windows..

//try this..
WNDCLASS winClass;
HWND hwnd;

winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance; //our instance handle
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION)
winclass.hCursor = LoadCursor(NULL, IDC_ARROW)
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH)
winclass.lpszMenuName = NULL
winclass.lpszClassName = "Project1"

//attempt to register it
if(!RegisterClass(&winclass))
return(0);

//create our window handle HERE!
hwnd = CreateWindow("Project1",
"Game 1",
WS_OVERLAPPEDWINDOW,
0,0,
800,600,
GetDesktopWindow(),
NULL,
winclass.hInstance,
NULL);
if(hwnd == NULL)
//error creating main window handle
return(0);


//NOW our hwnd contains our window handle to this application!

That should be more than enough to help you out...

Wazoo

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!