Пример #1
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);
}
Пример #2
0
/***************************************************************************\
  Clears the specified surface.
\***************************************************************************/
void IMR_DirectXInterface::Clear_Surface(LPDIRECTDRAWSURFACE4 Surface)
{
HRESULT ddflag;
RECT Area;
DDSURFACEDESC2 DDSurfaceDesc;
char *Mem;

// Make sure the surface exists:
if (!Surface) return;

// Lock the surface:
DDSurfaceDesc.dwSize = sizeof(DDSurfaceDesc);
ddflag = Surface->Lock(&Area, &DDSurfaceDesc, DDLOCK_WAIT, NULL);
if (ddflag == DDERR_SURFACELOST)
    {
    Restore(Surface);
    ddflag = Surface->Lock(NULL, &DDSurfaceDesc, DDLOCK_WAIT, NULL);
     }
if (ddflag != DD_OK) return;
Mem = (char *)DDSurfaceDesc.lpSurface;

// Clear the surface:
if (Mem) memset(Mem, 0, DDSurfaceDesc.dwSize);

// And unlock the surface:
Surface->Unlock(NULL);
 }
Пример #3
0
//=====================================================================================
//	FillLMapSurface
//=====================================================================================
static void FillLMapSurface2(DRV_LInfo *LInfo, int32 LNum)
{
	U16					*pTempBits;
	int32				w, h, Width, Height, Stride;
	U8					*pBitPtr;
	RGB_LUT				*Lut;
	geRDriver_THandle	*THandle;
	HRESULT				Result;
	const RECT			*pRect;
    DDSURFACEDESC2		SurfDesc;
	LPDIRECTDRAWSURFACE4	Surface;
	int32				Extra;

	THandle = LInfo->THandle;

	pBitPtr = (U8*)LInfo->RGBLight[LNum];

	Width = LInfo->Width;
	Height = LInfo->Height;

	Lut = &AppInfo.Lut1;

    pRect = TPage_BlockGetRect(THandle->Block);
	Surface = TPage_BlockGetSurface(THandle->Block);

    memset(&SurfDesc, 0, sizeof(DDSURFACEDESC2));
    SurfDesc.dwSize = sizeof(DDSURFACEDESC2);

	Result = Surface->Lock((RECT*)pRect, &SurfDesc, DDLOCK_WAIT, NULL);

	assert(Result == DD_OK);

	Stride = SurfDesc.dwWidth;

	pTempBits = (U16*)SurfDesc.lpSurface;

	Extra = Stride - Width; 

	for (h=0; h< Height; h++)
	{
		for (w=0; w< Width; w++)
		{
			U8	R, G, B;
			U16	Color;
			R = *pBitPtr++;
			G = *pBitPtr++;
			B = *pBitPtr++;
			
			Color = (U16)(Lut->R[R] | Lut->G[G] | Lut->B[B]);

			*pTempBits++ = Color;
		}
		pTempBits += Extra;
	}

    Result = Surface->Unlock((RECT*)pRect);

	assert(Result == DD_OK);
}
Пример #4
0
//=====================================================================================
//	LoadLMapFromSystem
//=====================================================================================
static void LoadLMapFromSystem(DRV_LInfo *LInfo, int32 Log, int32 LNum)
{
	U16					*pTempBits;
	int32				w, h, Width, Height, Size, Extra;
	U8					*pBitPtr;
	LPDIRECTDRAWSURFACE4 Surface;
	RGB_LUT				*Lut;
    DDSURFACEDESC2		ddsd;
    HRESULT				ddrval;

	pBitPtr = (U8*)LInfo->RGBLight[LNum];

	Width = LInfo->Width;
	Height = LInfo->Height;
	Size = 1<<Log;

	Extra = Size - Width;

	Lut = &AppInfo.Lut1;

	Surface = SystemToVideo[Log].Surface;

    memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
    ddsd.dwSize = sizeof(DDSURFACEDESC2);
    ddrval = Surface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);

	assert(ddrval == DD_OK);
	U8	R, G, B;
	U16	Color;

	pTempBits = (USHORT*)ddsd.lpSurface;

	for (h=0; h< Height; h++)
	{
		for (w=0; w< Width; w++)
		{
			R = *pBitPtr++;
			G = *pBitPtr++;
			B =  *pBitPtr++;
			
			Color = (U16)(Lut->R[R] | Lut->G[G] | Lut->B[B]);
			
			*pTempBits++ = Color;
		}
		pTempBits += Extra;
	}

    ddrval = Surface->Unlock(NULL);
	assert(ddrval == DD_OK);
}
Пример #5
0
/***************************************************************************\
  Restores the specified surface.
\***************************************************************************/
void IMR_DirectXInterface::Restore(LPDIRECTDRAWSURFACE4 Surface)
{
int err;

// If the surface hasn't been initialized, return:
if (!Surface) return;

// Restore the surface:
err = Surface->Restore();
if (err == DDERR_WRONGMODE)
    {
    DirectDraw->SetDisplayMode(Display.Width, Display.Height, Display.BPP, 0, 0);
    err = Surface->Restore();
     }
 }
