Ejemplo n.º 1
0
DWORD PisteDraw_Videomuistia()
{
	DDCAPS hel_caps, hal_caps;

	DD_INIT_STRUCT(hel_caps);
	DD_INIT_STRUCT(hal_caps);	
	
	if (FAILED(PD_lpdd->GetCaps(&hal_caps,&hel_caps)))	
	{
		strcpy(virhe,"Cannot aquire system information!");
		return PD_VIRHE;
	}
	
	return hal_caps.dwVidMemFree;
}
Ejemplo n.º 2
0
int PisteDraw_Buffer_Tayta(int i, UCHAR color)
{
	DD_INIT_STRUCT(PD_ddbltfx);
	PD_ddbltfx.dwFillColor = color;	
	IDirectDrawSurface4 *buffer;

	if (i >= MAX_BUFFEREITA)
		return PD_VIRHE;

	if (PD_buffers[i].lpdds == NULL)
		return PD_VIRHE;

	buffer = PD_buffers[i].lpdds;
	
	RECT dest_rect;
	dest_rect.left	 =	0;
	dest_rect.right	 =	PD_buffers[i].leveys;
	dest_rect.top	 =	0;
	dest_rect.bottom =	PD_buffers[i].korkeus;	

	if (FAILED(buffer->Blt(&dest_rect, 
					 	   NULL, 
						   NULL, 
						   DDBLT_COLORFILL | DDBLT_WAIT, 
						   &PD_ddbltfx))) {
		PisteLog_Kirjoita("[Error] Piste Draw: Buffer fill failed!\n");
		return PD_VIRHE;
	}

	return 0;
}
Ejemplo n.º 3
0
DWORD PisteDraw_Videomuistia_Max()
{
	DDCAPS hel_caps, hal_caps;

	DD_INIT_STRUCT(hel_caps);
	DD_INIT_STRUCT(hal_caps);	
	
	if (FAILED(PD_lpdd->GetCaps(&hal_caps,&hel_caps)))	
	{
		strcpy(virhe,"Cannot aquire system information!");
		PisteLog_Kirjoita("[Error] Piste Draw: Cannot aquire system information! \n");
		return PD_VIRHE;
	}

	return hal_caps.dwVidMemTotal;
}
Ejemplo n.º 4
0
LPDIRECTDRAWSURFACE4 PisteDraw_Create_Surface(int width, int height, int mem_flags, UCHAR color)
{
	LPDIRECTDRAWSURFACE4	lpdds;

	DD_INIT_STRUCT(PD_ddsd);

	PD_ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;

	PD_ddsd.dwWidth		=	width;
	PD_ddsd.dwHeight	=	height;

	PD_ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | mem_flags;

	if (FAILED(PD_lpdd->CreateSurface(&PD_ddsd, &lpdds, NULL)))
		return(NULL);

	DDCOLORKEY color_key;
	color_key.dwColorSpaceLowValue	= color;
	color_key.dwColorSpaceHighValue = color;
	
	if(FAILED(lpdds->SetColorKey(DDCKEY_SRCBLT, &color_key)))
		return(NULL);

	return(lpdds);
}
Ejemplo n.º 5
0
int Draw_Rectangle(int x1, int y1, int x2, int y2, int color,
                   LPDIRECTDRAWSURFACE7 lpdds)
{
// this function uses directdraw to draw a filled rectangle

DDBLTFX ddbltfx; // this contains the DDBLTFX structure
RECT fill_area;  // this contains the destination rectangle

// clear out the structure and set the size field 
DD_INIT_STRUCT(ddbltfx);

// set the dwfillcolor field to the desired color
ddbltfx.dwFillColor = color; 

// fill in the destination rectangle data (your data)
fill_area.top    = y1;
fill_area.left   = x1;
fill_area.bottom = y2+1;
fill_area.right  = x2+1;

// ready to blt to surface, in this case blt to primary
lpdds->Blt(&fill_area, // ptr to dest rectangle
           NULL,       // ptr to source surface, NA            
           NULL,       // ptr to source rectangle, NA
           DDBLT_COLORFILL | DDBLT_WAIT | DDBLT_ASYNC,   // fill and wait                   
           &ddbltfx);  // ptr to DDBLTFX structure

// return success
return(1);

} // end Draw_Rectangle
Ejemplo n.º 6
0
/*
 * DD_Lock_Surface:
 *      Locks a specified surface
 */
