Пример #1
0
/*
 * Helpers.
 */
static LPDIRECTDRAW7 getDDRAW (void)
{
    LPDIRECTDRAW7 pDDRAW = NULL;
    LPDIRECTDRAW iface = NULL;

    HRESULT rc = DirectDrawCreate (NULL, &iface, NULL);

    if (rc != DD_OK)
    {
        LOGDDRAW(("DDRAW: Could not create DirectDraw interface rc= 0x%08X\n", rc));
    }
    else
    {
        rc = iface->QueryInterface (IID_IDirectDraw7, (void**)&pDDRAW);

        if (rc != DD_OK)
        {
            LOGDDRAW(("DDRAW: Could not query DirectDraw 7 interface rc = 0x%08X\n", rc));
        }
        else
        {
            rc = pDDRAW->SetCooperativeLevel (NULL, DDSCL_NORMAL);

            if (rc != DD_OK)
            {
                LOGDDRAW(("DDRAW: Could not set the DirectDraw cooperative level rc = 0x%08X\n", rc));
                pDDRAW->Release ();
            }
        }

        iface->Release();
    }

    return rc == DD_OK? pDDRAW: NULL;
}
Пример #2
0
HRESULT CUtilGPU::QueryVideoMemorySize(DWORD dwCaps, DWORD* pdwTotalMem, DWORD* pdwFreeMem)
{
	LPDIRECTDRAW lpdd = NULL;
	HRESULT hr = DirectDrawCreate(NULL, &lpdd, NULL);
	if(SUCCEEDED(hr))
	{
		LPDIRECTDRAW7 lpdd7 = NULL;
		hr = lpdd->QueryInterface(IID_IDirectDraw7, (LPVOID*)&lpdd7);
		if(SUCCEEDED(hr))
		{
			DDSCAPS2 ddsCaps2;
			DWORD dwTotal=0, dwFree=0;
			// Initialize the structure.
			ZeroMemory(&ddsCaps2, sizeof(ddsCaps2));
			ddsCaps2.dwCaps = dwCaps;
			hr = lpdd7->GetAvailableVidMem(&ddsCaps2, &dwTotal, &dwFree);
			if(SUCCEEDED(hr))
			{
				if(pdwTotalMem)
					*pdwTotalMem =(dwTotal>>20); //rounded to MB
				if(pdwFreeMem)
					*pdwFreeMem = (dwFree>>20); //rounded to MB
			}
			lpdd7->Release();
		}
		lpdd->Release();
	}
	return hr;
}
Пример #3
0
void DDShutdown(void)
{
    // release clipper
    if (lpDDClipper) {
        lpDDClipper->Release();
        lpDDClipper = NULL;
    }
    
    // release the secondary surface
    if (lpDDSBack) {
        lpDDSBack->Release();
        lpDDSBack = NULL;
    }
    
    // release the primary surface
    if (lpDDSPrimary) {
        lpDDSPrimary->Release();
        lpDDSPrimary = NULL;
    }
    
    // finally, the main dd object
    if (lpDD) {
        lpDD->Release();
        lpDD = NULL;
    }
}
Пример #4
0
static void finiObjects(BOOL freeDD)
{
    if (!bActive)
    {
        return;
    }
    if (lpDD != NULL)
    {
        if (PrimarySurface != NULL)
        {
            PrimarySurface->Release();
            PrimarySurface = NULL;
        }
        if (BackSurface != NULL)
        {
            BackSurface->Release();
            BackSurface = NULL;
        }
        if (freeDD)
        {
            lpDD->Release();
            lpDD = NULL;
        }
    }
}
Пример #5
0
static void
ReleaseAllObjects(void)
{
    if (g_pDDSBack != NULL)
    {
        g_pDDSBack->Release();
        g_pDDSBack = NULL;
    }
    if (g_pDDSPrimary != NULL)
    {
        g_pDDSPrimary->Release();
        g_pDDSPrimary = NULL;
    }
    if (g_pDDSOne != NULL)
    {
        g_pDDSOne->Release();
        g_pDDSOne = NULL;
    }
    if (g_pDDSTwo != NULL)
    {
        g_pDDSTwo->Release();
        g_pDDSTwo = NULL;
    }
    if (g_pDD != NULL)
    {
        g_pDD->Release();
        g_pDD = NULL;
    }
}
Пример #6
0
BOOL WINAPI DDEnumDevCallback(GUID FAR *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName, LPVOID lpContext, HMONITOR hm)
{
	LPDIRECTDRAW ddp;
	LPDIRECTDRAW4 dd4p;
	DDDEVICEIDENTIFIER ddDev;
	BOOL ret = FALSE;

	if (DirectDrawCreate(lpGUID,&ddp,0) == DD_OK)
	{
		if(ddp->QueryInterface(IID_IDirectDraw4,(void **)&dd4p) == S_OK)
		{
			ZeroMemory(&ddDev,sizeof(ddDev));
			if(GetDeviceIdentifierEx(dd4p,&ddDev, DDGDI_GETHOSTIDENTIFIER) == DD_OK)
			{
				// add to table
				USES_CONVERSION;
				CUtilGPU::AddDisplayDevice(A2CT(lpDriverName), ddDev.dwVendorId, ddDev.dwDeviceId, ddDev.szDescription, ddDev.szDriver);
				ret = TRUE;
			}
			dd4p->Release();
		}
		ddp->Release();
	}

	return ret;
}
HRESULT DDVideo::InitDirectDraw()
{
	DDSURFACEDESC2 ddsd;
    DDSCAPS2 ddscaps;
	HRESULT		hRet;
 
    //Create the main DirectDraw object - updated to do it the hard way.... 7/10
    LPDIRECTDRAW pDD;

	HINSTANCE hInstDDraw;
    LPDIRECTDRAWCREATE pDDCreate = NULL;
    hInstDDraw = LoadLibrary("ddraw.dll");
	pDDCreate = ( LPDIRECTDRAWCREATE )GetProcAddress( hInstDDraw, "DirectDrawCreate" );
    pDDCreate( NULL, &pDD, NULL );
	//hRet = DirectDrawCreate(NULL,&pDD, NULL);

    hRet = pDD->QueryInterface(IID_IDirectDraw7, (LPVOID *) & m_lpDD);
      
	//Set cooperative level
	if (m_bWindowed) { //#112
		m_lpDD->SetCooperativeLevel(m_hWnd, DDSCL_ALLOWREBOOT | DDSCL_NORMAL | DDSCL_MULTITHREADED);
	} else {
		hRet = m_lpDD->SetCooperativeLevel(m_hWnd,DDSCL_EXCLUSIVE |DDSCL_ALLOWREBOOT| DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | DDSCL_MULTITHREADED);
		m_lpDD->SetDisplayMode(800,600,16,g_DX9Settings.m_refreshrate,0);
	}
	
	ZeroMemory(&ddsd, sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);
	
	//#112
	ddsd.dwFlags = (m_bWindowed) ? DDSD_CAPS : DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
	ddsd.ddsCaps.dwCaps = (m_bWindowed) ? DDSCAPS_PRIMARYSURFACE : DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;

	if (m_bWindowed) {
		LPDIRECTDRAWCLIPPER lpClipper;
		hRet = m_lpDD->CreateSurface(&ddsd, &m_lpDDSPrimary, NULL);
		hRet = m_lpDD->CreateClipper( 0, &lpClipper, NULL );
		hRet = lpClipper->SetHWnd( 0, m_hWnd );
		hRet = m_lpDDSPrimary->SetClipper( lpClipper );
		ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
		ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
		ddsd.dwWidth = 800;
		ddsd.dwHeight = 600;
		hRet = m_lpDD->CreateSurface(&ddsd, &m_lpDDSBack, NULL);
	} else {
		ddsd.dwBackBufferCount = 1;
		hRet = m_lpDD->CreateSurface(&ddsd, &m_lpDDSPrimary, NULL);
		ZeroMemory( &ddscaps, sizeof( ddscaps ) );
		ddscaps.dwCaps=DDSCAPS_BACKBUFFER;
		hRet = m_lpDDSPrimary->GetAttachedSurface(&ddscaps,&m_lpDDSBack);
	}

	pDD->Release();
	return hRet;
}
Пример #8
0
	~WSurfaceData() {
		if (clipper) clipper->Release();
		if (LeftBuffer) ((LPDIRECTDRAWSURFACE)LeftBuffer)->Release();
		if (RightBuffer) ((LPDIRECTDRAWSURFACE)RightBuffer)->Release();
		if (screen) screen->Release();
		if (ddraw) {
			if (!window_mode)
				ddraw->RestoreDisplayMode();
			ddraw->Release();
		}
		LeftBuffer=RightBuffer=0;
		ddraw=0,screen=0;
	}
