Esempio n. 1
0
int	EnumGraphicsDevice( void )
{
	LPDIRECTDRAWENUMERATEEX pDirectDrawEnumerateEx=NULL;
	HINSTANCE               hDDrawDLL = NULL;

	
	
	hDDrawDLL = GetModuleHandle("DDRAW");
	if( NULL == hDDrawDLL ){
		MessageBox( NULL, "LoadLibrary() FAILED", 
					"DirectDraw", MB_OK | MB_ICONERROR );
		return NULL;
	}

	
	g_iMaxDevices=0;
	DirectDrawEnumerate( DDEnumCallback, NULL );

	if( 0 == g_iMaxDevices ){
		MessageBox( NULL, "No devices to enumerate.", 
					"DirectDraw Sample", MB_OK | MB_ICONERROR );
		return NULL;
	}
	return g_iMaxDevices;
}
Esempio n. 2
0
VNGError VngoDirect3D::init(char *targetName)
{
    target = targetName;

    if (target != NULL)
    {
        if (DirectDrawEnumerate(FindDeviceCallback,(LPVOID)this)==DD_OK)
        {
            if (dd==NULL)
                err = DirectDrawCreate(&targetID, &dd, NULL);
            if (err != DD_OK)
            {
                if (dd != NULL)
                {
                    dd->Release();
                    dd = NULL;
                }
                err = DirectDrawCreate(NULL, &dd, NULL);
            }
        }
        else
        {
            if (dd==NULL)
                err = DirectDrawCreate(NULL, &dd, NULL);
        }
    }
    else
    {
        if (dd==NULL)
            err = DirectDrawCreate(NULL, &dd, NULL);
    }


    if (err != DD_OK)
        return VNGO_INTERNAL_ERROR;

    err = dd->QueryInterface(IID_IDirect3D2, (void**)&d3d);

    if (err != DD_OK)
        return VNGO_INTERNAL_ERROR;


    VgSystem->D3DTx = new VngoTextureManager;
    if (VgSystem->D3DTx)
    {
        VgSystem->D3DTx->screen = this;
    }
    else
    {
        term();
        return VNGO_INTERNAL_ERROR;
    }

    type_info = SCREENTYPE_D3D;
    return VNGO_NO_ERROR;
}
Esempio n. 3
0
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything and calls
//       DirectDrawEnumerateEx() to get all of the device info.
//-----------------------------------------------------------------------------
int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, int nCmdShow )
{
    LPDIRECTDRAWENUMERATEEX pDirectDrawEnumerateEx;
    HINSTANCE               hDDrawDLL = NULL;

    // Do a GetModuleHandle and GetProcAddress in order to get the
    // DirectDrawEnumerateEx function
    hDDrawDLL = GetModuleHandle("DDRAW");
    if( NULL == hDDrawDLL )
    {
        MessageBox( NULL, "LoadLibrary() FAILED", 
                    "DirectDraw Sample", MB_OK | MB_ICONERROR );
        return -1;
    }

    pDirectDrawEnumerateEx = (LPDIRECTDRAWENUMERATEEX) GetProcAddress( hDDrawDLL, "DirectDrawEnumerateExA" );
    if( pDirectDrawEnumerateEx )
    {
        pDirectDrawEnumerateEx( DDEnumCallbackEx, NULL,
                                DDENUM_ATTACHEDSECONDARYDEVICES |
                                DDENUM_DETACHEDSECONDARYDEVICES |
                                DDENUM_NONDISPLAYDEVICES );
    }
    else
    {
        // Old DirectDraw, so do it the old way
        DirectDrawEnumerate( DDEnumCallback, NULL );
    }

    if( 0 == g_iMaxDevices )
    {
        MessageBox( NULL, "No devices to enumerate.", 
                    "DirectDraw Sample", MB_OK | MB_ICONERROR );
        return -1;
    }

    // Bring up the dialog to show all the devices
    DialogBox( hInst, MAKEINTRESOURCE(IDD_DRIVERINFO), 
               GetDesktopWindow(), (DLGPROC)InfoDlgProc );

    return 0;
}
static void hwdEnumerate(void)
{
    (void)DirectDrawEnumerate(hwdDirectDraw_cb, NULL);
}
Esempio n. 5
0
/*
 * D3DAppICreateDD
 * Creates the DirectDraw device and saves the current palette. If a 3D 
 * capable DD driver is available, use it as the DD device, otherwise, use
 * the HEL.  It is assumed that a 3D capable DD hardware driver is not the
 * primary device and hence cannot operate in a window (ie it's a fullscreen
 * only device displaying on a second monitor).  Valid flags:
 *     D3DAPP_ONLYDDEMULATION    Always use the DirectDraw HEL
 */
