Advertisement

Help w/ Creating a Primary Surface in DX.

Started by August 14, 2002 09:46 AM
2 comments, last by DrunkenBastard 22 years, 3 months ago
I am going through Tricks of Windows Game Programming Gurus and have got to chapter 6 which deals with setting up DirectDraw. Now everything was fine until I tryed to create a primary surface. As always I am stuck . So if any of you would be kind enough to help me again(im retarded) I would be verry greatful. anyway heres the code:
    

// DirectX setup *********************************************************************************

LPDIRECTDRAW7			lpdd7 = NULL;
LPDIRECTDRAWPALETTE		lpddPal = NULL;
LPDIRECTDRAWSURFACE7	lpddsPrimary = NULL;

DDSURFACEDESC2			ddsd;

// MS recommends clearing out struct

memset(&ddsd, 0, sizeof(ddsd));

ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;


// GameInit **************************************************************************************

int GameInit(void *parms, int iNumParms){

	// Initialize here

	int i; // loop counter




	// Create Palette for use with 256 color//////////////////////////

	PALETTEENTRY pePalette[256];

	// fill pallette with color

	for(i = 0; i < 256; i++)
	{

		pePalette[i].peRed = i;
		pePalette[i].peGreen = i;
		pePalette[i].peBlue = i;

		pePalette[i].peFlags = PC_NOCOLLAPSE;

	}// end for




	// Init DDraw ///////////////////////////////////////////////////


	if(FAILED(DirectDrawCreateEx(NULL, (void**)&lpdd7, IID_IDirectDraw7, NULL)))
	{

		//error

		ErrorMsg("DirectDrawCreateEx Failed");
		return(0);

	}// end if



	if(FAILED(lpdd7->SetCooperativeLevel(gMainHWND,
										 DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX |
										 DDSCL_EXCLUSIVE  | DDSCL_ALLOWREBOOT)))
	{
		//error

		ErrorMsg("Failed to set windows cooperation level");
		return(0);
	}

	if(FAILED(lpdd7->SetDisplayMode(gdwScreenWidth, gdwScreenHeight,
								    gdwScreenBPP, gdwScreenRefresh, 0)))
	{
		//error

		ErrorMsg("Failed to set Display Mode");
		return(0);
	}




	// Initialize our palette ///////////////////////////////////////////////////////

	if(FAILED(lpdd7->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE,
								   pePalette, &lpddPal, NULL)))
	{
		//error

		ErrorMsg("Failed to Create Color Palette");
		return(0);
	}



	// Create primary surface

	if(FAILED(lpdd7->CreateSurface(&ddsd, &lpddsPrimary, NULL)))
	{
		//error

		ErrorMsg("Could not create primary surface");
	}

	return(0);


}// end GameInit




// GameShutDown **********************************************************************************

int GameShutDown(void *parms, int iNumParms){


	if(lpdd7)
	{
		lpdd7->Release();
		lpdd7 = NULL;
	}// end if


	if(lpddPal)
	{
		lpddPal->Release();
		lpddPal = NULL;
	}

	if(lpddsPrimary)
	{
		lpddsPrimary->Release();
		lpddsPrimary = NULL;
	}

	return(0);


}// end GameShutDown


     
and here is the error:
  
--------------------Configuration: DirectDraw - Win32 Debug--------------------
Compiling...
DirectDraw.cpp
C:\DirectDraw\DirectDraw.cpp(33) : error C2501: 'memset' : missing storage-class or type specifiers
C:\DirectDraw\DirectDraw.cpp(33) : error C2373: 'memset' : redefinition; different type modifiers
        c:\program files\microsoft visual studio\vc98\include\string.h(103) : see declaration of 'memset'
C:\DirectDraw\DirectDraw.cpp(33) : error C2078: too many initializers
C:\DirectDraw\DirectDraw.cpp(34) : error C2143: syntax error : missing ';' before '.'
C:\DirectDraw\DirectDraw.cpp(34) : error C2501: 'ddsd' : missing storage-class or type specifiers
C:\DirectDraw\DirectDraw.cpp(34) : error C2371: 'ddsd' : redefinition; different basic types
        C:\DirectDraw\DirectDraw.cpp(32) : see declaration of 'ddsd'
C:\DirectDraw\DirectDraw.cpp(34) : error C2143: syntax error : missing ';' before '.'
C:\DirectDraw\DirectDraw.cpp(35) : error C2143: syntax error : missing ';' before '.'
C:\DirectDraw\DirectDraw.cpp(35) : error C2501: 'ddsd' : missing storage-class or type specifiers
C:\DirectDraw\DirectDraw.cpp(35) : error C2371: 'ddsd' : redefinition; different basic types
        C:\DirectDraw\DirectDraw.cpp(32) : see declaration of 'ddsd'
C:\DirectDraw\DirectDraw.cpp(35) : error C2143: syntax error : missing ';' before '.'
C:\DirectDraw\DirectDraw.cpp(36) : error C2143: syntax error : missing ';' before '.'
C:\DirectDraw\DirectDraw.cpp(36) : error C2501: 'ddsd' : missing storage-class or type specifiers
C:\DirectDraw\DirectDraw.cpp(36) : error C2371: 'ddsd' : redefinition; different basic types
        C:\DirectDraw\DirectDraw.cpp(32) : see declaration of 'ddsd'
C:\DirectDraw\DirectDraw.cpp(36) : error C2143: syntax error : missing ';' before '.'
Error executing cl.exe.

DirectDraw.exe - 15 error(s), 0 warning(s)

---------------------------------------------------------------
  
if I take out the memset line in my code the top 3 errors go away, but I don't think leaving that out would be good, and I'm stumped on the rest of them. So if any of you know the answer to this I would be greatly appreciative. p.s. Thanks to everyone who has taken time to answer my questions in the past. [edited by - DrunkenBastard on August 14, 2002 10:48:11 AM]

You''re trying to initialize the ddsd structure outside of a function, which won''t work. You have to move that block of code (the one with ''memset'' in it) into GameInit().
Advertisement
Also it looks like you don''t #include any of the necessary headers.

It''s time to learn the basics of C instead of jumping into DirectX.

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
Thank you verry much Torin that worked.

siaspete: I didn''t post my headder code, so I don''t know what you think I''m not including???

This topic is closed to new replies.

Advertisement