Advertisement

display problem

Started by December 17, 2000 06:11 PM
1 comment, last by omegasyphon 24 years ago
my problem is this, when my program runs it quits upon execution. when i go throught it with f10 i get an exception handling error when it calls game_init, it then goes to the following line of code offsurface = createsurface(WWIDTH,WHEIGHT,DDSCAPS_VIDEOMEMORY);
  

LPDIRECTDRAWSURFACE7 createsurface(int width, int height, int mem_flags)
{
// this function creates an offscreen plain surface


DDSURFACEDESC2 ddsd;         // working description

LPDIRECTDRAWSURFACE7 lpdds;  // temporary surface

// set to access caps, width, and height

memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize  = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CKSRCBLT;
// set dimensions of the new bitmap surface

ddsd.dwWidth  =  width;
ddsd.dwHeight =  height;

// set surface to offscreen plain

ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | mem_flags;

if (FAILED(lpdd7->CreateSurface(&ddsd,&lpdds,NULL)))
   return(NULL);

// create the surface

   DDCOLORKEY color_key; // used to set color key

   color_key.dwColorSpaceLowValue  =rgb16bit(255,0,0);
   color_key.dwColorSpaceHighValue =rgb16bit(255,0,0);
   // now set the color key for source blitting

   lpdds->SetColorKey(DDCKEY_SRCBLT, &color_key);


// return surface

return(lpdds);
} // end DDraw_Create_Surface


int bltsprite(LPDIRECTDRAWSURFACE7 lpddstemp,LPDIRECTDRAWSURFACE7 lpddstemp2,int sx,
			  int sy,int dx, int dy)
{

	RECT src_rect,dst_rect;

	src_rect.top	=	(sy*16)-1;  
	src_rect.left	=	(sx*16)-1;  
	src_rect.right	=	(sx*16)+31;
	src_rect.bottom	=	(sy*16)+31;


	dst_rect.top	=	dy;
	dst_rect.left	=	dx;
	dst_rect.right	=	dx+15;
	dst_rect.bottom	=	dy+15;


   // blt to destination surface

   if (FAILED(lpddstemp2->Blt(&dst_rect,lpddstemp,&src_rect,DDBLT_WAIT,NULL)))
           return(0);
return 1;
}

void readmap()
{
	int x,y;
	while(!fin.eof())
	{
		for(x=0;x<=20;x++)
		{
			for(y=0;y<=20;y++)
			{
				fin>>map.maplayer1[x][y];
			}
		}
	}
	fin.close();
}

void drawmap()
{
	int x=0,y=0,cntr,sx=1,sy=1;

	for (cntr=1;cntr<45;cntr++)
	{
		for (x=0;x<=20;x++)
		{
			for (y=0;y<=20;y++)
			{
			if (map.maplayer1[x][y]==cntr)
			bltsprite(offsurface,lpddsback,sx,sy,(sx*16)-1,(sy*16)-1);
			}
		}
	}
}
	

// WINX GAME PROGRAMMING CONSOLE FUNCTIONS ////////////////

int Game_Init(void *parms, int num_parms)
{
	fin.open("map1.txt");

// first create base IDirectDraw interface

	if (FAILED(DirectDrawCreate(NULL, &lpdd1, NULL)))
	return(0);

// now query for IDirectDraw7

	if (FAILED(lpdd1->QueryInterface(IID_IDirectDraw7,(LPVOID *)&lpdd7)))
	return(0);

// set cooperation to full screen

	if (FAILED(lpdd7->SetCooperativeLevel(main_window_handle,DDSCL_FULLSCREEN |
		DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
	return(0);


// set display mode

	if (FAILED(lpdd7->SetDisplayMode(WWIDTH,WHEIGHT,BPP,0,0)))
		return(0);

	DD_INIT_STRUCT(ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
	ddsd.dwBackBufferCount = 1;
	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
//create primary surface

	if (FAILED(lpdd7->CreateSurface(&ddsd, &lpddsprimary, NULL)))
	return 0;
//create offscreen surface

	offsurface = createsurface(WWIDTH,WHEIGHT,DDSCAPS_VIDEOMEMORY);
	ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
	if (FAILED(lpddsprimary->GetAttachedSurface(&ddsd.ddsCaps, &lpddsback)))
	return(0); 

	if (!loadbitmap(&bitmap,"base1.bmp"))
	return(0);
	offsurface->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL);
// get video pointer to primary surfce

	UCHAR *image_buffer = (UCHAR *)ddsd.lpSurface;
	for (int x=0;x<WHEIGHT;x++)
	{
		memcpy(ℑ_buffer[x*ddsd.lPitch],&bitmap.buffer[x*WWIDTH*2],WWIDTH*2);
	}
	if (FAILED(offsurface->Unlock(NULL)))
	return 0;
	readmap();
	unloadbitmap(&bitmap);
	return 1; 
}

int Game_Main(void *parms, int num_parms)
{
	// make sure this isn''t executed again

	if (window_closed)
		return(0);

// for now test if user is hitting ESC and send WM_CLOSE

	if (KEYDOWN(VK_ESCAPE))
	{
		PostMessage(main_window_handle,WM_CLOSE,0,0);
		window_closed = 1;
	} // end if

		drawmap();
		lpddsprimary->Flip(NULL, DDFLIP_WAIT);
	return 1;
} // end Game_Main


int Game_Shutdown(void *parms, int num_parms)
{
	// now the primary surface

	if (lpddsprimary !=NULL)
		lpddsprimary->Release();
	return 1;


// release the directdraw object

	if (lpdd7!=NULL)
		lpdd7->Release();
	return 1;

// release the directdraw object

	if (lpdd1!=NULL)
		lpdd1->Release();
	return 1;
}

  
Why create your back buffer after you create an off screen plain? First set up your back buffer correctly.
Furthermore, you are using the variable name ddsd locally inside a function and what seems like a global variable (it is NOT declared inside your gameinit). Although not incorrect this may cause some confusion and maybe even the error. I haven''t tested any of this because i''d need the complete code. Although this might be quite useless, i gave it my best shot. Good luck.
Advertisement
show me the whole source code

if ( there''''s a will )
return ( there''''s a way );

This topic is closed to new replies.

Advertisement