BOOL
D3DAppICreateDD(DWORD flags)
{
    HDC hdc;
    int i;
    LPDIRECTDRAW lpDD = NULL;
    DDCAPS DriverCaps, HELCaps, ddcaps;
    LPDIRECTDRAW4 pdd4 = NULL;

    /*
     * If we aren't forced to use the DirectDraw HEL, search for a 3D capable
     * DirectDraw hardware driver and create it.
     */
    if (!(flags & D3DAPP_ONLYDDEMULATION))
    {
        ddcount3d = 0;
        LastError = DirectDrawEnumerate(D3DAppIDDEnumCallback, &lpDD);
        if (LastError != DD_OK) 
        {
            D3DAppISetErrorString("DirectDrawEnumerate failed.\n%s",
                                  D3DAppErrorToString(LastError));
            return FALSE;
        }
    }
    if (!lpDD)
    {
        /*
         * If we haven't created a hardware DD device by now, resort to HEL
         */
        d3dappi.bIsPrimary = TRUE;
        LastError = DirectDrawCreate(NULL, &d3dappi.lpDD, NULL);
        if (LastError != DD_OK) 
        {
            D3DAppISetErrorString("DirectDrawCreate failed.\n%s",
                                  D3DAppErrorToString(LastError));
            return FALSE;
        }
    } else 
    {
        d3dappi.lpDD = lpDD;

        memset (&DriverCaps, 0, sizeof(DDCAPS));
        DriverCaps.dwSize = sizeof(DDCAPS);
        memset (&HELCaps, 0, sizeof(DDCAPS));
        HELCaps.dwSize = sizeof(DDCAPS);

        d3dappi.lpDD->lpVtbl->GetCaps(d3dappi.lpDD, &DriverCaps, &HELCaps);

        if (!((DriverCaps.dwCaps & DDCAPS_BLTSTRETCH) || (HELCaps.dwCaps & DDCAPS_BLTSTRETCH)))
        {
            CanDoStrechBlt = FALSE;
        }
    }

    // find out if current driver can do windowed mode ( need dx6 interface )

    // query for IDirectDraw4 ptr
    IDirectDraw_QueryInterface( d3dappi.lpDD, &IID_IDirectDraw4, (LPVOID *)&pdd4 );

    if ( pdd4 )
    {
        // get caps
        memset( &ddcaps, 0, sizeof( DDCAPS ) );
        ddcaps.dwSize = sizeof( DDCAPS );
        IDirectDraw4_GetCaps( pdd4, &ddcaps, NULL );

        // can do windowed??
        if( ddcaps.dwCaps2 & DDCAPS2_CANRENDERWINDOWED )
            CanRenderWindowed = TRUE;
        else
            CanRenderWindowed = FALSE;

        // release dd4 interface
        IDirectDraw4_Release( pdd4 );
    }

    /*
     * Save the original palette for when we are paused.  Just in case we
     * start in a fullscreen mode, put them in ppe.
     */
    hdc = GetDC(NULL);
    GetSystemPaletteEntries(hdc, 0, (1 << 8),
                            (LPPALETTEENTRY)(&Originalppe[0]));
    for (i = 0; i < 256; i++)
        ppe[i] = Originalppe[i];
    ReleaseDC(NULL, hdc);
    return TRUE;
}
Esempio n. 6
0
bool DXGame::initDirectDraw(){
	dprintf(("entered initDirectDraw()\n"));	

	//LPDIRECTDRAW temp_lpdd;
	//create direct draw object	  	
	if(DirectDrawCreate(NULL, &lpDirectDrawObject, NULL) != DD_OK){	
	//if(DirectDrawCreate(NULL, &temp_lpdd, NULL) != DD_OK){	
		dprintf(("  ddobject not created\n"));
		DestroyWindow(hwnd); return FALSE;
	}dprintf(("  created direct draw object\n"));	

	/*
	//query interface
	if(temp_lpdd->QueryInterface(IID_IDirectDraw2, (LPVOID*)&lpDirectDrawObject) != S_OK){
		dprintf(("  could not query interfacen"));
		temp_lpdd->Release();
		DestroyWindow(hwnd); return FALSE;
	}
	temp_lpdd->Release();  // just used to get the DD2 interface
*/

	//set cooperative level
	if(lpDirectDrawObject->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) != DD_OK){
		DestroyWindow(hwnd); return FALSE;
	}dprintf(("  coop level set\n"));
	
	//enumerate the display drivers		
	if(DirectDrawEnumerate(enumDisplayDrivers, &displayDriverList) != DD_OK){
		dprintf(("  could not enumerate display driver\n"));
		DestroyWindow(hwnd); return FALSE;
	}

	if(displayDriverList != NULL){
		dprintf(("------------------------------------\n"));

		dprintf(("driver description:\n"));
		if(displayDriverList[0].description != NULL) 
			dprintf(("  %s\n", displayDriverList[0].description));

		//enumerate the display modes
		if(lpDirectDrawObject->EnumDisplayModes(0, NULL, &displayModeList, 
			enumDisplayModes) != DD_OK){			
			dprintf(("  could not enumerate display modes\n"));		
			DestroyWindow(hwnd); return FALSE;
		}

		// make sure the desired display mode is supported
		bool OK = false;
		DisplayMode *dm = NULL;
		for(dm = displayModeList; dm != NULL; dm=dm->next){			
			if(dm->width == screenWidth && dm->height == screenHeight && 
				dm->depth == colorDepth){
				dprintf(("  %dx%d: %d ---> YES\n", dm->width, dm->height, dm->depth));
				OK = true;
			}
		}

		// display an error message box if the display mode is not supported
		if(!OK){
			char message[64];
			sprintf(message, "Could not set display mode: %d x %d: %d", 
				screenWidth, screenHeight, colorDepth);		
			MessageBox(hwnd, message, "Sorry!", MB_OK);
			DestroyWindow(hwnd);
			return false;
		}		
		dprintf(("------------------------------------\n"));

	}// end if displayDriverList != NULL

	// change screen resolution, will not get here if the display mode
	// is not supported
	if(lpDirectDrawObject->SetDisplayMode(screenWidth, screenHeight, colorDepth) !=DD_OK ){		
		dprintf(("  could not set display mode\n"))
		DestroyWindow(hwnd); return FALSE;		
	}dprintf(("  display mode set\n"));

	//create the surfaces
	DDSurfaceDesc ddsd; //direct draw surface descriptor
	ZeroMemory(&ddsd, sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);
	ddsd.dwFlags = DDSD_CAPS|DDSD_BACKBUFFERCOUNT;// | DDSD_CKSRCBLT;
	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP 
		| DDSCAPS_COMPLEX;		
	ddsd.dwBackBufferCount = 1;
	//ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = TRANSPARENT_COLOR;
	//ddsd.ddckCKSrcBlt.dwColorSpaceHighValue = TRANSPARENT_COLOR;

	/*
	DDCAPS driverCaps;
	lpDirectDrawObject->GetCaps(&driverCaps, NULL);
	if((driverCaps.dwCaps2 & DDCAPS2_WIDESURFACES) == DDCAPS2_WIDESURFACES){	
		char message[256];
		sprintf(message, "Error: your primary display device does not\n" \
			"support wide surfaces. Check the DirectX setting in the Control \n"
			"Panel and uncheck Disable Wide Surfaces\n");
		dprintf((message));
		MessageBox(hwnd, message, "Sorry!", MB_OK);
		DestroyWindow(hwnd);
		return false;
	}*/

	dprintf(("   passed caps checks\n"));

	HRESULT r;
	if((r = lpDirectDrawObject->CreateSurface(&ddsd, &lpPrimary, NULL)) != DD_OK){
		dprintf(("Error ** could not create primary surface:\n"));
		debugCreateSurface(r);
		return FALSE;
	}	

	//get pointer to the secondary surface
	

	DDSCAPS ddscaps; ZeroMemory(&ddscaps, sizeof(ddscaps));
	ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
	if(lpPrimary->GetAttachedSurface(&ddscaps, &lpSecondary) != DD_OK){	    
		return false;
	}

	// setup the clipper
	LPDDClipper clipper;
	if(lpDirectDrawObject->CreateClipper(NULL, &clipper, NULL) != DD_OK) return false;
	if(clipper->SetHWnd(NULL, hwnd) != DD_OK) return false;
	if(lpSecondary->SetClipper(clipper) != DD_OK) return false;	
	//clipper->Release();

	dprintf(("entered initDirectDraw()\n"));
	return TRUE;
}
void enum_dd_devices(d3d_context* d3d)
{
    HRESULT hr;
    char targetDev[128];

    ddList.erase(ddList.begin(), ddList.end());

    hr = DirectDrawEnumerate(enum_dd_devices_cb, NULL);
    if (FAILED(hr))
    {
        errLog("enum_dd_devices(DirectDrawCreate)", hr);
    }

    devList.erase(devList.begin(), devList.end());

    for (listdd::iterator i = ddList.begin(); i != ddList.end(); ++i)
    {
        d3d->ddraw1 = (*i).ddraw;

        hr = d3d->ddraw1->QueryInterface(IID_IDirectDraw4, (void**)&d3d->ddraw4);
        if (FAILED(hr))
        {
            errLog("enum_dd_devices(QueryInterface[ddraw4])", hr);
            d3d->ddraw1->Release();
            d3d->ddraw1 = NULL;
            continue;
        }

        hr = d3d->ddraw4->QueryInterface(IID_IDirect3D3, (void**)&d3d->d3dObject);
        if (FAILED(hr))
        {
            errLog("enum_dd_devices(QueryInterface[d3d3])", hr);
            d3d->ddraw4->Release();
            d3d->ddraw4 = NULL;
            continue;
        }

        enum_display_modes(d3d, (*i).nameStr);

        enum_d3d_devices(d3d, (*i).nameStr);

        d3d->d3dObject->Release();
        d3d->d3dObject = NULL;

        d3d->ddraw4->Release();
        d3d->ddraw4 = NULL;

        strncpy(targetDev, rglD3DGetDevice(), 127);
        if (strlen(targetDev) > 0)
        {
            if (strcmp((*i).nameStr, targetDev) == 0)
            {
                lpDirectDraw = d3d->ddraw1;
                d3d->ddraw1 = NULL;
//                rglD3DSetDevice(NULL);
                goto FINISH_NOW;
            }
            else
            {
                d3d->ddraw1->Release();
                d3d->ddraw1 = NULL;
            }
        }
        else
        {
            d3d->ddraw1->Release();
            d3d->ddraw1 = NULL;
        }
    }

  FINISH_NOW:
    devList.erase(devList.begin(), devList.end());
}