Пример #9
0
//-----------------------------------------------------------------------------
// Name: ReleaseAllObjects()
// Desc: Finished with all objects we use; release them
//-----------------------------------------------------------------------------
static void ReleaseAllObjects(void)
{
	if (g_pDDSPrimary != NULL)
	{
		g_pDDSPrimary->Release();
		g_pDDSPrimary = NULL;
	}

	if (g_pDD != NULL)
	{
		g_pDD->Release();
		g_pDD = NULL;
	}
}
Пример #10
0
//------------------------------------------------------------
// Name: ShutDown
// Desc: Clean up everything.
//------------------------------------------------------------
int Shutdown()
{
	// this function is where you shutdown your game and
	// release all resources that you allocated

	// first release the primary surface
	if (lpddsprimary != NULL)
		lpddsprimary->Release();
       
	// release the directdraw object
	if (lpdd != NULL)
		lpdd->Release();

	// return success
	return(1);
} // end Shutdown
Пример #11
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;
}
Пример #12
0
//-----------------------------------------------------------------------------
// Name: CleanupGraphics()
// Desc:
//-----------------------------------------------------------------------------
VOID CleanupGraphics()
{
    for( DWORD i=0; i<4; i++ )
        if( g_pddsShip[i] )
            g_pddsShip[i]->Release();
    if( g_pddsNumbers )
        g_pddsNumbers->Release();
    if( g_pddsFrontBuffer )
        g_pddsFrontBuffer->Release();
    if( g_pArtPalette )
        g_pArtPalette->Release();
    if( g_pSplashPalette )
        g_pSplashPalette->Release();
    if( !g_bFullscreen && g_pddsBackBuffer )
        g_pddsBackBuffer->Release();
    if( g_pDD )
        g_pDD->Release();
}
Пример #13
0
void FreeDDraw()
{
	if(lpDD != NULL)
	{
		if(lpDDSPrimary != NULL)
		{
			lpDDSPrimary->Release();
			lpDDSPrimary = NULL;
		}
		if(lpDDSTemp != NULL)
		{
			lpDDSTemp->Release ();
			lpDDSTemp = NULL;
		}
		lpDD->Release ();
		lpDD = NULL;
	}
	return;
}
Пример #14
0
static void init_DirectDraw() {
    /**
     * Note: if DirectDraw fails to initialize, we will use GDI to
     *  draw to do the screenBuffer->LCD copying.
     */
    HRESULT hRet;
    hRet = DirectDrawCreate(NULL, &g_pDD, NULL);
    if (hRet != DD_OK) {
        return;
    }

    hRet = g_pDD->SetCooperativeLevel(hwndMain, DDSCL_NORMAL);
    if (hRet != DD_OK) {
        g_pDD->Release();
        g_pDD = NULL;
        return;
    }

    wince_init_fonts();
}
Пример #15
0
void _ReleaseAll( void )
{
    if ( DirectOBJ != NULL )
    {
        if ( RealScreen != NULL )
        {
            RealScreen->Release();
            RealScreen = NULL;
        }
        if ( SpriteImage != NULL )
        {
            SpriteImage->Release();
            SpriteImage = NULL;
        }
        if ( BackGround != NULL )
        {
            BackGround->Release();
            BackGround = NULL;
        }
        DirectOBJ->Release();
        DirectOBJ = NULL;
    }
}
Пример #16
0
void DD_CreateSurfaces(int w, int h, int fsh, int fs, int fsbpp, int flip, int dbl, int fsovl) // fsh is the height to use (not screen res)
{
  int resize_h=8, resize_w=8;
#ifdef RESIZE_ONRESIZE
  int fb_save[64*65+1];
  int fb_save_use=0;
#endif
  EnterCriticalSection(&g_cs);
  nodraw=0;
  if (g_lpDD)
  {
    extern int config_reuseonresize;
#ifdef RESIZE_ONRESIZE
    HRESULT han;
    int ll=!!last_used;
    DDSURFACEDESC d={sizeof(d),};
  	if (config_reuseonresize && g_w && g_h && g_lpRenderSurf[ll] &&
        (han = g_lpRenderSurf[ll]->Lock(NULL,&d,DDLOCK_WAIT,NULL)) == DD_OK) 
    {
      if (d.lpSurface)
      {
        int x,y;
        int dxpos=(g_w<<16)/64;
        int ypos=0;
        int dypos=(g_h<<16)/64;
        int *pp=((int *)d.lpSurface);

        if (g_fs && g_fs_height < g_h) // adjust to use partial screen when 
        {
          int fsy=g_h/2-g_fs_height/2;
          dypos=(g_fs_height<<16)/64;
          pp+=fsy * g_w;
        }

        for (y = 0; y < 64; y++)
        {
          int *p=pp + g_w * (ypos>>16);
          int xpos=0;
          for (x = 0; x < 64; x ++)
          {
            fb_save[(y<<6)+x]=p[xpos>>16];
            xpos+=dxpos;
          }
          ypos+=dypos;
        }
        memset(fb_save+64*64,0,sizeof(int)*65);
        fb_save_use=1;
      }
      g_lpRenderSurf[ll]->Unlock(d.lpSurface);
    }
#endif

		if (g_lpPrimSurf)
		{
			g_lpPrimSurf->Release();
			g_lpPrimSurfBack=g_lpPrimSurf=NULL;
		}
    if (g_lpRenderSurf[0]) g_lpRenderSurf[0]->Release();
    if (g_lpRenderSurf[1]) g_lpRenderSurf[1]->Release();
    g_lpRenderSurf[0]=0;
    g_lpRenderSurf[1]=0;
    if (g_lpddsOverlay) g_lpddsOverlay->Release();
    if (g_lpddsPrimary) g_lpddsPrimary->Release();
    g_lpddsOverlay=g_lpddsPrimary=NULL;
    g_lpDD->Release();
    g_lpDD=NULL;
  }
Пример #17
0
//-----------------------------------------------------------------------------
// Name: GetDXVersion()
// Desc: This function returns the DirectX version number as follows:
//          0x0000 = No DirectX installed
//          0x0100 = DirectX version 1 installed
//          0x0200 = DirectX 2 installed
//          0x0300 = DirectX 3 installed
//          0x0500 = At least DirectX 5 installed.
//          0x0600 = At least DirectX 6 installed.
//          0x0601 = At least DirectX 6.1 installed.
//          0x0700 = At least DirectX 7 installed.
//          0x0800 = At least DirectX 8 installed.
// 
//       Please note that this code is intended as a general guideline. Your
//       app will probably be able to simply query for functionality (via
//       QueryInterface) for one or two components.
//
//       Please also note:
//          "if( dwDXVersion != 0x500 ) return FALSE;" is VERY BAD. 
//          "if( dwDXVersion <  0x500 ) return FALSE;" is MUCH BETTER.
//       to ensure your app will run on future releases of DirectX.
//-----------------------------------------------------------------------------
DWORD GetDXVersion()
{
    DIRECTDRAWCREATE     DirectDrawCreate   = NULL;
    DIRECTDRAWCREATEEX   DirectDrawCreateEx = NULL;
    DIRECTINPUTCREATE    DirectInputCreate  = NULL;
    HINSTANCE            hDDrawDLL          = NULL;
    HINSTANCE            hDInputDLL         = NULL;
    HINSTANCE            hD3D8DLL           = NULL;
    HINSTANCE            hDPNHPASTDLL       = NULL;
    LPDIRECTDRAW         pDDraw             = NULL;
    LPDIRECTDRAW2        pDDraw2            = NULL;
    LPDIRECTDRAWSURFACE  pSurf              = NULL;
    LPDIRECTDRAWSURFACE3 pSurf3             = NULL;
    LPDIRECTDRAWSURFACE4 pSurf4             = NULL;
    DWORD                dwDXVersion        = 0;
    HRESULT              hr;

    // First see if DDRAW.DLL even exists.
    hDDrawDLL = LoadLibrary(_T("DDRAW.DLL"));
    if( hDDrawDLL == NULL )
    {
        dwDXVersion = 0;
        OutputDebugString(_T("Couldn't LoadLibrary DDraw\r\n"));
        return dwDXVersion;
    }

    // See if we can create the DirectDraw object.
    DirectDrawCreate = (DIRECTDRAWCREATE)GetProcAddress( hDDrawDLL, "DirectDrawCreate" );
    if( DirectDrawCreate == NULL )
    {
        dwDXVersion = 0;
        FreeLibrary( hDDrawDLL );
        OutputDebugString(_T("Couldn't GetProcAddress DirectDrawCreate\r\n"));
        return dwDXVersion;
    }

    hr = DirectDrawCreate( NULL, &pDDraw, NULL );
    if( FAILED(hr) )
    {
        dwDXVersion = 0;
        FreeLibrary( hDDrawDLL );
        OutputDebugString(_T("Couldn't create DDraw\r\n"));
        return dwDXVersion;
    }

    // So DirectDraw exists.  We are at least DX1.
    dwDXVersion = 0x100;

    // Let's see if IID_IDirectDraw2 exists.
    hr = pDDraw->QueryInterface( IID_IDirectDraw2, (VOID**)&pDDraw2 );
    if( FAILED(hr) )
    {
        // No IDirectDraw2 exists... must be DX1
        pDDraw->Release();
        FreeLibrary( hDDrawDLL );
        OutputDebugString(_T("Couldn't QI DDraw2\r\n"));
        return dwDXVersion;
    }

    // IDirectDraw2 exists. We must be at least DX2
    pDDraw2->Release();
    dwDXVersion = 0x200;


	//-------------------------------------------------------------------------
    // DirectX 3.0 Checks
	//-------------------------------------------------------------------------

    // DirectInput was added for DX3
    hDInputDLL = LoadLibrary(_T("DINPUT.DLL"));
    if( hDInputDLL == NULL )
    {
        // No DInput... must not be DX3
        pDDraw->Release();
        FreeLibrary( hDDrawDLL );
        OutputDebugString(_T("Couldn't LoadLibrary DInput\r\n"));
        return dwDXVersion;
    }

    DirectInputCreate = (DIRECTINPUTCREATE)GetProcAddress( hDInputDLL,
                                                        "DirectInputCreateA" );
    if( DirectInputCreate == NULL )
    {
        // No DInput... must be DX2
        FreeLibrary( hDInputDLL );
        pDDraw->Release();
        FreeLibrary( hDDrawDLL );
        OutputDebugString(_T("Couldn't GetProcAddress DInputCreate\r\n"));
        return dwDXVersion;
    }

    // DirectInputCreate exists. We are at least DX3
    dwDXVersion = 0x300;
    FreeLibrary( hDInputDLL );

    // Can do checks for 3a vs 3b here


	//-------------------------------------------------------------------------
    // DirectX 5.0 Checks
	//-------------------------------------------------------------------------

    // We can tell if DX5 is present by checking for the existence of
    // IDirectDrawSurface3. First, we need a surface to QI off of.
    DDSURFACEDESC ddsd;
    ZeroMemory( &ddsd, sizeof(ddsd) );
    ddsd.dwSize         = sizeof(ddsd);
    ddsd.dwFlags        = DDSD_CAPS;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

    hr = pDDraw->SetCooperativeLevel( NULL, DDSCL_NORMAL );
    if( FAILED(hr) )
    {
        // Failure. This means DDraw isn't properly installed.
        pDDraw->Release();
        FreeLibrary( hDDrawDLL );
        dwDXVersion = 0;
        OutputDebugString(_T("Couldn't Set coop level\r\n"));
        return dwDXVersion;
    }

    hr = pDDraw->CreateSurface( &ddsd, &pSurf, NULL );
    if( FAILED(hr) )
    {
        // Failure. This means DDraw isn't properly installed.
        pDDraw->Release();
        FreeLibrary( hDDrawDLL );
        dwDXVersion = 0;
        OutputDebugString(_T("Couldn't CreateSurface\r\n"));
        return dwDXVersion;
    }

    // Query for the IDirectDrawSurface3 interface
    if( FAILED( pSurf->QueryInterface( IID_IDirectDrawSurface3,
                                       (VOID**)&pSurf3 ) ) )
    {
        pSurf->Release();
        pDDraw->Release();
        FreeLibrary( hDDrawDLL );
        OutputDebugString(_T("Couldn't QI DDS3\r\n"));
        return dwDXVersion;
    }

    // QI for IDirectDrawSurface3 succeeded. We must be at least DX5
    dwDXVersion = 0x500;
    pSurf3->Release();


	//-------------------------------------------------------------------------
    // DirectX 6.0 Checks
	//-------------------------------------------------------------------------

    // The IDirectDrawSurface4 interface was introduced with DX 6.0
    if( FAILED( pSurf->QueryInterface( IID_IDirectDrawSurface4,
                                       (VOID**)&pSurf4 ) ) )
    {
        pSurf->Release();
        pDDraw->Release();
        FreeLibrary( hDDrawDLL );
        OutputDebugString(_T("Couldn't QI DDS4\r\n"));
        return dwDXVersion;
    }

    // IDirectDrawSurface4 was create successfully. We must be at least DX6
    dwDXVersion = 0x600;
    pSurf4->Release();
    pSurf->Release();
    pDDraw->Release();


	//-------------------------------------------------------------------------
    // DirectX 6.1 Checks
	//-------------------------------------------------------------------------

    // Check for DMusic, which was introduced with DX6.1
    LPDIRECTMUSIC pDMusic = NULL;
    CoInitialize( NULL );
    hr = CoCreateInstance( CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER,
                           IID_IDirectMusic, (VOID**)&pDMusic );
    if( FAILED(hr) )
    {
        FreeLibrary( hDDrawDLL );
        OutputDebugString(_T("Couldn't create CLSID_DirectMusic\r\n"));
        return dwDXVersion;
    }

    // DirectMusic was created successfully. We must be at least DX6.1
    dwDXVersion = 0x601;
    pDMusic->Release();
    CoUninitialize();
    

	//-------------------------------------------------------------------------
    // DirectX 7.0 Checks
	//-------------------------------------------------------------------------

    // Check for DirectX 7 by creating a DDraw7 object
    LPDIRECTDRAW7 pDD7;
    DirectDrawCreateEx = (DIRECTDRAWCREATEEX)GetProcAddress( hDDrawDLL,
                                                       "DirectDrawCreateEx" );
    if( NULL == DirectDrawCreateEx )
    {
        FreeLibrary( hDDrawDLL );
        OutputDebugString(_T("Couldn't GetProcAddress DirectDrawCreateEx\r\n"));
        return dwDXVersion;
    }

    if( FAILED( DirectDrawCreateEx( NULL, (VOID**)&pDD7, IID_IDirectDraw7,
                                    NULL ) ) )
    {
        FreeLibrary( hDDrawDLL );
        OutputDebugString(_T("Couldn't DirectDrawCreateEx\r\n"));
        return dwDXVersion;
    }

    // DDraw7 was created successfully. We must be at least DX7.0
    dwDXVersion = 0x700;
    pDD7->Release();


	//-------------------------------------------------------------------------
    // DirectX 8.0 Checks
	//-------------------------------------------------------------------------

    // Simply see if D3D8.dll exists.
    hD3D8DLL = LoadLibrary(_T("D3D8.DLL"));
    if( hD3D8DLL == NULL )
    {
	    FreeLibrary( hDDrawDLL );
        OutputDebugString(_T("Couldn't LoadLibrary D3D8.DLL\r\n"));
        return dwDXVersion;
    }

    // D3D8.dll exists. We must be at least DX8.0
    dwDXVersion = 0x800;


	//-------------------------------------------------------------------------
    // DirectX 8.1 Checks
	//-------------------------------------------------------------------------

    // Simply see if dpnhpast.dll exists.
    hDPNHPASTDLL = LoadLibrary(_T("dpnhpast.dll"));
    if( hDPNHPASTDLL == NULL )
    {
	    FreeLibrary( hDPNHPASTDLL );
        OutputDebugString(_T("Couldn't LoadLibrary dpnhpast.dll\r\n"));
        return dwDXVersion;
    }

    // dpnhpast.dll exists. We must be at least DX8.1
    dwDXVersion = 0x801;


	//-------------------------------------------------------------------------
    // End of checking for versions of DirectX 
	//-------------------------------------------------------------------------

    // Close open libraries and return
    FreeLibrary( hDDrawDLL );
    FreeLibrary( hD3D8DLL );
    
    return dwDXVersion;
}
Пример #18
0
//-----------------------------------------------------------------------------
// Name: GetDXVersion()
// Desc: This function returns two arguments:
//          dwDXVersion:
//            0x0000 = No DirectX installed
//            0x0100 = DirectX version 1 installed
//            0x0200 = DirectX 2 installed
//            0x0300 = DirectX 3 installed
//            0x0500 = At least DirectX 5 installed.
//            0x0600 = At least DirectX 6 installed.
//            0x0601 = At least DirectX 6.1 installed.
//            0x0700 = At least DirectX 7 installed.
//          dwDXPlatform:
//            0                          = Unknown (This is a failure case)
//            VER_PLATFORM_WIN32_WINDOWS = Windows 9X platform
//            VER_PLATFORM_WIN32_NT      = Windows NT platform
// 
//          Please note that this code is intended as a general guideline. Your
//          app will probably be able to simply query for functionality (via
//          QueryInterface) for one or two components.
//
//          Please also note:
//            "if (dxVer != 0x500) return FALSE;" is BAD. 
//            "if (dxVer < 0x500) return FALSE;" is MUCH BETTER.
//          to ensure your app will run on future releases of DirectX.
//-----------------------------------------------------------------------------
VOID GetDXVersion( DWORD* pdwDXVersion, DWORD* pdwDXPlatform )
{
    HRESULT              hr;
    HINSTANCE            DDHinst = 0;
    HINSTANCE            DIHinst = 0;
    LPDIRECTDRAW         pDDraw  = 0;
    LPDIRECTDRAW2        pDDraw2 = 0;
    DIRECTDRAWCREATE     DirectDrawCreate   = 0;
    DIRECTDRAWCREATEEX   DirectDrawCreateEx = 0;
    DIRECTINPUTCREATE    DirectInputCreate  = 0;
    OSVERSIONINFO        osVer;
    LPDIRECTDRAWSURFACE  pSurf  = 0;
    LPDIRECTDRAWSURFACE3 pSurf3 = 0;
    LPDIRECTDRAWSURFACE4 pSurf4 = 0;

    // First get the windows platform
    osVer.dwOSVersionInfoSize = sizeof(osVer);
    if( !GetVersionEx( &osVer ) )
    {
        (*pdwDXPlatform) = 0;
        (*pdwDXVersion)  = 0;
        return;
    }

    if( osVer.dwPlatformId == VER_PLATFORM_WIN32_NT )
    {
        (*pdwDXPlatform) = VER_PLATFORM_WIN32_NT;

        // NT is easy... NT 4.0 is DX2, 4.0 SP3 is DX3, 5.0 is DX5
        // and no DX on earlier versions.
        if( osVer.dwMajorVersion < 4 )
        {
            (*pdwDXVersion) = 0; // No DX on NT3.51 or earlier
            return;
        }

        if( osVer.dwMajorVersion == 4 )
        {
            // NT4 up to SP2 is DX2, and SP3 onwards is DX3, so we are at least DX2
            (*pdwDXVersion) = 0x200;

            // We're not supposed to be able to tell which SP we're on, so check for dinput
            DIHinst = LoadLibrary( "DINPUT.DLL" );
            if( DIHinst == 0 )
            {
                // No DInput... must be DX2 on NT 4 pre-SP3
                OutputDebugString( "Couldn't LoadLibrary DInput\r\n" );
                return;
            }

            DirectInputCreate = (DIRECTINPUTCREATE)GetProcAddress( DIHinst,
                                                                 "DirectInputCreateA" );
            FreeLibrary( DIHinst );

            if( DirectInputCreate == 0 )
            {
                // No DInput... must be pre-SP3 DX2
                OutputDebugString( "Couldn't GetProcAddress DInputCreate\r\n" );
                return;
            }

            // It must be NT4, DX2
            (*pdwDXVersion) = 0x300;  // DX3 on NT4 SP3 or higher
            return;
        }
        // Else it's NT5 or higher, and it's DX5a or higher: Drop through to
        // Win9x tests for a test of DDraw (DX6 or higher)
    }
    else
    {
        // Not NT... must be Win9x
        (*pdwDXPlatform) = VER_PLATFORM_WIN32_WINDOWS;
    }

    // Now we know we are in Windows 9x (or maybe 3.1), so anything's possible.
    // First see if DDRAW.DLL even exists.
    DDHinst = LoadLibrary( "DDRAW.DLL" );
    if( DDHinst == 0 )
    {
        (*pdwDXVersion)  = 0;
        (*pdwDXPlatform) = 0;
        FreeLibrary( DDHinst );
        return;
    }

    // See if we can create the DirectDraw object.
    DirectDrawCreate = (DIRECTDRAWCREATE)GetProcAddress( DDHinst, "DirectDrawCreate" );
    if( DirectDrawCreate == 0 )
    {
        (*pdwDXVersion)  = 0;
        (*pdwDXPlatform) = 0;
        FreeLibrary( DDHinst );
        OutputDebugString( "Couldn't LoadLibrary DDraw\r\n" );
        return;
    }

    hr = DirectDrawCreate( NULL, &pDDraw, NULL );
    if( FAILED(hr) )
    {
        (*pdwDXVersion)  = 0;
        (*pdwDXPlatform) = 0;
        FreeLibrary( DDHinst );
        OutputDebugString( "Couldn't create DDraw\r\n" );
        return;
    }

    // So DirectDraw exists.  We are at least DX1.
    (*pdwDXVersion) = 0x100;

    // Let's see if IID_IDirectDraw2 exists.
    hr = pDDraw->QueryInterface( IID_IDirectDraw2, (VOID**)&pDDraw2 );
    if( FAILED(hr) )
    {
        // No IDirectDraw2 exists... must be DX1
        pDDraw->Release();
        FreeLibrary( DDHinst );
        OutputDebugString( "Couldn't QI DDraw2\r\n" );
        return;
    }

    // IDirectDraw2 exists. We must be at least DX2
    pDDraw2->Release();
    (*pdwDXVersion) = 0x200;


    ///////////////////////////////////////////////////////////////////////////
    // DirectX 3.0 Checks
    ///////////////////////////////////////////////////////////////////////////

    // DirectInput was added for DX3
    DIHinst = LoadLibrary( "DINPUT.DLL" );
    if( DIHinst == 0 )
    {
        // No DInput... must not be DX3
        OutputDebugString( "Couldn't LoadLibrary DInput\r\n" );
        pDDraw->Release();
        FreeLibrary( DDHinst );
        return;
    }

    DirectInputCreate = (DIRECTINPUTCREATE)GetProcAddress( DIHinst,
                                                        "DirectInputCreateA" );
    if( DirectInputCreate == 0 )
    {
        // No DInput... must be DX2
        FreeLibrary( DIHinst );
        FreeLibrary( DDHinst );
        pDDraw->Release();
        OutputDebugString( "Couldn't GetProcAddress DInputCreate\r\n" );
        return;
    }

    // DirectInputCreate exists. We are at least DX3
    (*pdwDXVersion) = 0x300;
    FreeLibrary( DIHinst );

    // Can do checks for 3a vs 3b here


    ///////////////////////////////////////////////////////////////////////////
    // DirectX 5.0 Checks
    ///////////////////////////////////////////////////////////////////////////

    // We can tell if DX5 is present by checking for the existence of
    // IDirectDrawSurface3. First, we need a surface to QI off of.
    DDSURFACEDESC ddsd;
    ZeroMemory( &ddsd, sizeof(ddsd) );
    ddsd.dwSize         = sizeof(ddsd);
    ddsd.dwFlags        = DDSD_CAPS;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

    hr = pDDraw->SetCooperativeLevel( NULL, DDSCL_NORMAL );
    if( FAILED(hr) )
    {
        // Failure. This means DDraw isn't properly installed.
        pDDraw->Release();
        FreeLibrary( DDHinst );
        (*pdwDXVersion) = 0;
        OutputDebugString( "Couldn't Set coop level\r\n" );
        return;
    }

    hr = pDDraw->CreateSurface( &ddsd, &pSurf, NULL );
    if( FAILED(hr) )
    {
        // Failure. This means DDraw isn't properly installed.
        pDDraw->Release();
        FreeLibrary( DDHinst );
        *pdwDXVersion = 0;
        OutputDebugString( "Couldn't CreateSurface\r\n" );
        return;
    }

    // Query for the IDirectDrawSurface3 interface
    if( FAILED( pSurf->QueryInterface( IID_IDirectDrawSurface3,
                                       (VOID**)&pSurf3 ) ) )
    {
        pDDraw->Release();
        FreeLibrary( DDHinst );
        return;
    }

    // QI for IDirectDrawSurface3 succeeded. We must be at least DX5
    (*pdwDXVersion) = 0x500;


    ///////////////////////////////////////////////////////////////////////////
    // DirectX 6.0 Checks
    ///////////////////////////////////////////////////////////////////////////

    // The IDirectDrawSurface4 interface was introduced with DX 6.0
    if( FAILED( pSurf->QueryInterface( IID_IDirectDrawSurface4,
                                       (VOID**)&pSurf4 ) ) )
    {
        pDDraw->Release();
        FreeLibrary( DDHinst );
        return;
    }

    // IDirectDrawSurface4 was create successfully. We must be at least DX6
    (*pdwDXVersion) = 0x600;
    pSurf->Release();
    pDDraw->Release();


    ///////////////////////////////////////////////////////////////////////////
    // DirectX 6.1 Checks
    ///////////////////////////////////////////////////////////////////////////

    // Check for DMusic, which was introduced with DX6.1
    LPDIRECTMUSIC pDMusic = NULL;
    CoInitialize( NULL );
    hr = CoCreateInstance( CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER,
                           IID_IDirectMusic, (VOID**)&pDMusic );
    if( FAILED(hr) )
    {
        OutputDebugString( "Couldn't create CLSID_DirectMusic\r\n" );
        FreeLibrary( DDHinst );
        return;
    }

    // DirectMusic was created successfully. We must be at least DX6.1
    (*pdwDXVersion) = 0x601;
    pDMusic->Release();
    CoUninitialize();
    

    ///////////////////////////////////////////////////////////////////////////
    // DirectX 7.0 Checks
    ///////////////////////////////////////////////////////////////////////////

    // Check for DirectX 7 by creating a DDraw7 object
    LPDIRECTDRAW7 pDD7;
    DirectDrawCreateEx = (DIRECTDRAWCREATEEX)GetProcAddress( DDHinst,
                                                       "DirectDrawCreateEx" );
    if( NULL == DirectDrawCreateEx )
    {
        FreeLibrary( DDHinst );
        return;
    }

    if( FAILED( DirectDrawCreateEx( NULL, (VOID**)&pDD7, IID_IDirectDraw7,
                                    NULL ) ) )
    {
        FreeLibrary( DDHinst );
        return;
    }

    // DDraw7 was created successfully. We must be at least DX7.0
    (*pdwDXVersion) = 0x700;
    pDD7->Release();

    
    ///////////////////////////////////////////////////////////////////////////
    // End of checks
    ///////////////////////////////////////////////////////////////////////////

    // Close open libraries and return
    FreeLibrary( DDHinst );
    
    return;
}
Пример #19
0
void ShutDownDirectDraw(){
  if(lpDirectDrawObject!=NULL){ //if DD object exists
    ReleaseSurfaces();
    lpDirectDrawObject->Release(); //release DD object
  }
}
Пример #20
0
/********************************************************************
* Function : WindowProc()
* Purpose : Receive and handle windows messages.
********************************************************************/
long FAR PASCAL WindowProc(HWND hwnd, UINT message,
									WPARAM wParam, LPARAM lParam)
{
	DDSURFACEDESC ddsd;
	DDBLTFX	BltFx;
	HRESULT ddreturn;

	switch (message)
	{
		case WM_ACTIVATEAPP :
			ActiveApp = wParam;
			break;

		case WM_CREATE :
			break;

		case WM_KEYDOWN :
			switch (wParam)
			{
				case VK_PAUSE :	/* Start or Stop realtime. */
					RealTime = !RealTime;
					break;
				case VK_SPACE :	/* Flip a single frame. */
					SimLoop();
					break;
				case VK_ESCAPE :
					DestroyWindow(hwnd);
					break;
				case VK_LEFT :
					bLeftKey = TRUE;
					break;
				case VK_RIGHT :
					bRightKey = TRUE;
					break;
				case VK_UP :
					bForwardKey = TRUE;
					break;
				case VK_DOWN :
					bBackKey = TRUE;
					break;
				case VK_ADD :
					nGauge++;
					break;
				case VK_SUBTRACT :
					nGauge--;
					break;
				case VK_HOME :
					nGauge = 0;
					break;
			}
			break;

		case WM_KEYUP :
			switch (wParam)
			{
				case VK_F1 :
					nState = 1;
					break;
				case VK_F2 :
					nState = 2;
					break;
				case VK_F3 :
					nState = 3;
					break;
				case VK_F4 :
					nState = 4;
					break;
				case VK_F5 :
					nState = 5;
					break;
				case VK_F6 :
					nState = 6;
					break;
				case VK_F7 :
					nState = 7;
					break;
				case VK_F8 :
					nState = 8;
					break;
				case VK_F9 :
					nState = 9;
					break;
				case VK_F10 :
					nState = 0;
					break;
				case VK_LEFT :
					bLeftKey = FALSE;
					break;
				case VK_RIGHT :
					bRightKey = FALSE;
					break;
				case VK_UP :
					bForwardKey = FALSE;
					break;
				case VK_DOWN :
					bBackKey = FALSE;
					break;
				case 'S' :
					// Screen Snapshot.
					// This is not done very reliably, infact, it's more of a hack so
					// I can show some Chrome snapshots on my website.
					// Open a file named "Snapshot.tga" and write the current content
					// of the screen as a targa file.
					HANDLE hFile;
					hFile = CreateFile("Snapshot.tga", GENERIC_WRITE, 0, NULL, 
										CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
										NULL);
					if (hFile != NULL)
					{
						// Write the Targa header, as appropriate for the current
						// screen type.
						DWORD dwWritten;
					   /* Targa File Header : (Little Endian / Intel)
						* Offset Length  Description
						*      0      1  ID field length
						*      1      1  Color map type.
						*      2      1  Image type.
						*      3      2  First color map entry.
						*      5      2  Color map length.
						*      7      1  Color map entry size.
						*      8      2  Image X origin.
						*     10      2  Image Y Origin.
						*     12      2  Image Width.
						*     14      2  Image Height.
						*     16      1  Bits per pixel.
						*     17      1  Image descriptor bits.
						* (from : "Graphics File Formats", David C. Kay and John R. Levine)
						*/
#						define OutB(b)\
						{	unsigned char b2;\
							b2 = b;\
							WriteFile(hFile, &b2, sizeof(b2), &dwWritten, NULL);\
						}
#						define OutW(w)\
						{	unsigned short w2;\
							w2 = w;\
							WriteFile(hFile, &w2, sizeof(w2), &dwWritten, NULL);\
						}
						OutB(0);		// No message ID field length.
						OutB(0);		// Colormap type = 0; true color.
						OutB(2);		// Image type = 2, True color, uncompressed.
						OutW(0);		// First colormap entry is 0, (Because Cmap type = 0).
						OutW(0);		// Colormap length = 0, (CMap type = 0).
						OutB(0);		// CMap entry size is 0 (because CMap type = 0)
						OutW(0);		// OriginX = 0;
						OutW(0);		// OriginY = 0;
						OutW(XRES);		// Image Width is the value of the XRES constant.
						OutW(YRES);		// Image Height is the value of the YRES constant.
						OutB(24);		// Bits per pixel.
						OutB(0x20);		// Image Descriptor Bits (0x20 = left to right, top to bottom).

						// Each pixel is written as a Blue Green Red triple.

						// Lock the surface & write each byte.
						DDSURFACEDESC ddsd;
						memset(&ddsd, 0, sizeof(DDSURFACEDESC));
						ddsd.dwSize = sizeof(ddsd);
						ddreturn = lpBackbuffer->Lock(NULL, &ddsd, DDLOCK_READONLY | DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL);
						if (ddreturn == DD_OK)
						{
							//DrawWorld((unsigned char *)ddsd.lpSurface, (int)ddsd.lPitch);
							int nX, nY;
							for (nY = 0; nY < YRES; nY++)
							{
								for (nX = 0; nX < XRES; nX++)
								{
									unsigned char ucByte;
									ucByte = *(((unsigned char *)ddsd.lpSurface) + ddsd.lPitch * nY + nX);

									// Index the colormap & write the BGR triple.
									OutB(WinColormap[ucByte].peBlue);
									OutB(WinColormap[ucByte].peGreen);
									OutB(WinColormap[ucByte].peRed);
								}
							}
							lpBackbuffer->Unlock(NULL);
						}
						// Close the file, we're done...
						CloseHandle(hFile);
					}
			}
			break;

		case WM_DESTROY :
			if (lpDirectDrawObject != NULL)
			{
				if (lpBackbuffer != NULL)
					lpBackbuffer->Release();
				if (lpPrimary != NULL)
					lpPrimary->Release();
				if (lpPalette != NULL)
					lpPalette->Release();
				lpDirectDrawObject->Release();
			}
			/* Free the world. */
			EndWorld();

			/* Free the font. */
			if (AppFont != NULL)
				DeleteObject(AppFont);

			ShowCursor(TRUE);
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hwnd, message, wParam, lParam);
	}

	return 0L;
}
Пример #21
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;
}
Пример #22
0
VOID CheckDXVersion()
{
	HRESULT hr;
	HINSTANCE DDHinst = 0;
	HINSTANCE DIHinst = 0;
	LPDIRECTDRAW pDDraw  = 0;
	LPDIRECTDRAW2 pDDraw2 = 0;
	DIRECTDRAWCREATE DirectDrawCreate   = 0;
	DIRECTDRAWCREATEEX DirectDrawCreateEx = 0;
	DIRECTINPUTCREATE DirectInputCreate  = 0;
	OSVERSIONINFO osVer;
	LPDIRECTDRAWSURFACE pSurf  = 0;
	LPDIRECTDRAWSURFACE3 pSurf3 = 0;
	LPDIRECTDRAWSURFACE4 pSurf4 = 0;
	DWORD * pdwDXVersion=&g_dwDXVersion;
	DWORD * pdwDXPlatform=&g_dwDXPlatform;

	// First get the windows platform
	osVer.dwOSVersionInfoSize = sizeof(osVer);
	if( !GetVersionEx( &osVer ) )
	{
		(*pdwDXPlatform) = 0;
		(*pdwDXVersion)  = 0;
		return;
	}

	if( osVer.dwPlatformId == VER_PLATFORM_WIN32_NT )
	{
		(*pdwDXPlatform) = VER_PLATFORM_WIN32_NT;

		// NT is easy... NT 4.0 is DX2, 4.0 SP3 is DX3, 5.0 is DX5
		// and no DX on earlier versions.
		if( osVer.dwMajorVersion < 4 )
		{
			(*pdwDXVersion) = 0; // No DX on NT3.51 or earlier
			return;
		}

		if( osVer.dwMajorVersion == 4 )
		{
			// NT4 up to SP2 is DX2, and SP3 onwards is DX3, so we are at least DX2
			(*pdwDXVersion) = 0x200;

			// We're not supposed to be able to tell which SP we're on, so check for dinput
			DIHinst = LoadLibrary( "DINPUT.DLL" );
			if( DIHinst == 0 )
			{
				// No DInput... must be DX2 on NT 4 pre-SP3
				OutputDebugString( "Couldn't LoadLibrary DInput\r\n" );
				return;
			}

			DirectInputCreate = (DIRECTINPUTCREATE)GetProcAddress( DIHinst,
																  "DirectInputCreateA" );
			FreeLibrary( DIHinst );

			if( DirectInputCreate == 0 )
			{
				// No DInput... must be pre-SP3 DX2
				OutputDebugString( "Couldn't GetProcAddress DInputCreate\r\n" );
				return;
			}

			// It must be NT4, DX2
			(*pdwDXVersion) = 0x300;  // DX3 on NT4 SP3 or higher
			return;
		}
		// Else it's NT5 or higher, and it's DX5a or higher: Drop through to
		// Win9x tests for a test of DDraw (DX6 or higher)
	}
	else
	{
		// Not NT... must be Win9x
		(*pdwDXPlatform) = VER_PLATFORM_WIN32_WINDOWS;
	}

	// Now we know we are in Windows 9x (or maybe 3.1), so anything's possible.
	// First see if DDRAW.DLL even exists.
	DDHinst = LoadLibrary( "DDRAW.DLL" );
	if( DDHinst == 0 )
	{
		(*pdwDXVersion)  = 0;
		(*pdwDXPlatform) = 0;
		FreeLibrary( DDHinst );
		return;
	}

	// See if we can create the DirectDraw object.
	DirectDrawCreate = (DIRECTDRAWCREATE)GetProcAddress( DDHinst, "DirectDrawCreate" );
	if( DirectDrawCreate == 0 )
	{
		(*pdwDXVersion)  = 0;
		(*pdwDXPlatform) = 0;
		FreeLibrary( DDHinst );
		OutputDebugString( "Couldn't LoadLibrary DDraw\r\n" );
		return;
	}

	hr = DirectDrawCreate( NULL, &pDDraw, NULL );
	if( FAILED(hr) )
	{
		(*pdwDXVersion)  = 0;
		(*pdwDXPlatform) = 0;
		FreeLibrary( DDHinst );
		OutputDebugString( "Couldn't create DDraw\r\n" );
		return;
	}

	// So DirectDraw exists.  We are at least DX1.
	(*pdwDXVersion) = 0x100;

	// Let's see if IID_IDirectDraw2 exists.
	hr = pDDraw->QueryInterface( IID_IDirectDraw2, (VOID * *)&pDDraw2 );
	if( FAILED(hr) )
	{
		// No IDirectDraw2 exists... must be DX1
		pDDraw->Release();
		FreeLibrary( DDHinst );
		OutputDebugString( "Couldn't QI DDraw2\r\n" );
		return;
	}

	// IDirectDraw2 exists. We must be at least DX2
	pDDraw2->Release();
	(*pdwDXVersion) = 0x200;


	///////////////////////////////////////////////////////////////////////////
	// DirectX 3.0 Checks
	///////////////////////////////////////////////////////////////////////////

	// DirectInput was added for DX3
	DIHinst = LoadLibrary( "DINPUT.DLL" );
	if( DIHinst == 0 )
	{
		// No DInput... must not be DX3
		OutputDebugString( "Couldn't LoadLibrary DInput\r\n" );
		pDDraw->Release();
		FreeLibrary( DDHinst );
		return;
	}

	DirectInputCreate = (DIRECTINPUTCREATE)GetProcAddress( DIHinst,
														  "DirectInputCreateA" );
	if( DirectInputCreate == 0 )
	{
		// No DInput... must be DX2
		FreeLibrary( DIHinst );
		FreeLibrary( DDHinst );
		pDDraw->Release();
		OutputDebugString( "Couldn't GetProcAddress DInputCreate\r\n" );
		return;
	}

	// DirectInputCreate exists. We are at least DX3
	(*pdwDXVersion) = 0x300;
	FreeLibrary( DIHinst );

	// Can do checks for 3a vs 3b here


	/////////////////////////////////////////////////////////////////////////////
	//// DirectX 5.0 Checks
	/////////////////////////////////////////////////////////////////////////////

	//// We can tell if DX5 is present by checking for the existence of
	//// IDirectDrawSurface3. First, we need a surface to QI off of.
	//DDSURFACEDESC ddsd;
	//ZeroMemory( &ddsd, sizeof(ddsd) );
	//ddsd.dwSize         = sizeof(ddsd);
	//ddsd.dwFlags        = DDSD_CAPS;
	//ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

	//hr = pDDraw->SetCooperativeLevel( NULL, DDSCL_NORMAL );
	//if( FAILED(hr) )
	//{
	//	// Failure. This means DDraw isn't properly installed.
	//	pDDraw->Release();
	//	FreeLibrary( DDHinst );
	//	(*pdwDXVersion) = 0;
	//	OutputDebugString( "Couldn't Set coop level\r\n" );
	//	return;
	//}
	//int surfcreated=0;
	//if (dx5_common.primary_surface) //already inited? (Cannot get primary surface twice)
	//{
	//	//we know, that we are dx5 at least, as the engine works
	//	pSurf3=dx5_common.primary_surface;
	//	surfcreated=0;
	//}
	//else
	//{
	//	hr = pDDraw->CreateSurface( &ddsd, &pSurf, NULL );
	//	if( FAILED(hr) )
	//	{
	//		// Failure. This means DDraw isn't properly installed.
	//		pDDraw->Release();
	//		FreeLibrary( DDHinst );
	//		*pdwDXVersion = 0;
	//		OutputDebugString( "Couldn't CreateSurface\r\n" );
	//		return;
	//	}
	//	surfcreated=1;


	//	// Query for the IDirectDrawSurface3 interface
	//	if( FAILED( pSurf->QueryInterface( IID_IDirectDrawSurface3,
	//									  (VOID * *)&pSurf3 ) ) )
	//	{
	//		pDDraw->Release();
	//		FreeLibrary( DDHinst );
	//		return;
	//	}
	//	pSurf->Release();
	//	pSurf=0;
	//}

	//// QI for IDirectDrawSurface3 succeeded. We must be at least DX5
	//(*pdwDXVersion) = 0x500;


	///////////////////////////////////////////////////////////////////////////
	// DirectX 6.0 Checks
	///////////////////////////////////////////////////////////////////////////

	//// The IDirectDrawSurface4 interface was introduced with DX 6.0
	//if( FAILED( pSurf3->QueryInterface( IID_IDirectDrawSurface4,
	//								   (VOID * *)&pSurf4 ) ) )
	//{
	//	pDDraw->Release();
	//	FreeLibrary( DDHinst );
	//	return;
	//}

	//// IDirectDrawSurface4 was create successfully. We must be at least DX6
	//(*pdwDXVersion) = 0x600;
	//if (surfcreated=1)
	//{
	//	pSurf3->Release();
	//}
	//pSurf3=0;
	//pSurf4->Release();
	//pDDraw->Release();


	///////////////////////////////////////////////////////////////////////////
	// DirectX 6.1 Checks
	///////////////////////////////////////////////////////////////////////////

	// Check for DMusic, which was introduced with DX6.1
	//LPUNKNOWN pDMusic = NULL;
	//CoInitialize( NULL );
	//hr = CoCreateInstance( CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER,
	//					  IID_IDirectMusic, (VOID * *)&pDMusic );
	//if( FAILED(hr) )
	//{
	//	OutputDebugString( "Couldn't create CLSID_DirectMusic\r\n" );
	//	FreeLibrary( DDHinst );
	//	return;
	//}

	//// DirectMusic was created successfully. We must be at least DX6.1
	//(*pdwDXVersion) = 0x601;
	//pDMusic->Release();
	//CoUninitialize();


	///////////////////////////////////////////////////////////////////////////
	// DirectX 7.0 Checks
	///////////////////////////////////////////////////////////////////////////

	// Check for DirectX 7 by creating a DDraw7 object
	LPDIRECTDRAW7 pDD7;
	DirectDrawCreateEx = (DIRECTDRAWCREATEEX)GetProcAddress( DDHinst,
															"DirectDrawCreateEx" );
	if( NULL == DirectDrawCreateEx )
	{
		FreeLibrary( DDHinst );
		return;
	}

	if( FAILED( DirectDrawCreateEx( NULL, (VOID * *)&pDD7, IID_IDirectDraw7,
								   NULL ) ) )
	{
		FreeLibrary( DDHinst );
		return;
	}

	// DDraw7 was created successfully. We must be at least DX7.0
	(*pdwDXVersion) = 0x700;
	pDD7->Release();
	FreeLibrary( DDHinst );

	///////////////////////////////////////////////////////////////////////////
	// DirectX8
	///////////////////////////////////////////////////////////////////////////

	//This one is easy: We just check wheter D3D8.DLL exists
	HINSTANCE D3D8;
	D3D8=LoadLibrary("d3d8.dll");
	if (!D3D8)
	{
		return;
	}
	(*pdwDXVersion)=0x800;
	FreeLibrary( D3D8);

	//-------------------------------------------------------------------------
	// DirectX 8.1 Checks
	//-------------------------------------------------------------------------

	// Simply see if dpnhpast.dll exists.
	HINSTANCE hDPNHPASTDLL;
	hDPNHPASTDLL = LoadLibrary( "dpnhpast.dll" );
	if( hDPNHPASTDLL == NULL )
	{
		//FreeLibrary( hDPNHPASTDLL );
		OutputDebugString( "Couldn't LoadLibrary dpnhpast.dll\r\n" );
		return;
	}

	FreeLibrary(hDPNHPASTDLL);
	// dpnhpast.dll exists. We must be at least DX8.1
	(*pdwDXVersion)= 0x801;

	//------------------------------------------------------------------------
	// DirectX 9.0 Checks
	//------------------------------------------------------------------------
	HINSTANCE dx9lib=0;
	dx9lib=LoadLibrary("d3d9.dll");
	if (dx9lib)
	{
		(*pdwDXVersion)=0x900;
		FreeLibrary(dx9lib);
	}
	else
	{
		return;
	}

	// DirectX 10? We don't use it, but we can test for it. 
	HINSTANCE dx10lib=0;
	dx9lib=LoadLibrary("d3d10.dll");
	if (dx9lib)
	{
		(*pdwDXVersion)=0x1000;
		FreeLibrary(dx10lib);
	}
	else
	{
		return;
	}



	///////////////////////////////////////////////////////////////////////////
	// End of checks
	///////////////////////////////////////////////////////////////////////////

	// Close open libraries and return


	return;
}