WORD *DDLockSurface(LPDIRECTDRAWSURFACE lpdds, int *lpitch)
{
    // lock the surface
    DD_INIT_STRUCT(ddsd);
    lpdds->Lock(NULL, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL);
    
    // set the memory pitch
    *lpitch = ddsd.lPitch >> 1;
    
    // return pointer to surface
    return((WORD *)ddsd.lpSurface);
}
Ejemplo n.º 7
0
int PisteDraw_Buffer_Tayta(int i, int vasen, int yla, int oikea, int ala, UCHAR color)
{

	DD_INIT_STRUCT(PD_ddbltfx);
	PD_ddbltfx.dwFillColor = color;	
	IDirectDrawSurface4 *buffer;

	if (i >= MAX_BUFFEREITA)
		return PD_VIRHE;

	if (PD_buffers[i].lpdds == NULL)
		return PD_VIRHE;

	buffer = PD_buffers[i].lpdds;

	vasen += vasen_marginaali;
	oikea += vasen_marginaali;
	yla += yla_marginaali;
	ala += yla_marginaali;

	RECT dest_rect;

	dest_rect.left	 =	(long)vasen;
	dest_rect.right	 =	(long)oikea;
	dest_rect.top	 =	(long)yla;
	dest_rect.bottom =	(long)ala;
	
	if (dest_rect.left < PD_buffers[i].klipperi.left)
		dest_rect.left = PD_buffers[i].klipperi.left;

	if (dest_rect.right > PD_buffers[i].klipperi.right)
		dest_rect.right = PD_buffers[i].klipperi.right;

	if (dest_rect.top < PD_buffers[i].klipperi.top)
		dest_rect.top = PD_buffers[i].klipperi.top;

	if (dest_rect.bottom > PD_buffers[i].klipperi.bottom)
		dest_rect.bottom = PD_buffers[i].klipperi.bottom;

	if (FAILED(buffer->Blt(&dest_rect, 
					  	   NULL, 
						   NULL, 
						   DDBLT_COLORFILL | DDBLT_WAIT, 
						   &PD_ddbltfx))) {
		PisteLog_Kirjoita("[Error] Piste Draw: Buffer fill area failed!\n");
		return PD_VIRHE;
	}

	return 0;
}
Ejemplo n.º 8
0
int PisteDraw_Buffer_Flip(int i)
{
	DD_INIT_STRUCT(PD_ddsd);
	DD_INIT_STRUCT(PD_ddbltfx);

	RECT dest_rect;
	dest_rect.left	 =	0;
	dest_rect.right	 =	PD_ruudun_leveys;
	dest_rect.top	 =	0;
	dest_rect.bottom =	PD_ruudun_korkeus;

	if (FAILED(PD_buffers[PD_TAUSTABUFFER].lpdds->Blt(&dest_rect, 
										PD_buffers[i].lpdds,
										&dest_rect, 
										(DDBLT_WAIT | DDBLT_KEYSRC),
										NULL)))
	{
		strcpy(virhe,"Unable to flip surface!");
		PisteLog_Kirjoita("[Error] Piste Draw: Unable to flip surface!\n");
		return PD_VIRHE;	
	}
	return 0;
}
Ejemplo n.º 9
0
void DDFillSurface(LPDIRECTDRAWSURFACE lpdds, WORD color)
{
    DDBLTFX ddbltfx; // this contains the DDBLTFX structure
    
    // clear out the structure and set the size field
    DD_INIT_STRUCT(ddbltfx);
    
    // set the dwfillcolor field to the desired color
    ddbltfx.dwFillColor = color;
    
    // ready to blt to surface
    lpdds->Blt(NULL,                           // ptr to dest rectangle
               NULL,                           // ptr to source surface, NA
               NULL,                           // ptr to source rectangle, NA
               DDBLT_COLORFILL | DDBLT_WAIT,   // fill and wait
               &ddbltfx);                      // ptr to DDBLTFX structure
}
Ejemplo n.º 10
0
int PisteDraw_Piirto_Aloita(int i, UCHAR *&back_buffer, DWORD &lPitch)
{
	if (PD_buffers[i].lukittu)
		if (PisteDraw_Piirto_Lopeta(i)==PD_VIRHE) {
			PisteLog_Kirjoita("[Error] Piste Draw: Can't start free draw: Surface unlock failed!\n");
			return PD_VIRHE;
		}
	
	DD_INIT_STRUCT(PD_ddsd); 
	//PD_piirto_buffer_index = i;

	if (FAILED(PD_buffers[i].lpdds->Lock(NULL, &PD_ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL)))
	{
		PisteLog_Kirjoita("[Error] Piste Draw: Can't start free draw: Surface lock failed!\n");
		return PD_VIRHE;
	}	

	back_buffer = (UCHAR *)PD_ddsd.lpSurface;
	lPitch		= (DWORD &)PD_ddsd.lPitch;
		
	PD_buffers[i].lukittu = true;
	
	return 0;
}
Ejemplo n.º 11
0
int DMusic_Load_MIDI(char *filename)
{
   // this function loads a midi segment

   DMUS_OBJECTDESC ObjDesc; 
   HRESULT hr;
   IDirectMusicSegment* pSegment = NULL;

    
   // look for open slot for midi segment
   int id = -1;
   int index;
   for (index = 0; index < DM_NUM_SEGMENTS; index++)
   {
      // is this one open
      if (dm_midi[index].state == MIDI_NULL)
      {
         // validate id, but don't validate object until loaded
         id = index;
         break;
      } 
   } 

   // found good id?
   if (id==-1)
      return(-1);

   // get current working directory
   char szDir[_MAX_PATH];
   WCHAR wszDir[_MAX_PATH]; 

   if(_getcwd( szDir, _MAX_PATH ) == NULL)
      return(-1);

   MULTI_TO_WIDE(wszDir, szDir);

   // tell the loader were to look for files
   hr = dm_loader->SetSearchDirectory(GUID_DirectMusicAllTypes,wszDir, FALSE);

   if (FAILED(hr)) 
      return (-1);   

   // convert filename to wide string
   WCHAR wfilename[_MAX_PATH]; 
   MULTI_TO_WIDE(wfilename, filename);
    
   // setup object description
   DD_INIT_STRUCT(ObjDesc);
   ObjDesc.guidClass = CLSID_DirectMusicSegment;
   wcscpy(ObjDesc.wszFileName, wfilename );
   ObjDesc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_FILENAME;
    
   // load the object and query it for the IDirectMusicSegment interface
   // This is done in a single call to IDirectMusicLoader::GetObject
   // note that loading the object also initializes the tracks and does 
   // everything else necessary to get the MIDI data ready for playback.

   hr = dm_loader->GetObject(&ObjDesc,IID_IDirectMusicSegment, (void**) &pSegment);

   if (FAILED(hr))
      return(-1);
    
   // ensure that the segment plays as a standard MIDI file
   // you now need to set a parameter on the band track
   // Use the IDirectMusicSegment::SetParam method and let 
   // DirectMusic find the trackby passing -1 (or 0xFFFFFFFF) in the dwGroupBits method parameter.

   hr = pSegment->SetParam(GUID_StandardMIDIFile,-1, 0, 0, (void*)dm_perf);

   if (FAILED(hr))
      return(-1);
     
   // This step is necessary because DirectMusic handles program changes and 
   // bank selects differently for standard MIDI files than it does for MIDI 
   // content authored specifically for DirectMusic. 
   // The GUID_StandardMIDIFile parameter must be set before the instruments are downloaded. 

   // The next step is to download the instruments. 
   // This is necessary even for playing a simple MIDI file 
   // because the default software synthesizer needs the DLS data 
   // for the General MIDI instrument set
   // If you skip this step, the MIDI file will play silently.
   // Again, you call SetParam on the segment, this time specifying the GUID_Download parameter:

   hr = pSegment->SetParam(GUID_Download, -1, 0, 0, (void*)dm_perf);

   if (FAILED(hr))
      return(-1);

   // at this point we have MIDI loaded and a valid object

   dm_midi[id].dm_segment  = pSegment;
   dm_midi[id].dm_segstate = NULL;
   dm_midi[id].state       = MIDI_LOADED;
   return(id); 
} 
Ejemplo n.º 12
0
int PisteDraw_Buffer_Flip_Nopea(int lahde_index, int kohde_index, int x, int y)
{
	DD_INIT_STRUCT(PD_ddsd);				//Alustetaan DirectX pintakuvaus
	DD_INIT_STRUCT(PD_ddbltfx);				//Alustetaan Blittaus tehosteet
	int leveys;								//Apumuuttuja
	int korkeus;							//Apumuuttuja
	RECT source_rect;						//Alue lähdebufferista josta kopioidaan kohdebufferiin
	RECT *klipperi_kohde;					//Pointteri kohdebufferin leikkuriin 
	RECT *klipperi_lahde;					//Pointteri lähdebufferin leikkuriin

	x += vasen_marginaali;
	y += yla_marginaali;

	klipperi_kohde = &PD_buffers[kohde_index].klipperi;	
	klipperi_lahde = &PD_buffers[lahde_index].klipperi;

	int vasen	= klipperi_lahde->left;
	int oikea	= klipperi_lahde->right;
	int yla		= klipperi_lahde->top;
	int ala		= klipperi_lahde->bottom;

	leveys  = oikea - vasen;	// lasketaan apuja
	korkeus = ala - yla; 

	if (x+leveys > klipperi_kohde->right)			//Varmistetaan että ei piirretä kohdebufferin
	{												//rajojen ulkopuolelle
		oikea = vasen + klipperi_kohde->right - x;
	}

	if (x < klipperi_kohde->left)
	{
		vasen = vasen - x + klipperi_kohde->left;
		x = klipperi_kohde->left;
	}

	if (y+korkeus > klipperi_kohde->bottom)
	{
		ala = yla + klipperi_kohde->bottom - y;
	}

	if (y < klipperi_kohde->top)
	{
		yla = yla - y + klipperi_kohde->top;
		y = klipperi_kohde->top;
	}

	if (oikea>vasen && ala>yla)
	{
		source_rect.left	=	vasen;
		source_rect.right	=	oikea;
		source_rect.top		=	yla;
		source_rect.bottom	=	ala;

		if (FAILED(PD_buffers[kohde_index].lpdds->BltFast(x, y, PD_buffers[lahde_index].lpdds, &source_rect,
			(DDBLTFAST_WAIT | DDBLTFAST_SRCCOLORKEY)))) {			
			PisteLog_Kirjoita("[Error] Piste Draw: BlitFast failed!\n");
			return PD_VIRHE; // blitataan kaikki paitsi läpinäkyvyysväri
		}
	}

	return 0;
}
Ejemplo n.º 13
0
int PisteDraw_Buffer_Flip(int lahde_index, int kohde_index, int x, int y, bool peilaa_x, bool peilaa_y)
{
	DD_INIT_STRUCT(PD_ddsd);				//Alustetaan DirectX pintakuvaus
	DD_INIT_STRUCT(PD_ddbltfx);				//Alustetaan Blittaus tehosteet
	int leveys;								//Apumuuttuja
	int korkeus;							//Apumuuttuja
	RECT dest_rect;							//Alue kohdebufferista josta kopioidaan lähdebufferiin
	RECT source_rect;						//Alue lähdebufferista josta kopioidaan kohdebufferiin
	RECT *klipperi_kohde;					//Pointteri kohdebufferin leikkuriin 
	RECT *klipperi_lahde;					//Pointteri lähdebufferin leikkuriin

	x += vasen_marginaali;
	y += yla_marginaali;

	if (peilaa_x)
		PD_ddbltfx.dwDDFX = DDBLTFX_MIRRORLEFTRIGHT;

	if (peilaa_y)
		PD_ddbltfx.dwDDFX = DDBLTFX_MIRRORUPDOWN;

	if (peilaa_x && peilaa_y)
		PD_ddbltfx.dwDDFX = DDBLTFX_MIRRORLEFTRIGHT | DDBLTFX_MIRRORUPDOWN;

	klipperi_kohde = &PD_buffers[kohde_index].klipperi;	
	klipperi_lahde = &PD_buffers[lahde_index].klipperi;

	int vasen	= klipperi_lahde->left;
	int oikea	= klipperi_lahde->right;
	int yla		= klipperi_lahde->top;
	int ala		= klipperi_lahde->bottom;

	leveys  = oikea - vasen;	// lasketaan apuja
	korkeus = ala - yla; 

	if (x+leveys > klipperi_kohde->right)			//Varmistetaan että ei piirretä kohdebufferin
	{												//rajojen ulkopuolelle
		oikea = vasen + klipperi_kohde->right - x;
	}

	if (x < klipperi_kohde->left)
	{
		vasen = vasen - x + klipperi_kohde->left;
	}

	if (y+korkeus > klipperi_kohde->bottom)
	{
		ala = yla + klipperi_kohde->bottom - y;
	}

	if (y < klipperi_kohde->top)
	{
		yla = yla - y + klipperi_kohde->top;
	}

	if (oikea>vasen && ala>yla)
	{
				
		dest_rect.left		=	vasen+x;
		dest_rect.right		=	oikea+x;
		dest_rect.top		=	yla+y;
		dest_rect.bottom	=	ala+y;		

		source_rect.left	=	vasen;
		source_rect.right	=	oikea;
		source_rect.top		=	yla;
		source_rect.bottom	=	ala;

		if (peilaa_x)
		{
			if (x<klipperi_kohde->left)
			{
				source_rect.left  = klipperi_lahde->left;
				source_rect.right = klipperi_lahde->right - (vasen - klipperi_lahde->left);		
			}
			else
			{
				source_rect.left  = klipperi_lahde->left + (klipperi_lahde->right - oikea);
				source_rect.right = klipperi_lahde->right;
			}
		}

		if (peilaa_y)
		{
			if (y < klipperi_kohde->top)
			{
				source_rect.top    = klipperi_lahde->top;
				source_rect.bottom = klipperi_lahde->bottom - (yla - klipperi_lahde->top);		
			}
			else
			{
				source_rect.top    = klipperi_lahde->top + (klipperi_lahde->bottom - ala);
				source_rect.bottom = klipperi_lahde->bottom;
			}		
		}

		if (FAILED(PD_buffers[kohde_index].lpdds->Blt(&dest_rect, PD_buffers[lahde_index].lpdds, &source_rect,
			(DDBLT_WAIT | DDBLT_KEYSRC | DDBLT_DDFX), &PD_ddbltfx))){
			PisteLog_Kirjoita("[Error] Piste Draw: Unable to flip surface!\n");
			return PD_VIRHE; 
		}
	}

	return 0;
}
Ejemplo n.º 14
0
int PisteDraw_Lataa_Kuva(int index, char *filename, bool lataa_paletti)
{
	BITMAP_FILE		bitmap;

	bool ok = false;

	char paate[4];

	for (int i=0;i<4;i++)
		paate[i] = toupper(filename[strlen(filename)-3+i]);
	paate[4] = '\0';

	if (strcmp(paate,"BMP")==0)
	{
		ok = true;
		if (PD_buffers[index].lpdds)
		{
			if (PisteDraw_Load_Bitmap(&bitmap, filename) != 0)
			{
				strcpy(virhe,"Could not load picture ");
				strcat(virhe,filename);
				strcat(virhe,"!");
				PisteLog_Kirjoita("[Error] Piste Draw: ");
				PisteLog_Kirjoita(virhe);
				PisteLog_Kirjoita("\n");
				return PD_VIRHE;
			}

			DD_INIT_STRUCT(PD_ddsd);
			
			if (FAILED(PD_buffers[index].lpdds->Lock(NULL,&PD_ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL)))
			{
				strcpy(virhe,"Could not lock surface after loading a picture!");
				PisteLog_Kirjoita("[Error] Piste Draw: Could not lock surface after loading a picture! \n");
				return PD_VIRHE;
			}

			UCHAR *back_buffer = (UCHAR *)PD_ddsd.lpSurface; 

			int x;
			int y;
			int leveys, korkeus;

			if (bitmap.bitmapinfoheader.biWidth > PD_buffers[index].leveys)
				leveys = PD_buffers[index].leveys;
			else
				leveys = bitmap.bitmapinfoheader.biWidth;

			if (bitmap.bitmapinfoheader.biHeight > PD_buffers[index].korkeus)
				korkeus = PD_buffers[index].korkeus;
			else
				korkeus = bitmap.bitmapinfoheader.biHeight;

			for (y=0; y<korkeus; y++)
			{
				for (x=0; x<leveys; x++)
				{
					back_buffer[x+y*PD_ddsd.lPitch] = bitmap.buffer[x+y*bitmap.bitmapinfoheader.biWidth];
				}
			}

			if (FAILED(PD_buffers[index].lpdds->Unlock(NULL)))
			{
				strcpy(virhe,"Could not unlock surface after loading a picture!");
				PisteLog_Kirjoita("[Error] Piste Draw: Could not unlock surface after loading a picture! \n");
				return PD_VIRHE;
			}


			PisteDraw_Unload_Bitmap_File(&bitmap);
			
			if (lataa_paletti)
			{
			
				if (FAILED(PD_lpddpal->SetEntries(0,0,PD_max_varit, bitmap.paletti)))
				{
					strcpy(virhe,"Could not set palette after loading a picture!");
					PisteLog_Kirjoita("[Error] Piste Draw: Could not set palette after loading a picture! \n");
					return PD_VIRHE;
				}

				for (int pi=0;pi<256;pi++)
				{
					PD_paletti[pi].peBlue  = bitmap.paletti[pi].peBlue;
					PD_paletti[pi].peRed   = bitmap.paletti[pi].peRed;
					PD_paletti[pi].peGreen = bitmap.paletti[pi].peGreen;
					PD_paletti[pi].peFlags = bitmap.paletti[pi].peFlags;
				}

			}

		}
		else
			return PD_VIRHE;
	}

	if (strcmp(paate,"PCX")==0)
	{
		ok = true;
		if (PisteDraw_Lataa_PCX(filename, index, lataa_paletti) == PD_VIRHE) {
			strcpy(virhe,"Could not load picture ");
			strcat(virhe,filename);
			strcat(virhe,"!");
			PisteLog_Kirjoita("[Error] Piste Draw: ");
			PisteLog_Kirjoita(virhe);
			PisteLog_Kirjoita("\n");
			return PD_VIRHE;
		}
	}

	if (!ok)
	{
		strcpy(virhe,"Could not load bitmap file of type ");
		strcat(virhe,paate);
		return PD_VIRHE;
	}

	return 0;
}
Ejemplo n.º 15
0
int PisteDraw_Buffer_Uusi(int leveys, int korkeus, bool video_muisti, UCHAR color)
{
	int i = 0, 
		varaus;
	bool find = false;

	DDCAPS hel_caps, hal_caps;

	DD_INIT_STRUCT(hel_caps);
	DD_INIT_STRUCT(hal_caps);

	if (FAILED(PD_lpdd->GetCaps(&hal_caps,&hel_caps)))	
	{
		strcpy(virhe,"Cannot aquire system information!");
		PisteLog_Kirjoita("[Error] Piste Draw: Cannot aquire system information to create a new buffer! \n");
		return PD_VIRHE;
	}

	if ((unsigned long)(leveys*korkeus) > hal_caps.dwVidMemFree) {		//tarkastetaan riittääkö videomuistia
		video_muisti = false;
		PisteLog_Kirjoita("[Warning] Piste Draw: Out of video memory - creating a new buffer in system memory! \n");
	}

	if (video_muisti)
	{
		varaus = DDSCAPS_VIDEOMEMORY;
	}
	else
	{
		varaus = DDSCAPS_SYSTEMMEMORY;
	}

	while ((i < MAX_BUFFEREITA) && !find)
	{
		if (PD_buffers[i].lpdds == NULL)	// Onko puskurin pinta jo varattu?
		{
			if ((PD_buffers[i].lpdds = PisteDraw_Create_Surface(leveys, korkeus, varaus, color)) != NULL)
			{
				PD_buffers[i].leveys			= leveys;
				PD_buffers[i].korkeus			= korkeus;
				PD_buffers[i].klipperi.left		= 0;
				PD_buffers[i].klipperi.top		= 0;
				PD_buffers[i].klipperi.right	= leveys;
				PD_buffers[i].klipperi.bottom	= korkeus;
				PD_buffers[i].video_muisti		= video_muisti;
				PD_buffers[i].lukittu			= false;
				find = true;
				PD_buffereita_varattu++;
			}
			else
			{
				i = PD_VIRHE;
				strcpy(virhe,"Cannot create a new DirectDraw surface!");
				PisteLog_Kirjoita("[Error] Piste Draw: Cannot create a new DirectDraw surface! \n");
			}
		}
		else
		{
			i++;
		}
	}
	
	if (!find)
	{
		strcpy(virhe,"PisteEngine has run out of buffers!");
		PisteLog_Kirjoita("[Error] Piste Draw: PisteDraw has run out of buffers! \n");
		i = PD_VIRHE;
	}

	return i;
}
Ejemplo n.º 16
0
int	PisteDraw_Alusta(HWND &main_window_handle, HINSTANCE &hinstance_app, 
					 int leveys, int korkeus, int bpp,
					 int max_colors)
{

	if (PD_unload) {

		strcpy(virhe,"Uh, oh, I think we have a bug...");

		PD_main_window_handle	= (HWND &)main_window_handle;
		PD_hinstance_app		= (HINSTANCE &)hinstance_app;
		PD_ruudun_leveys		= leveys;
		PD_ruudun_korkeus		= korkeus;
		PD_ruudun_bpp			= bpp;
		PD_max_varit			= max_colors;
		
		LPDIRECTDRAW temp = NULL;				 // väliaikainen rajapinta jolla haetaan uusin versio
		int i;

		if (FAILED(DirectDrawCreate(NULL, &temp, NULL)))	// luo rajapintaosoitin versioon 1.0
		{
			strcpy(virhe,"Cannot initialize DirectDraw!");
			PisteLog_Kirjoita("[Error] Piste Draw: Cannot initialize DirectDraw! \n");
			return PD_VIRHE;
		}

		if (FAILED(temp->QueryInterface(IID_IDirectDraw4,(LPVOID *)&PD_lpdd))) // osoitin v 4.0
		{
			strcpy(virhe,"Cannot initialize DirectDraw4!");
			PisteLog_Kirjoita("[Error] Piste Draw: Cannot initialize DirectDraw4! \n");
			return PD_VIRHE;
		}

		temp->Release();	// tuhotaan väliaikainen rajapinta
		temp = NULL;
		
		if (FAILED(PD_lpdd->SetCooperativeLevel(PD_main_window_handle, // Yhteistyö Windowsin kanssa..
											  DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX |
											  DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
		{
			strcpy(virhe,"Failed to cooperate with Windows!");
			PisteLog_Kirjoita("[Error] Piste Draw: Failed to cooperate with Windows! \n");
			return PD_VIRHE;
		}
		
		if (FAILED(PD_lpdd->SetDisplayMode(PD_ruudun_leveys, PD_ruudun_korkeus, PD_ruudun_bpp,0,0)))
		{
			strcpy(virhe,"Unable to change video mode!");
			PisteLog_Kirjoita("[Error] Piste Draw: Unable to change video mode! \n");
			return PD_VIRHE;
		}

		DD_INIT_STRUCT(PD_ddsd);

		PD_ddsd.dwFlags				=	DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
		PD_ddsd.dwBackBufferCount	=	2;				//Kolmoispuskurointi = primary + 2 taustapuskuria
		PD_ddsd.ddsCaps.dwCaps		=	DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
		
		if (FAILED(PD_lpdd->CreateSurface(&PD_ddsd, &PD_lpddsprimary, NULL)))
		{
			strcpy(virhe,"Cannot create primary surface!");
			PisteLog_Kirjoita("[Error] Piste Draw: Cannot create primary surface! \n");
			return PD_VIRHE;
		}
		
		PD_buffers[PD_TAUSTABUFFER].leveys		= leveys;
		PD_buffers[PD_TAUSTABUFFER].korkeus		= korkeus;
		PisteDraw_Aseta_Klipperi(PD_TAUSTABUFFER,0,0,leveys,korkeus);
		PD_ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
		
		if (FAILED(PD_lpddsprimary->GetAttachedSurface(&PD_ddsd.ddsCaps, &PD_buffers[PD_TAUSTABUFFER].lpdds)))
		{
			strcpy(virhe,"Cannot attach back buffer to primary surface!");
			PisteLog_Kirjoita("[Error] Piste Draw: Cannot attach back buffer to primary surface! \n");
			return PD_VIRHE;
		}

		PD_buffers[PD_TAUSTABUFFER2].leveys		= leveys;
		PD_buffers[PD_TAUSTABUFFER2].korkeus	= korkeus;
		PisteDraw_Aseta_Klipperi(PD_TAUSTABUFFER2,0,0,leveys,korkeus);

		for (i=1;i<255;i++)							//Luodaan 8-bittinen paletti
		{
			PD_paletti[i].peRed		=	0;
			PD_paletti[i].peGreen	=	0;
			PD_paletti[i].peBlue	=	0;
			PD_paletti[i].peFlags	=	PC_NOCOLLAPSE;
		}

		if (FAILED(PD_lpdd->CreatePalette(DDPCAPS_8BIT |
										DDPCAPS_ALLOW256 |
										DDPCAPS_INITIALIZE,
										PD_paletti,
										&PD_lpddpal,
										NULL)))
		{
			PisteLog_Kirjoita("[Error] Piste Draw: Cannot create 8-bit palette! \n");
			strcpy(virhe,"Cannot create 8-bit palette!");
			return PD_VIRHE;
		}

		if (FAILED(PD_lpddsprimary->SetPalette(PD_lpddpal)))
		{
			PisteLog_Kirjoita("[Error] Piste Draw: Cannot set palette! \n");
			strcpy(virhe,"Cannot set palette!");
			return PD_VIRHE;
		}

		/*LIITETÄÄN KLIPPERI KUVAN REUNOJEN YLIKIRJOITUSTA ESTÄMÄÄN*/

		PD_fontbuffer = PisteDraw_Buffer_Uusi(PD_ruudun_leveys,10,true,255);

		for (i=2;i<MAX_BUFFEREITA;i++)		// alustetaan kuvabufferi taulukko.  
			PD_buffers[i].lpdds = NULL;				// 0 ja 1 on varattu taustapuskureille

		vasen_marginaali = 0;
		yla_marginaali = 0;
	
		PD_unload = false;
	}

	return 0;
}