Пример #6
0
//=====================================================================================
//	SetupTexture
//=====================================================================================
geBoolean SetupTexture(int32 Stage, geRDriver_THandle *THandle, int32 MipLevel)
{
#ifdef D3D_MANAGE_TEXTURES
	D3DSetTexture(Stage, THandle->MipData[MipLevel].Texture);
	return GE_TRUE;
#else
	THandle_MipData		*MipData;

	MipData = &THandle->MipData[MipLevel];
	
	if (!SetupMipData(MipData))
	{
		MipData->Flags |= THANDLE_UPDATE;		// Force an upload
		CacheInfo.TexMisses++;
	}

	if (MipData->Flags & THANDLE_UPDATE)
	{
		HRESULT					Error;
		LPDIRECTDRAWSURFACE4	Surface;

		Surface = D3DCache_SlotGetSurface(MipData->Slot);

		Error = Surface->BltFast(0, 0, MipData->Surface, NULL, DDBLTFAST_WAIT);

		if (Error != DD_OK)
		{
			if(Error==DDERR_SURFACELOST)
			{
				if (!D3DMain_RestoreAllSurfaces())
					return FALSE;
			}
			else
			{
				D3DMain_Log("SetupTexture: System to Video cache Blt failed.\n %s", D3DErrorToString(Error));
				return GE_FALSE;
			}
		}
	}

	MipData->Flags &= ~THANDLE_UPDATE;

	D3DCache_SlotSetLRU(MipData->Slot, CurrentLRU);
	D3DSetTexture(Stage, D3DCache_SlotGetTexture(MipData->Slot));

	return GE_TRUE;
#endif
}
Пример #7
0
 void Shutdown(void)
     { 
     if (Lightmap) Lightmap->Release(); 
     Lightmap = NULL;
     if (LightmapSurface) LightmapSurface->Release();
     LightmapSurface = NULL;
     DirectX = NULL;
      };
Пример #8
0
/***************************************************************************\
  Blits one surface to another.
\**************************************************************************/
int IMR_DirectXInterface::Blit(LPDIRECTDRAWSURFACE4 Source, LPDIRECTDRAWSURFACE4 Target)
{
RECT Dest;
HRESULT ddrval;
DDSURFACEDESC2 SourceDesc, TargetDesc;
int BltX, BltY;

// Make sure DirectDraw is active:
if (!Flags.DirectDrawActive)
    {
    IMR_SetErrorText("IMR_DirectXInterface::Blit(): Interface not initialized!");
    return IMRERR_NOTREADY;
     }

// Make sure we have surfaces:
if (!Source || !Target)
    {
    IMR_SetErrorText("IMR_DirectXInterface::Blit(): NULL surface(s) specified!");
    return IMRERR_NODATA;
     }

// Get a surface descriptor for the surfaces:
TargetDesc.dwSize = sizeof(TargetDesc);
Target->GetSurfaceDesc(&TargetDesc);
SourceDesc.dwSize = sizeof(SourceDesc);
Source->GetSurfaceDesc(&SourceDesc);

// Now find the blit coords:
BltX = (TargetDesc.dwWidth / 2) - (SourceDesc.dwWidth / 2);
BltY = (TargetDesc.dwHeight / 2) - (SourceDesc.dwHeight / 2);

// Blit the surface:
ddrval = Target->BltFast(BltX, BltY, Source, NULL, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);

// If we lost the surface, return failure:
if (ddrval == DDERR_SURFACELOST)
    {
    Restore(Source);
    Restore(Target);
    IMR_SetErrorText("IMR_DirectXInterface::Blit(): Lost surface!");
    return IMRERR_DIRECTX;
     }

// Return ok:
return IMR_OK;
 }
Пример #9
0
// 페이지 플리핑
int Flip()
{
	//동영상 재생
	if ( ParkPlaying && (smFlipCount&1)==0 )  {
		updateFrameWin_Video();
		return TRUE;
	}

	if ( WindowMode || ( hFocusWnd && (smFlipCount&1)==0) ) {
		updateFrameWin();
		return TRUE;
	}


    HRESULT hresult = lpDDSPrimary->Flip( NULL, DDFLIP_WAIT );
    if ( hresult == DDERR_SURFACELOST ) {
        lpDDSPrimary->Restore();
		return FALSE;
	}
	smFlipCount++;			//플리핑 카운터

	return TRUE;
}
Пример #10
0
/***************************************************************************\
  Sets the palette for the specified surface.
  Palette is a pointer to 256 3-byte (RGB) palette entries.  
\***************************************************************************/
int IMR_DirectXInterface::Set_Surface_Palette(LPDIRECTDRAWSURFACE4 Surface, void *Palette)
{
PALETTEENTRY SurfacePal[256];
LPDIRECTDRAWPALETTE DDPalette;
char *Pal = (char *)Palette;
int ColorIndex, err;

// If NULL was specified for Surface, use the primary surface:
if (!Surface) Surface = DDPrimarySurface;
if (!DDPrimarySurface)
    {
    IMR_SetErrorText("IMR_DirectXInterface::Set_Surface_Palette(): No primary surface!");
    return IMRERR_NODATA;
     }

// Convert the palette:
for (int color = 0; color < 256; color ++)
    {
    ColorIndex = color * 3;
    SurfacePal[color].peRed   = Pal[ColorIndex];
    SurfacePal[color].peGreen = Pal[ColorIndex + 1];
    SurfacePal[color].peBlue  = Pal[ColorIndex + 2];
    SurfacePal[color].peFlags = PC_NOCOLLAPSE;
     }

// Make sure the DirectDraw object and the surfaces have been initialized:
if (DirectDraw && Surface)
    {
    // Create the palette.  If we can't, return false:
    err = DirectDraw->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256, SurfacePal, &DDPalette, NULL);
    if (err != DD_OK)
        {
        IMR_SetErrorText("IMR_DirectXInterface::Set_Palette(): DXERR: %s", IMR_MsgFromDXErr(err));
        return IMRERR_DIRECTX;
         }
  
    // Set the palette for the surface:
    Surface->SetPalette(DDPalette);
     }
else
    {
    IMR_SetErrorText("IMR_DirectXInterface::Set_Palette(): No surface specified or not initialized!");
    return IMRERR_NODATA;
     }

// Return OK:
return IMR_OK;
 }
