Jump to content
  • Advertisement

Archived

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

DrunkenBastard

Help w/ Creating a Primary Surface in DX.

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

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]

Share this post


Link to post
Share on other sites
Advertisement

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().

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!