Jump to content
  • Advertisement
Sign in to follow this  
Drakon

DirectDraw - Failing to create back buffer

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

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)

{
WNDCLASS		windowClass;
HWND			hwnd;

	// fill out the window class structure
	//windowClass.cbSize			= sizeof(WNDCLASS);
	windowClass.style			= CS_HREDRAW || CS_VREDRAW;
	windowClass.lpfnWndProc		= WndProc;
	windowClass.cbClsExtra		= 0;
	windowClass.cbWndExtra		= 0;
	windowClass.hInstance		= hInstance;
	windowClass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);			// default icon
	windowClass.hCursor			= LoadCursor(NULL, IDC_ARROW);				// default arrow
	windowClass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);		// white background
	windowClass.lpszMenuName	= NULL;										// no menu
	windowClass.lpszClassName	= "MyClass";
	//windowClass.hIconSm			= LoadIcon(NULL, IDI_WINLOGO);			// windows logo small icon
	
	if (!RegisterClass(&windowClass)) 
	{
	//	cErrorReporter.WriteErrorMessage(ERR_REGISTERCLASS,true);
	}

	hwnd = CreateWindowEx(NULL,								// extended style
						  "MyClass",						// class name
						  "A REAL Windows Application!",	// app name
						  WS_POPUP | WS_VISIBLE,	// style
						  100, 100,							// x,y coordinate
						  400, 400,							// width, height
						  NULL,								// handle to parent
						  NULL,								// handle to menu
						  hInstance,						// application instance
						  NULL);
	
	if (!hwnd) 
	{
	//	cErrorReporter.WriteErrorMessage(ERR_CREATEWIN,true);
	}

	ShowWindow(hwnd,nCmdShow);
	UpdateWindow(hwnd);

LPDIRECTDRAW7 lpDD = NULL;
LPDIRECTDRAWSURFACE7 lpDDSPrimary = NULL;
LPDIRECTDRAWSURFACE7 lpDDSBack = NULL;
DDSURFACEDESC2 ddsd;
DDSCAPS2 ddscaps;

if ( FAILED( DirectDrawCreateEx( NULL, ( LPVOID* )&lpDD,IID_IDirectDraw7, NULL ) ) )
{
   return FALSE;
}

if ( FAILED( lpDD->SetCooperativeLevel( hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT ) ) )
   return FALSE;

if ( FAILED( lpDD->SetDisplayMode( 800, 600, 16, 0, 0 ) ) )
   return FALSE;

ZeroMemory( &ddsd, sizeof( ddsd ) );
ddsd.dwSize = sizeof( ddsd );

ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;

ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
                      DDSCAPS_FLIP | DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 1;

if ( FAILED( lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL ) ) )
   return FALSE;


************************
if ( FAILED( lpDDSPrimary->GetAttachedSurface( &ddscaps, &lpDDSBack ) ) )
   return FALSE;
************************


return TRUE;
}

(I hope I remember how to do the code tags right...) I was trying to do some direct draw tutorials, and after some testing, I've found that the code between the stars at the very bottom(The stars are not in the actual code, so thats not the problem...) fails, and returns false, causing my window to immediately fullscreen and immediately close afterwards when running. I think I've included all the relevant code. If you need to see the rest of the program, just let me know. Edited by Coder: Used source tags instead of code tags. Source tags are preferrable with 'wide' listings of code [Edited by - Coder on August 9, 2005 11:41:06 AM]

Share this post


Link to post
Share on other sites
Advertisement
After "backBufferCount=1" add
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
and after your "CreatSurface" call, specify
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;

I had a look at my code, and that was the only difference b/w the two :P Oh, I also don't declare a DDSCAPS2 ddscaps; var, but...w/e. HOpe this helps

...
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
DDSCAPS_FLIP | DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 1;

***ADDED THIS***
//complex , flipable
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;

if ( FAILED( lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL ) ) )
return FALSE;

**ADDED THIS***
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;

if ( FAILED( lpDDSPrimary->GetAttachedSurface( &ddscaps, &lpDDSBack ) ) )
return FALSE;


Share this post


Link to post
Share on other sites
ddsd.dwFlags = DDSD_CAPS
There I think. You specify that DDSD will contain a valid DDSDCAPS member. Then DX knows this is valid, so you can then use it. Either way, I don't have one, and it workds just dandy. Here is my start up code. Hope this helps. Try it without declaring that one variable, and with the added code. I'm 99% sure you don't need DDSDCAPS2 <name>. I learnt all this code from André LaMothe's book, "Tricks of the Game Programming Gurus, 2nd edition"

//DirectDraw7 Specific
LPDIRECTDRAW7 lpdd; //version 7.0 main
DDSURFACEDESC2 ddsd; //primary surface descriptor
LPDIRECTDRAWSURFACE7 DDback; //DD backbuffer surface
LPDIRECTDRAWSURFACE7 DDprimary; //DX primary surface

void MercuryEngine::Load()
{
// create IDirectDraw interface 7.0 object and test for error
if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)))
Application->MessageBoxA("Error: Can't initialize DirectDraw 7","Error",MB_OK);

// set cooperation to fullscreen
lpdd->SetCooperativeLevel(/*Handle*/Form1->Handle, DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT);

//set display mode
lpdd->SetDisplayMode(Screen_Width,Screen_Height,32,0,0); //Change this to 1024x768

//M$ says clean out our struct
memset(&ddsd,0, sizeof(ddsd));

//tell DirectX the size of ddsd
ddsd.dwSize = sizeof(ddsd);

//tell DX what valid data we will be giving it
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;

//backbuffer count
ddsd.dwBackBufferCount = 1;

//complex , flipable
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;

//now create the primary surface
if(FAILED(lpdd->CreateSurface(&ddsd,&DDprimary,NULL)))
Application->MessageBoxA("Error: Can't create primary surface","Error", MB_OK);

ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;

//atach backbuffer
if(FAILED(DDprimary->GetAttachedSurface(&ddsd.ddsCaps, &DDback)));

}



GL, and I hope this helps!

//Edit. BTW, I use BCB6, thus the Form1->Handle, and Application->MessageBoxA() stuff.

Share this post


Link to post
Share on other sites
Drakn man,send me a PM, I cant see ur msgs btw this keybard is brken, thus the bad writing

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!