예제 #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
int PisteDraw_Palauta_Pinnat()
{
	if (FAILED(PD_lpdd->RestoreAllSurfaces()))	
		return PD_VIRHE;

	return 0;
}
예제 #3
0
int PisteDraw_Aseta_Videomode(int leveys, int korkeus, int bpp,
					 int max_colors)
{
	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;
	}
	return 0;
}
예제 #4
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;
}
예제 #5
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;
}
예제 #6
0
// Direct3D 생성
BOOL CreateD3D()
{
    // DirectDraw 인터페이스 생성
    LPDIRECTDRAW lpdd;

    // 설정된 DirectDraw Device
    HRESULT hresult = DirectDrawCreate( NULL, &lpdd, NULL );
    if ( hresult != DD_OK )
	{
		MESSAGE( "DirectDrawCreate" );
        return FALSE;
	}

    // DirectDraw2 인터페이스 얻기
    hresult = lpdd->QueryInterface( IID_IDirectDraw4, (LPVOID*)&lpDD );
    if ( hresult != DD_OK )
	{
		MESSAGE( "lpdd->QueryInterface" );
        return FALSE;
	}

    // DirectDraw 인터페이스 제거
    lpdd->Release();


    // Direct3D 인터페이스 얻기
    hresult = lpDD->QueryInterface( IID_IDirect3D3, (LPVOID*)&lpD3D );
    if ( hresult != DD_OK )
	{
		MESSAGE( "lpDD3->QueryInterface" );
        return FALSE;
	}

    // Direct3D Device 인터페이스 얻기
	hresult = lpD3D->EnumDevices( DeviceEnumCallback, (LPVOID)&lpDeviceDesc );
    if ( hresult != DD_OK )
	{
		MESSAGE( "lpD3D->EnumDevices" );
        return FALSE;
	}

	lpD3DDeviceDesc = FindBestDevice( lpDeviceDesc );
	if ( !lpD3DDeviceDesc )
		return FALSE;

    return TRUE;
}
예제 #7
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;
}
예제 #8
0
int DD_Shutdown () 
{
	
	
	if(lpdd) 
	{
	
		if (lpddsprimary) 
		{
			lpddsprimary->Release();
			lpddsprimary = NULL;
				
		}
		lpdd->Release();
		lpdd = NULL;

		return 1;
	}
	return 0;

} // end DD_Shutdown
HRESULT __stdcall DDRAWSURFACE4_HOOK_Lock(LPVOID *ppvOut, LPRECT lpDestRect, LPDDSURFACEDESC2 lpDDSurfaceDesc, DWORD dwFlags, HANDLE hEvent) {
	const unsigned int hpos = 25;
	
	char dwFlags_buffer[LOGBUFFER_MAX];
	FlagsToString(FLAGS_DDLOCK, CFLAGS_DDLOCK, dwFlags, dwFlags_buffer, LOGBUFFER_MAX);

	Log("IDirectDrawSurface4::%s(this=%#010lx, lpDestRect=%#010lx { left=%d, right=%d, top=%d, bottom=%d }, lpDDSurfaceDesc=%#010lx, dwFlags=%#010lx (%s), hEvent=%#010lx)", ddrawsurface4_hooks[hpos].name, ppvOut, lpDestRect, (lpDestRect != NULL ? lpDestRect->left : NULL), (lpDestRect != NULL ? lpDestRect->right : NULL), (lpDestRect != NULL ? lpDestRect->top : NULL), (lpDestRect != NULL ? lpDestRect->bottom : NULL), lpDDSurfaceDesc, dwFlags, dwFlags_buffer, hEvent);

	//dwFlags |= DDLOCK_NOSYSLOCK;
	if (g_config.displaymode && lpDDSurfaceDesc) {
		DDSURFACEDESC2 sd;
		memset(&sd, 0, sizeof(DDSURFACEDESC2));
		sd.dwSize = sizeof(sd);
		((IDirectDrawSurface4 *)ppvOut)->GetSurfaceDesc(&sd);
		LPDIRECTDRAWSURFACE4 * ppDecoySurface = 0;
		// If the game is locking the backbuffer, it can do arbitrary stuff in there,
		// which this wrapper has no chance of making scaled properly.
		// So the game is given a surface with the dimension it expects, and the wrapper will
		// scale it up in the UnLock function.
		// Luckily, this appears to be only used for videos, where simple upscaling is the only option anyway.
		if((!g_config.fullscreen && (LPDIRECTDRAWSURFACE4)ppvOut == g_backbuffer) ||
		  (sd.dwWidth == 640 &&
		   sd.dwHeight == 480 &&
		   (sd.ddsCaps.dwCaps & DDSCAPS_BACKBUFFER))) {
			ppDecoySurface = &g_decoyBackBuffer;
			g_decoyBackLockFlags = dwFlags;
			Log("Backbuffer locking: substitute decoy surface\n");
		}
		// Similarily, the frontbuffer is read for special effects which also depend on the fixed size.
		if((!g_config.fullscreen && (LPDIRECTDRAWSURFACE4)ppvOut == g_frontbuffer) ||
		  (sd.dwWidth == 640 &&
		   sd.dwHeight == 480 &&
		   (sd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))) {
			ppDecoySurface = &g_decoyFrontBuffer;
			g_decoyFrontLockFlags = dwFlags;
			Log("Frontbuffer locking: substitute decoy surface\n");
		}
		if(ppDecoySurface) {
			DDSURFACEDESC2 ddsd;
			memset(&ddsd, 0, sizeof(DDSURFACEDESC2));
			ddsd.dwSize = sizeof(ddsd);
			if((*ppDecoySurface) == NULL) {
				LPDIRECTDRAW4 lpDD = NULL;
				ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
				ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
				ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
				ddsd.ddpfPixelFormat.dwFourCC = 0;
				ddsd.ddpfPixelFormat.dwRGBBitCount = 16;
				ddsd.ddpfPixelFormat.dwRBitMask = 0xf800;
				ddsd.ddpfPixelFormat.dwGBitMask = 0x07e0;
				ddsd.ddpfPixelFormat.dwBBitMask = 0x001f;
				ddsd.dwWidth = 640;
				ddsd.dwHeight = 480;
				ddsd.ddsCaps.dwCaps = DDSCAPS_3DDEVICE | DDSCAPS_OFFSCREENPLAIN;
				((IDirectDrawSurface4 *)ppvOut)->GetDDInterface((LPVOID *)&lpDD);
				lpDD->CreateSurface(&ddsd, ppDecoySurface, NULL);
				SAFE_RELEASE(lpDD);
			}
			if((*ppDecoySurface)->IsLost())
				(*ppDecoySurface)->Restore();
			RECT rcDest, rcSource;
			sd.dwHeight = displaymode_options[g_config.displaymode].resY;
			sd.dwWidth = displaymode_options[g_config.displaymode].resX;
			// FIXME: In windowed mode, the front buffer probably contains the whole screen or something
			if(sd.dwHeight >= g_game.height) {
				rcSource.top = (sd.dwHeight - g_game.height)/2; rcSource.bottom = sd.dwHeight - rcSource.top;
				rcDest.top = 0; rcDest.bottom = 480;
			} else {
				rcSource.top = 0; rcSource.bottom = sd.dwHeight;
				rcDest.top = (LONG)((g_game.height - sd.dwHeight) / (2 * g_game.modY)); rcDest.bottom = 480 - rcDest.top;
			}
			if(sd.dwWidth >= g_game.width) {
				rcSource.left = (sd.dwWidth - g_game.width)/2; rcSource.right = sd.dwWidth - rcSource.left;
				rcDest.left = 0; rcDest.right = 640;
			} else {
				rcSource.left = 0; rcSource.right = sd.dwWidth;
				rcDest.left = (LONG)((g_game.width - sd.dwWidth) / (2 * g_game.modX)); rcDest.bottom = 640 - rcDest.left;
			}
			if(~dwFlags & DDLOCK_WRITEONLY)
				(*ppDecoySurface)->Blt(&rcDest, (IDirectDrawSurface4 *)ppvOut, &rcSource, DDBLT_WAIT, NULL);
			HRESULT ret = (*ppDecoySurface)->Lock(lpDestRect, lpDDSurfaceDesc, dwFlags | DDLOCK_WAIT, 0);
			return ret;
		}
	}

	DDRAWSURFACE4_Lock_Type ofn = (DDRAWSURFACE4_Lock_Type)ddrawsurface4_hooks[hpos].oldFunc;
	HRESULT ret = ofn(ppvOut, lpDestRect, lpDDSurfaceDesc, dwFlags, hEvent);
	LogDXError(ret);
	Log("\n");
	
	if(lpDDSurfaceDesc != NULL) {
		char dwFlags_buffer[LOGBUFFER_MAX], ddscaps1_buffer[LOGBUFFER_MAX], ddpf_buffer[LOGBUFFER_MAX];
		FlagsToString(FLAGS_DDSD, CFLAGS_DDSD, lpDDSurfaceDesc->dwFlags, (char *)&dwFlags_buffer, LOGBUFFER_MAX);
		FlagsToString(FLAGS_DDSCAPS1, CFLAGS_DDSCAPS1, lpDDSurfaceDesc->ddsCaps.dwCaps, (char *)&ddscaps1_buffer, LOGBUFFER_MAX);
		FlagsToString(FLAGS_DDPF, CFLAGS_DDPF, lpDDSurfaceDesc->ddpfPixelFormat.dwFlags, (char *)&ddpf_buffer, LOGBUFFER_MAX);

		Log("->lpDDSurfaceDesc { dwSize=%#010lx, dwFlags=%#010lx (%s), dwWidth=%#010lx (%d), dwHeight=%#010lx (%d), lPitch=%#010lx , dwLinearSize=%#010lx, dwBackBufferCount=%#010lx, dwMipMapCount=%#010lx, dwRefreshRate=%#010lx, dwAlphaBitDepth=%#010lx, dwReserved=%#010lx,\n"
			"  lpSurface=%#010lx, ddckCKDestOverlay={ %#010lx, %#010lx }, ddckCKDestBlt={ %#010lx, %#010lx }, ddckCKSrcOverlay={ %#010lx, %#010lx }, ddckCKSrcBlt={ %#010lx, %#010lx },\n"
			"  ddpfPixelFormat={ dwSize=%#010lx, dwFlags=%#010lx (%s), dwFourCC=%#010lx, dwRGBBitCount=%#010lx, dwYUVBitCount=%#010lx, dwZBufferBitDepth=%#010lx, dwAlphaBitDepth=%#010lx, dwLuminanceBitCount=%#010lx, dwBumpBitCount=%#010lx, dwRBitMask=%#010lx,\n"
			"    dwYBitMask=%#010lx, dwStencilBitDepth=%#010lx, dwLuminanceBitMask=%#010lx, dwBumpDuBitMask=%#010lx, dwGBitMask=%#010lx, dwUBitMask=%#010lx, dwZBitMask=%#010lx, dwBumpDvBitMask=%#010lx, dwBBitMask=%#010lx, dwVBitMask=%#010lx, dwStencilBitMask=%#010lx,\n"
			"    dwBumpLuminanceBitMask=%#010lx, dwRGBAlphaBitMask=%#010lx, dwYUVAlphaBitMask=%#010lx, dwLuminanceAlphaBitMask=%#010lx, dwRGBZBitMask=%#010lx, dwYUVZBitMask=%#010lx },\n"
			"  ddsCaps={ %#010lx (%s), %#010lx, %#010lx, %#010lx }, dwTextureStage=%#010lx }\n",
			lpDDSurfaceDesc->dwSize, lpDDSurfaceDesc->dwFlags, dwFlags_buffer, lpDDSurfaceDesc->dwWidth, (unsigned int)lpDDSurfaceDesc->dwWidth, lpDDSurfaceDesc->dwHeight, (unsigned int)lpDDSurfaceDesc->dwHeight, lpDDSurfaceDesc->lPitch,
			lpDDSurfaceDesc->dwLinearSize, lpDDSurfaceDesc->dwBackBufferCount, lpDDSurfaceDesc->dwMipMapCount, lpDDSurfaceDesc->dwRefreshRate, lpDDSurfaceDesc->dwAlphaBitDepth, lpDDSurfaceDesc->dwReserved, lpDDSurfaceDesc->lpSurface,
			lpDDSurfaceDesc->ddckCKDestOverlay.dwColorSpaceLowValue, lpDDSurfaceDesc->ddckCKDestOverlay.dwColorSpaceHighValue, lpDDSurfaceDesc->ddckCKDestBlt.dwColorSpaceLowValue, lpDDSurfaceDesc->ddckCKDestBlt.dwColorSpaceHighValue,
			lpDDSurfaceDesc->ddckCKSrcOverlay.dwColorSpaceLowValue, lpDDSurfaceDesc->ddckCKSrcOverlay.dwColorSpaceHighValue, lpDDSurfaceDesc->ddckCKSrcBlt.dwColorSpaceLowValue, lpDDSurfaceDesc->ddckCKSrcBlt.dwColorSpaceHighValue,
			
			lpDDSurfaceDesc->ddpfPixelFormat.dwSize, lpDDSurfaceDesc->ddpfPixelFormat.dwFlags, ddpf_buffer, lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC, lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount, lpDDSurfaceDesc->ddpfPixelFormat.dwYUVBitCount,
			lpDDSurfaceDesc->ddpfPixelFormat.dwZBufferBitDepth, lpDDSurfaceDesc->ddpfPixelFormat.dwAlphaBitDepth, lpDDSurfaceDesc->ddpfPixelFormat.dwLuminanceBitCount, lpDDSurfaceDesc->ddpfPixelFormat.dwBumpBitCount,
			lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask, lpDDSurfaceDesc->ddpfPixelFormat.dwYBitMask, lpDDSurfaceDesc->ddpfPixelFormat.dwStencilBitDepth, lpDDSurfaceDesc->ddpfPixelFormat.dwLuminanceBitMask,
			lpDDSurfaceDesc->ddpfPixelFormat.dwBumpDuBitMask, lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask, lpDDSurfaceDesc->ddpfPixelFormat.dwUBitMask, lpDDSurfaceDesc->ddpfPixelFormat.dwZBitMask, lpDDSurfaceDesc->ddpfPixelFormat.dwBumpDvBitMask,
			lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask, lpDDSurfaceDesc->ddpfPixelFormat.dwVBitMask, lpDDSurfaceDesc->ddpfPixelFormat.dwStencilBitMask, lpDDSurfaceDesc->ddpfPixelFormat.dwBumpLuminanceBitMask,
			lpDDSurfaceDesc->ddpfPixelFormat.dwRGBAlphaBitMask, lpDDSurfaceDesc->ddpfPixelFormat.dwYUVAlphaBitMask, lpDDSurfaceDesc->ddpfPixelFormat.dwLuminanceAlphaBitMask, lpDDSurfaceDesc->ddpfPixelFormat.dwRGBZBitMask,
			lpDDSurfaceDesc->ddpfPixelFormat.dwYUVZBitMask,
			
			lpDDSurfaceDesc->ddsCaps.dwCaps, ddscaps1_buffer, lpDDSurfaceDesc->ddsCaps.dwCaps2, lpDDSurfaceDesc->ddsCaps.dwCaps3, lpDDSurfaceDesc->ddsCaps.dwCaps4, lpDDSurfaceDesc->dwTextureStage
		);
		g_lockedSurface = (LPDIRECTDRAWSURFACE4)ppvOut;
		g_lpSurface = lpDDSurfaceDesc->lpSurface;
	}

	return ret;
}
예제 #10
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;
}
예제 #11
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;
}
예제 #12
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;
    }
}
예제 #13
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;
}
예제 #14
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;
}
예제 #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