Пример #11
0
int	PisteDraw_Lopeta()
{

	if (!PD_unload) {

		int i;

		for (i=0; i<MAX_FONTTEJA; i++)
		{
			if (PD_fontit[i] != NULL )
				delete PD_fontit[i];
			PD_fontit[i] = NULL;
		}

		for (i=2;i<MAX_BUFFEREITA;i++)		// 0 ja 1 on varattu taustapuskureille
			PisteDraw_Buffer_Tuhoa(i);

		if (PD_lpddpal)
		{
			PD_lpddpal->Release();
		}

		PisteDraw_Buffer_Tuhoa(PD_TAUSTABUFFER);

		PisteDraw_Buffer_Tuhoa(PD_TAUSTABUFFER2);

		if (PD_lpddsprimary)
		{
			PD_lpddsprimary->Release();
		} 

		if (PD_lpdd)
		{
			PD_lpdd->Release();
		}

		PD_unload = true;
	}

	return 0;
}
Пример #12
0
int DD_Shutdown () 
{
	
	
	if(lpdd) 
	{
	
		if (lpddsprimary) 
		{
			lpddsprimary->Release();
			lpddsprimary = NULL;
				
		}
		lpdd->Release();
		lpdd = NULL;

		return 1;
	}
	return 0;

} // end DD_Shutdown
Пример #13
0
/***************************************************************************\
  Prepares all surfaces for rendering.
\***************************************************************************/
void IMR_DirectXInterface::Prepare_Frame(LPDIRECTDRAWSURFACE4 Target)
{
D3DRECT ClearRect;
DDSURFACEDESC2 TargetDesc;

// Make sure we have a target surface and a viewport interface:
if (!Direct3DViewport || !Target)
    return;

// Get target size info:
TargetDesc.dwSize = sizeof(TargetDesc);
Target->GetSurfaceDesc(&TargetDesc);

// Setup the area to clear:
ClearRect.x1 = 0;
ClearRect.y1 = 0;
ClearRect.x2 = TargetDesc.dwWidth;
ClearRect.y2 = TargetDesc.dwHeight;

// Clear the viewport:
Direct3DViewport->Clear2(1, &ClearRect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, (float)1.0, NULL);
 }
Пример #14
0
void updateFrameWin()
{
    RECT                rcRect;
    RECT                destRect;
    HRESULT             ddrval;
	POINT				pt;

    GetClientRect(hwnd,&destRect);

    pt.x=pt.y=0;
    ClientToScreen(hwnd,&pt);
    OffsetRect(&destRect,pt.x,pt.y);
   //////////////////////////////////////////////////////////////
   // 두개의 페이지 전환이 이루어 지는 곳 
   // Blt() 함수가 실제로 비트맵을 그리는 함수

	rcRect.left   = 0;
	rcRect.right  = smScreenWidth;
	rcRect.top    = 0;
	rcRect.bottom = smScreenHeight;



	while(1)
	{
		ddrval=lpDDSPrimary->Blt(&destRect,lpDDSBack,&rcRect,NULL,NULL);
		if(ddrval == DD_OK) break;
		if(ddrval == DDERR_SURFACELOST)
		{
	//		ddrval = restoreAll();
			if(ddrval != DD_OK)	return;
		}
		if(ddrval != DDERR_WASSTILLDRAWING) break;

	}

} 
Пример #15
0
int DD_Init(HWND hwnd)
{

	int index;
	
	if(DirectDrawCreate(NULL,&pdd,NULL)!=DD_OK)
	{
		DD_Shutdown();
		return 0;
	}

	if(pdd->QueryInterface(IID_IDirectDraw4, (LPVOID *) & lpdd ) != DD_OK)
	{
		DD_Shutdown();
		return 0;
	}

	if(lpdd->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN ) != DD_OK )
	{
		DD_Shutdown();
		return 0;
	}


	if(lpdd->SetDisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,0,0) != DD_OK)
	{
		DD_Shutdown();
		return 0;
	}

	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 (lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL) != DD_OK)
	{
		DD_Shutdown();
		return 0;
	}


	ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
	if (lpddsprimary->GetAttachedSurface(&ddscaps,&lpddsback) != DD_OK)
	{
		DD_Shutdown();
		return 0;
	}

	memset(colour_palette,0,256*sizeof(PALETTEENTRY));

	for(index = 0; index < 256; index++ ) 
	{
		
		
			colour_palette[index].peRed = colour_bmp_file.palette[index].peBlue ;
			colour_palette[index].peBlue = colour_bmp_file.palette[index].peRed;
			colour_palette[index].peGreen = colour_bmp_file.palette[index].peGreen;
		
		
		colour_palette[index].peFlags = PC_NOCOLLAPSE;
				
	}

	if(lpdd->CreatePalette((DDPCAPS_8BIT | DDPCAPS_INITIALIZE),colour_palette,&lpddpal,NULL)!=DD_OK)
	{
		DD_Shutdown();
		return 0;
	}

	lpddsprimary->SetPalette(lpddpal);
//	lpddsback->SetPalette(lpddpal);

	

	return 1;

} // end DD_Init
Пример #16
0
//=====================================================================================
//	SetupLMap
//=====================================================================================
geBoolean SetupLMap(int32 Stage, DRV_LInfo *LInfo, int32 LNum, geBoolean Dynamic)
{
#ifdef D3D_MANAGE_TEXTURES
	#ifdef USE_TPAGES
	{
		geRDriver_THandle		*THandle;

		THandle = LInfo->THandle;

		if (Dynamic)
			THandle->Flags |= THANDLE_UPDATE;

		if (!THandle->Block)
		{
			THandle->Block = TPage_MgrFindOptimalBlock(TPageMgr, CurrentLRU);
			THandle->Flags |= THANDLE_UPDATE;
			TPage_BlockSetUserData(THandle->Block, THandle);
			assert(THandle->Block);
		}
		else if (TPage_BlockGetUserData(THandle->Block) != THandle)
		{
			// Find another block
			THandle->Block = TPage_MgrFindOptimalBlock(TPageMgr, CurrentLRU);
			assert(THandle->Block);

			THandle->Flags |= THANDLE_UPDATE;
			TPage_BlockSetUserData(THandle->Block, THandle);
		}

		if (THandle->Flags & THANDLE_UPDATE)
			FillLMapSurface2(LInfo, LNum);

		TPage_BlockSetLRU(THandle->Block, CurrentLRU);
		D3DSetTexture(Stage, TPage_BlockGetTexture(THandle->Block));
	
		if (Dynamic)
			THandle->Flags |= THANDLE_UPDATE;
		else
			THandle->Flags &= ~THANDLE_UPDATE;

		return GE_TRUE;
	}
	#else
	{
		geRDriver_THandle		*THandle;

		THandle = LInfo->THandle;

		if (Dynamic)
			THandle->MipData[0].Flags |= THANDLE_UPDATE;

		if (THandle->MipData[0].Flags & THANDLE_UPDATE)
			FillLMapSurface(LInfo, LNum);

		D3DSetTexture(Stage, THandle->MipData[0].Texture);
	
		if (Dynamic)
			THandle->MipData[0].Flags |= THANDLE_UPDATE;
		else
			THandle->MipData[0].Flags &= ~THANDLE_UPDATE;

		return GE_TRUE;
	}
	#endif

#else
	geRDriver_THandle	*THandle;
	THandle_MipData		*MipData;

	THandle = LInfo->THandle;
	MipData = &THandle->MipData[0];

	if (Dynamic)
		MipData->Flags |= THANDLE_UPDATE;

	if (!SetupMipData(MipData))
	{
		MipData->Flags |= THANDLE_UPDATE;		// Force an upload
		CacheInfo.LMapMisses++;
	}

	if (MipData->Flags & THANDLE_UPDATE)
	{
		HRESULT					Error;
		LPDIRECTDRAWSURFACE4	Surface;

		assert(MipData->Slot);
		
		Surface = D3DCache_SlotGetSurface(MipData->Slot);

		assert(Surface);
		assert(THandle->Log < MAX_LMAP_LOG_SIZE);
		assert(SystemToVideo[THandle->Log].Surface);

		LoadLMapFromSystem(LInfo, THandle->Log, LNum);

		Error = Surface->BltFast(0, 0, SystemToVideo[THandle->Log].Surface, NULL, DDBLTFAST_WAIT);
		//Error = Surface->BltFast(0, 0, SystemToVideo[THandle->Log].Surface, NULL, 0);
		//Error = Surface->Blt(NULL, SystemToVideo[THandle->Log].Surface, NULL, DDBLT_WAIT, NULL);
		//Error = Surface->Blt(NULL, SystemToVideo[THandle->Log].Surface, NULL, 0, NULL);
		
		if (Error != DD_OK)
		{
			if(Error==DDERR_SURFACELOST)
			{
				if (!D3DMain_RestoreAllSurfaces())
					return GE_FALSE;
			}
			else
			{
				D3DMain_Log("SetupTexture: System to Video cache Blt failed.\n %s", D3DErrorToString(Error));
				return GE_FALSE;
			}
		}
	}

	if (Dynamic)		// If it was dynmamic, force an update for one more frame
		MipData->Flags |= THANDLE_UPDATE;
	else
		MipData->Flags &= ~THANDLE_UPDATE;

	D3DCache_SlotSetLRU(MipData->Slot, CurrentLRU);
	D3DSetTexture(Stage, D3DCache_SlotGetTexture(MipData->Slot));

	return GE_TRUE;
#endif
}
Пример #17
0
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR lpszArgs, int nWinMode)
{
	HWND hwnd;
	MSG msg;
	WNDCLASS wcl;
	HDC hdc;
	char buffer[] = "hello";

	wcl.hInstance = hThisInst;
	wcl.lpszClassName = WINDOW_CLASS_NAME;
	wcl.lpfnWndProc = WindowFunc;
	wcl.style = CS_HREDRAW | CS_VREDRAW;

	wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	//wcl.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
	wcl.hCursor = LoadCursor(NULL, IDC_ARROW);

	wcl.lpszMenuName = WINDOW_CLASS_NAME;
	wcl.cbClsExtra = 0;
	wcl.cbWndExtra = 0;	

	wcl.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
	

	if(!RegisterClass(&wcl)) return 0;

	if(!(hwnd = CreateWindowEx (
		WS_EX_TOPMOST,
		WINDOW_CLASS_NAME,
		"My First Proper Thing 2",
		WS_POPUP,
		0,
		0,
		GetSystemMetrics(SM_CXSCREEN),
		GetSystemMetrics(SM_CYSCREEN),
		NULL,
		NULL,
		hThisInst,
		NULL
		))) return 0;

	ShowWindow(hwnd, nWinMode);
	UpdateWindow(hwnd);
	SetFocus(hwnd);
	ShowCursor(0);
	main_window_handle = hwnd;

	LoadBitmap(&colour_bmp_file,"texture2.bmp");
	LoadBitmap(&height_bmp_file,"heightd2.bmp");
	
	if (!DD_Init(hwnd))
	{

		DestroyWindow(hwnd);
		return 0;
	}


	ofstream fout("myfile.dem");

	int i,j,n,index = 0;
	for ( i = 0; i < 512; i++) {

		for ( j = 0; j < 512; j++) {

//			heights[i][j] = height_bmp_file.buffer[index++] * 8;
//			fout << heights[i][j] << " ";
			heights[i][j] = 0;
		
		}	

	fout << "\n";
	}

	index = 0;
	for ( i = 0; i < 1024; i++) {

		for ( j = 0; j < 1024; j++) {

			if ((colours[i][j] = colour_bmp_file.buffer[index++])>250) colours[i][j] = 250;
		
		
		}	

	fout << "\n";
	}

	LoadDEM();

	fout.close();

	LoadDEM();

	while (1) 
	{
		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			if(msg.message == WM_QUIT) { DD_Shutdown(); break; }
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		} 
		else 
		{	
			
			memset(&ddsd,0,sizeof(ddsd));
			ddsd.dwSize = sizeof(ddsd);


		



			
			while ( lpddsback->Lock(NULL,&ddsd,DDLOCK_SURFACEMEMORYPTR,NULL) != DD_OK);

				video_buffer = (UCHAR *) ddsd.lpSurface;

				memset(video_buffer,0,SCREEN_WIDTH*SCREEN_HEIGHT);


				GameMain();
			
				lpddsback->Unlock(NULL);
			
			

		sprintf(buffer,"%d",poo);
	

		if (lpddsback->GetDC(&hdc) == DD_OK) {
		 
			 SetBkColor(hdc, RGB(0, 0, 255));
			SetTextColor(hdc, RGB(255, 255, 0));
       
            TextOut(hdc, 0, 0, buffer, lstrlen(buffer));
           
		
        lpddsback->ReleaseDC(hdc);
		}

		
//Z+=10;
if (Z>3840.0) Z -=3840.0;

			while (TRUE)
               {
                   ddrval = lpddsprimary->Flip(NULL, 0);
                   if (ddrval == DD_OK)
					  
					   
                       break;
                   if (ddrval == DDERR_SURFACELOST)
                   {
                       ddrval = lpddsprimary->Restore();
                       if (ddrval != DD_OK)
                           break;
                   }
                   if (ddrval != DDERR_WASSTILLDRAWING)
                       break; 
			} 
			
            
			if (KEY_DOWN(VK_ESCAPE)) {
				
			DD_Shutdown();
			
				PostMessage(main_window_handle,WM_CLOSE,0,0);
			}
		} 
	}

	DD_Shutdown();

	return(msg.wParam);

}
Пример #18
0
/***************************************************************************\
  Unlocks the specified surface.  
\***************************************************************************/
void IMR_DirectXInterface::Unlock_Surface(LPDIRECTDRAWSURFACE4 Surface)
{
if (!Surface) Surface = DDPrimarySurface;
Surface->Unlock(NULL);
}
Пример #19
0
/***************************************************************************\
  Initializes Direct3D.
\***************************************************************************/
int IMR_DirectXInterface::InitDirect3D(LPDIRECTDRAWSURFACE4 Target)
{
int err;
D3DVIEWPORT2   PortInitData;
DDPIXELFORMAT  ZBufferPixelFormat;  
DDSURFACEDESC2 ZBufferDesc, TargetDesc;
D3DDEVICEDESC  HALDesc, HELDesc;
int DeviceFound = FALSE, FormatFound = FALSE;

// Make sure DirectDraw is active:
if (!Flags.DirectDrawActive)
    {
    IMR_SetErrorText("IMR_DirectXInterface::InitDirect3D(): DirectDraw not initialized!");
    return IMRERR_NOTREADY;
     }

// Make sure we have a target surface:
if (!Target)
    {
    IMR_SetErrorText("IMR_DirectXInterface::InitDirect3D(): NULL target specified!");
    return IMRERR_NODATA;
     }

// Get target size info:
TargetDesc.dwSize = sizeof(TargetDesc);
Target->GetSurfaceDesc(&TargetDesc);

// Release all Direct3D interfaces:
if (Direct3DViewport)
    {
    Direct3DViewport->Release();
    Direct3DViewport = NULL;
     }
if (Direct3DDevice)
    {
    Direct3DDevice->Release();
    Direct3DDevice = NULL;
     }
if (Direct3D)
    {
    Direct3D->Release();
    Direct3D = NULL;
     }
Flags.Direct3DActive = 0;

// Now get a new Direct3D3 interface:
DirectDraw->QueryInterface(IID_IDirect3D3, (void **)&Direct3D);
if (err != DD_OK)
    {
    IMR_SetErrorText("IMR_DirectXInterface::InitDirect3D(): 1 DXERR: %s", IMR_MsgFromDXErr(err));
    return IMRERR_DIRECTX;
     }

// Enumerate the devices and find one to use:
err = Direct3D->EnumDevices(DeviceCallback, &DeviceFound);
if (err != D3D_OK)
    {
    IMR_SetErrorText("IMR_DirectXInterface::InitDirect3D(): 2 DXERR: %s", IMR_MsgFromDXErr(err));
    return IMRERR_DIRECTX;
     }
if (!DeviceFound) 
    { 
    IMR_SetErrorText("IMR_DirectXInterface::InitDirect3D(): No usable rendering devices!");
    return IMRERR_DIRECTX;
     }

// Find a pixel format for our z-buffer and verify that it worked:
Direct3D->EnumZBufferFormats(Direct3DDeviceInfo.Guid, ZBufferCallback, (void *)&ZBufferPixelFormat);
if (ZBufferPixelFormat.dwSize != sizeof(DDPIXELFORMAT))
    {
    IMR_SetErrorText("IMR_DirectXInterface::InitDirect3D(): Couldn't find Z-Buffer pixel format!");
    return IMRERR_DIRECTX;
     }

// Create a Z-Buffer:
ZeroMemory((void *)&ZBufferDesc, sizeof(ZBufferDesc));
ZBufferDesc.dwSize = sizeof(ZBufferDesc);
ZBufferDesc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
ZBufferDesc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
ZBufferDesc.dwWidth = TargetDesc.dwWidth;
ZBufferDesc.dwHeight = TargetDesc.dwHeight;
memcpy(&ZBufferDesc.ddpfPixelFormat, &ZBufferPixelFormat, sizeof(DDPIXELFORMAT));
if (IsEqualIID(Direct3DDeviceInfo.Guid, IID_IDirect3DHALDevice))
    ZBufferDesc.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
else
    ZBufferDesc.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY; 
err = DirectDraw->CreateSurface(&ZBufferDesc, &DDZBuffer, NULL);
if (err != DD_OK)
    {
    IMR_SetErrorText("IMR_DirectXInterface::InitDirect3D(): 3 DXERR: %s", IMR_MsgFromDXErr(err));
    return IMRERR_DIRECTX;
     }

// Now attach the Z-buffer to the target surface:
err = Target->AddAttachedSurface(DDZBuffer);
if (err != DD_OK)
    {
    IMR_SetErrorText("IMR_DirectXInterface::InitDirect3D(): 4 DXERR: %s", IMR_MsgFromDXErr(err));
    return IMRERR_DIRECTX;
     }

// Now create the device:
err = Direct3D->CreateDevice(Direct3DDeviceInfo.Guid, Target, &Direct3DDevice, NULL);
if (err != D3D_OK)
    {
    IMR_SetErrorText("IMR_DirectXInterface::InitDirect3D(): 5 DXERR: %s", IMR_MsgFromDXErr(err));
    return IMRERR_DIRECTX;
     }
 
// Setup the device:
Direct3DDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
Direct3DDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE, D3DSHADE_GOURAUD);
Direct3DDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
Direct3DDevice->SetLightState(D3DLIGHTSTATE_MATERIAL, NULL);

// Make sure this device can handle our textures:
Direct3DDevice->EnumTextureFormats(TextureFormatCallback, (void *)&FormatFound);
if (!FormatFound)
    {
    IMR_SetErrorText("IMR_DirectXInterface::InitDirect3D(): No acceptable texture formats found!");
    return IMRERR_DIRECTX;
     }

// Now create a viewport init structure:
ZeroMemory(&PortInitData, sizeof(D3DVIEWPORT2));
PortInitData.dwSize = sizeof(D3DVIEWPORT2);
PortInitData.dwX = 0;
PortInitData.dwY = 0;
PortInitData.dwWidth = TargetDesc.dwWidth;
PortInitData.dwHeight = TargetDesc.dwHeight;
PortInitData.dvClipX = 0;
PortInitData.dvClipY = 0;
PortInitData.dvClipWidth = TargetDesc.dwWidth;
PortInitData.dvClipHeight = TargetDesc.dwHeight;
PortInitData.dvMinZ = 0.0f;
PortInitData.dvMaxZ = 1.0f;

// Create the viewport:
err = Direct3D->CreateViewport(&Direct3DViewport, NULL);
if (err != D3D_OK)
    {
    IMR_SetErrorText("IMR_DirectXInterface::InitDirect3D(): 6 DXERR: %s", IMR_MsgFromDXErr(err));
    return IMRERR_DIRECTX;
     }

// Associate the viewport with the device:
Direct3DDevice->AddViewport(Direct3DViewport); 

// Set the parameters for the new viewport:
Direct3DViewport->SetViewport2(&PortInitData);

// Set the current viewport for the device:
Direct3DDevice->SetCurrentViewport(Direct3DViewport);

// Flag that Direct3D is up and running:
Flags.Direct3DActive = 1;

// Whew!  That's done, so return success:
return IMR_OK;
 }
Пример #20
0
 void Destroy_Surface(LPDIRECTDRAWSURFACE4 Surface) const { Surface->Release(); };
Пример #21
0
void updateFrameWin_Video()
{
	RECT                rcRect;
    RECT                rcRect1;
	RECT                rcRect2;
	RECT                rcRect3;
	RECT                rcRect4;

    RECT                destRect;
	RECT                destRect1;
	RECT                destRect2;
	RECT                destRect3;
	RECT                destRect4;
    HRESULT             ddrval;
	POINT				pt;

    GetClientRect(hwnd,&destRect);

    pt.x=pt.y=0;
    ClientToScreen(hwnd,&pt);
    OffsetRect(&destRect,pt.x,pt.y);


   //////////////////////////////////////////////////////////////
   // 두개의 페이지 전환이 이루어 지는 곳 
   // Blt() 함수가 실제로 비트맵을 그리는 함수

	rcRect.left   = 0;
	rcRect.right  = smScreenWidth;
	rcRect.top    = 0;
	rcRect.bottom = smScreenHeight;

	destRect1.left	= 0;
	destRect1.right	= smScreenWidth;
	destRect1.top	= 0;
	destRect1.bottom = ParkPlayRect.top;

	destRect2.left	= 0;
	destRect2.right	= ParkPlayRect.left;
	destRect2.top	= ParkPlayRect.top;
	destRect2.bottom = ParkPlayRect.bottom;

	destRect3.left	= ParkPlayRect.right;
	destRect3.right	= smScreenWidth;
	destRect3.top	= ParkPlayRect.top;
	destRect3.bottom = ParkPlayRect.bottom;

	destRect4.left	= 0;
	destRect4.right	= smScreenWidth;
	destRect4.top	= ParkPlayRect.bottom;
	destRect4.bottom = smScreenHeight;


	rcRect1.left   = 0;
	rcRect1.right  = smScreenWidth;
	rcRect1.top    = 0;
	rcRect1.bottom = ParkPlayRect.top;


	rcRect2.left   = 0;
	rcRect2.right  = ParkPlayRect.left;
	rcRect2.top    = ParkPlayRect.top;
	rcRect2.bottom = ParkPlayRect.bottom;


	rcRect3.left   = ParkPlayRect.right;
	rcRect3.right  = smScreenWidth;
	rcRect3.top    = ParkPlayRect.top;
	rcRect3.bottom = ParkPlayRect.bottom;

	rcRect4.left   = 0;
	rcRect4.right  = smScreenWidth;
	rcRect4.top    = ParkPlayRect.bottom;
	rcRect4.bottom = smScreenHeight;


	while(1)
	{
		//ddrval=lpDDSPrimary->Blt(&destRect,lpDDSBack,&rcRect,NULL,NULL);
		ddrval=lpDDSPrimary->Blt(&destRect1,lpDDSBack,&rcRect1,NULL,NULL);
		ddrval=lpDDSPrimary->Blt(&destRect2,lpDDSBack,&rcRect2,NULL,NULL);
		ddrval=lpDDSPrimary->Blt(&destRect3,lpDDSBack,&rcRect3,NULL,NULL);
		ddrval=lpDDSPrimary->Blt(&destRect4,lpDDSBack,&rcRect4,NULL,NULL);
		if(ddrval == DD_OK) break;
		if(ddrval == DDERR_SURFACELOST)
		{
	//		ddrval = restoreAll();
			if(ddrval != DD_OK)	return;
		}
		if(ddrval != DDERR_WASSTILLDRAWING) break;

	}

} 
Пример #22
0
// 비디오 모드 전환
BOOL SetDisplayModeWin( HWND hWnd, DWORD Width, DWORD Height, DWORD BPP )
{
    // Set Cooperative Level

	
    HRESULT hresult = lpDD->SetCooperativeLevel( hWnd,DDSCL_NORMAL );

    if ( hresult != DD_OK )
	{
		MESSAGE( "lpDD->SetCooperativeLevel" );
        return FALSE;
	}


    // Primary Surface 생성
    DDSURFACEDESC2 ddsd;
    ZeroMemory( &ddsd, sizeof( ddsd ) );

    ddsd.dwSize             = sizeof(ddsd);
    ddsd.ddsCaps.dwCaps     = DDSCAPS_PRIMARYSURFACE |
                              DDSCAPS_3DDEVICE;

    // Primary surface 생성
    hresult = lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL );
    if ( hresult != DD_OK )
	{
		MESSAGE( "lpDD2->CreateSurface(lpDDSPrimary)" );
        return FALSE;
	}


	int w,h;
	RECT lpRect;
	GetWindowRect( GetDesktopWindow() , &lpRect );
	w = lpRect.right - lpRect.left;
	h = lpRect.bottom - lpRect.top;

	// 백 버퍼 1 생성
    ZeroMemory( &ddsd, sizeof(ddsd) );
	ddsd.dwSize=sizeof(ddsd);
    ddsd.dwFlags=DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH;
    ddsd.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN|DDSCAPS_3DDEVICE| DDSCAPS_VIDEOMEMORY;
    ddsd.dwWidth  = w;
    ddsd.dwHeight = h;
    lpDD->CreateSurface(&ddsd,&lpDDSBack,NULL);

	lpDD->CreateClipper( 0, &lpDDClipper , NULL );
	lpDDClipper->SetHWnd( 0, hWnd );
	lpDDSPrimary->SetClipper( lpDDClipper );
	lpDDClipper->Release();


	DDPIXELFORMAT	ddpx;
    // z-buffer Surface 생성
    ZeroMemory( &ddsd, sizeof(ddsd) );
    ddsd.dwSize            = sizeof(ddsd);
    ddsd.dwFlags           = DDSD_CAPS |
                             DDSD_WIDTH |
                             DDSD_HEIGHT|
                             DDSD_PIXELFORMAT;

    ddsd.dwWidth           = w;
    ddsd.dwHeight          = h;

	lpD3D->EnumZBufferFormats( lpD3DDeviceDesc->guid , EnumZBufferCallback , (VOID *)&ddpx );

	memcpy( &ddsd.ddpfPixelFormat , &ddpx , sizeof( DDPIXELFORMAT ) );

	//######################################################################################
	//작 성 자 : 오 영 석
	::CopyMemory( &g_ddpfPixelFormatZ, &ddsd.ddpfPixelFormat, sizeof(g_ddpfPixelFormatZ) );
	//######################################################################################

    // 하드웨어 이면 z-buffer를 비디오 메모리에 만든다.
    if ( lpD3DDeviceDesc->bIsHardware )
        ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY;
    else
        ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_SYSTEMMEMORY;

    // Create the ZBuffer surface.
    hresult = lpDD->CreateSurface( &ddsd, &lpDDSZBuffer, NULL );
    if ( hresult != DD_OK )
	{
		MESSAGE( "lpDD2->CreateSurface(lpDDSZBuffer)" );
        return FALSE;
	}

    // Back Surface에 Z-buffer를 붙인다.
    hresult = lpDDSBack->AddAttachedSurface( lpDDSZBuffer );
    if ( hresult != DD_OK )
	{
		MESSAGE( "lpDDSBack->AddAttachedSurface" );
        return FALSE;
	}

    // Direct3D Device 생성
    hresult = lpD3D->CreateDevice( lpD3DDeviceDesc->guid,
									lpDDSBack,
									&lpD3DDevice,
									NULL );
    if ( hresult != D3D_OK )
	{
		MESSAGE( "lpD3D->CreateDevice" );
        return FALSE;
	}

    // Viewport 크기 설정
    D3DRect.x1 = 0;
    D3DRect.y1 = 0;
    D3DRect.x2 = w;
    D3DRect.y2 = h;

	smScreenWidth = Width;
	smScreenHeight = Height;

	return TRUE;
}
Пример #23
0
// 비디오 모드 전환
BOOL SetDisplayMode( HWND hWnd, DWORD Width, DWORD Height, DWORD BPP )
{
    // Set Cooperative Level

	smTextureBPP = BPP;

	if ( WindowMode ) return SetDisplayModeWin( hWnd , Width , Height , BPP );
	
    HRESULT hresult = lpDD->SetCooperativeLevel( hWnd,
                                                  DDSCL_EXCLUSIVE |
                                                  DDSCL_FULLSCREEN |
												  DDSCL_ALLOWMODEX );
    if ( hresult != DD_OK )
	{
		MESSAGE( "lpDD->SetCooperativeLevel" );
        return FALSE;
	}


    // 풀화면 모드로 전환
    hresult = lpDD->SetDisplayMode( Width, Height, BPP, 0, 0 );
    if ( hresult != DD_OK )
	{
		MESSAGE( "lpDD3->SetDisplayMode" );
        return FALSE;
	}


    // Primary Surface 생성
    DDSURFACEDESC2 ddsd;
    ZeroMemory( &ddsd, sizeof(ddsd) );

    ddsd.dwSize             = sizeof(ddsd);
    ddsd.dwBackBufferCount  = 1;
    ddsd.dwFlags            = DDSD_CAPS |
                              DDSD_BACKBUFFERCOUNT;
    ddsd.ddsCaps.dwCaps     = DDSCAPS_PRIMARYSURFACE |
                              DDSCAPS_FLIP |
                              DDSCAPS_COMPLEX |
                              DDSCAPS_VIDEOMEMORY |
                              DDSCAPS_3DDEVICE;

    // Primary surface 생성
    hresult = lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL );
    if ( hresult != DD_OK )
	{
		MESSAGE( "lpDD->CreateSurface(lpDDSPrimary)" );
        return FALSE;
	}

    // Back Surface 생성(?)
    DDSCAPS2 ddscaps;
    ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
    hresult = lpDDSPrimary->GetAttachedSurface( &ddscaps, &lpDDSBack );
    if ( hresult != DD_OK )
	{
		MESSAGE( "lpDDSPrimary->GetAttachedSurface" );
        return FALSE;
	}


	//////////// 클리퍼 생성 ////////////////////////
	lpDD->CreateClipper( 0, &lpDDClipper , NULL );
	lpDDClipper->SetHWnd( 0, hWnd );
	lpDDSPrimary->SetClipper( lpDDClipper );
	lpDDClipper->Release();



    // z-buffer Surface 생성
    ZeroMemory( &ddsd, sizeof(ddsd) );
    ddsd.dwSize            = sizeof(ddsd);
    ddsd.dwFlags           = DDSD_CAPS |
                             DDSD_WIDTH |
                             DDSD_HEIGHT |
                             DDSD_PIXELFORMAT;
    ddsd.dwWidth           = Width;
    ddsd.dwHeight          = Height;

	lpD3D->EnumZBufferFormats( IID_IDirect3DHALDevice , EnumZBufferCallback , (VOID *)&ddsd.ddpfPixelFormat );

	//######################################################################################
	//작 성 자 : 오 영 석
	::CopyMemory( &g_ddpfPixelFormatZ, &ddsd.ddpfPixelFormat, sizeof(g_ddpfPixelFormatZ) );
	//######################################################################################

    // 하드웨어 이면 z-buffer를 비디오 메모리에 만든다.
    if ( lpD3DDeviceDesc->bIsHardware )
        ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY;
    else
        ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_SYSTEMMEMORY;

    // Create the ZBuffer surface.
    hresult = lpDD->CreateSurface( &ddsd, &lpDDSZBuffer, NULL );
    if ( hresult != DD_OK )
	{
		MESSAGE( "lpDD2->CreateSurface(lpDDSZBuffer)" );
        return FALSE;
	}

    // Back Surface에 Z-buffer를 붙인다.
    hresult = lpDDSBack->AddAttachedSurface( lpDDSZBuffer );
    if ( hresult != DD_OK )
	{
		MESSAGE( "lpDDSBack->AddAttachedSurface" );
        return FALSE;
	}

    // Direct3D Device 생성
    hresult = lpD3D->CreateDevice( lpD3DDeviceDesc->guid,
                                    lpDDSBack,
                                    &lpD3DDevice,
									NULL );
    if ( hresult != D3D_OK )
	{
		MESSAGE( "lpD3D->CreateDevice" );
        return FALSE;
	}

    // Viewport 크기 설정
    D3DRect.x1 = 0;
    D3DRect.y1 = 0;
    D3DRect.x2 = Width;
    D3DRect.y2 = Height;

	smScreenWidth = Width;
	smScreenHeight = Height;

    return TRUE;
}
Пример #24
0
// Direct3D 제거
void ReleaseD3D()
{
	//######################################################################################
	//작 성 자 : 오 영 석
	DestroyDevice( lpDeviceDesc );
	//######################################################################################

	//######################################################################################
	//작 성 자 : 오 영 석
	ReleaseNewRenderTarget();
	//######################################################################################

    // Viewport 제거
    if ( lpD3DViewport )
    {
        // Direct3D Device 에서 Viewport 제거
        lpD3DDevice->DeleteViewport( lpD3DViewport );
		
        lpD3DViewport->Release();
        lpD3DViewport = NULL;
    }

    // Direct3D Device 제거
    if ( lpD3DDevice )
    {
        lpD3DDevice->Release();
        lpD3DDevice = NULL;
    }


    // Z-Buffer Surface 제거
    if ( lpDDSZBuffer )
    {
        // Back Surface 에서 Z-Buffer Surface 제거
        if ( lpDDSBack )
            lpDDSBack->DeleteAttachedSurface( 0L, lpDDSZBuffer );

        lpDDSZBuffer->Release();
        lpDDSZBuffer = NULL;
    }

	//######################################################################################
	//작 성 자 : 오 영 석
	if ( lpDDSBack )
	{
		lpDDSBack->Release();
        lpDDSBack = NULL;
	}
	//######################################################################################

    // Direct3D Interface 제거
    if ( lpD3D )
    {
        lpD3D->Release();
        lpD3D = NULL;
    }

    // Primary Surface 제거
    if ( lpDDSPrimary )
    {
        lpDDSPrimary->Release();
        lpDDSPrimary = NULL;
    }

    // DirectDraw2 Interface 제거
    if ( lpDD )
    {
        // 비디오 모드 복귀
        lpDD->RestoreDisplayMode();

        lpDD->Release();
        lpDD = NULL;
    }
}
Пример #25
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;
}
Пример #26
0
void PisteDraw_Paivita_Naytto()
{
	PisteDraw_Fade_Paletti();
	while (FAILED(PD_lpddsprimary->Flip(NULL, DDFLIP_WAIT)));
}