⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dglpf.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 2 页
字号:
				lpDD1,				&IID_IDirectDraw4,				(void**)&lpDD4);	if (FAILED(hRes)) {		ddlogError(DDLOG_ERROR, "dglBPFL: QueryInterface (DD4) failed", hRes);		goto clean_up;	}	// Retrieve caps of current display mode	ZeroMemory(&ddsdDisplayMode, sizeof(ddsdDisplayMode));	ddsdDisplayMode.dwSize = sizeof(ddsdDisplayMode);	hRes = IDirectDraw4_GetDisplayMode(lpDD4, &ddsdDisplayMode);	if (FAILED(hRes))		goto clean_up;	dwDisplayBitDepth = ddsdDisplayMode.ddpfPixelFormat.dwRGBBitCount;	dwPixelType = (dwDisplayBitDepth <= 8) ? PFD_TYPE_COLORINDEX : PFD_TYPE_RGBA;	dwRb = BitCount(ddsdDisplayMode.ddpfPixelFormat.dwRBitMask);	dwGb = BitCount(ddsdDisplayMode.ddpfPixelFormat.dwGBitMask);	dwBb = BitCount(ddsdDisplayMode.ddpfPixelFormat.dwBBitMask);	dwRs = BitShift(ddsdDisplayMode.ddpfPixelFormat.dwRBitMask);	dwGs = BitShift(ddsdDisplayMode.ddpfPixelFormat.dwGBitMask);	dwBs = BitShift(ddsdDisplayMode.ddpfPixelFormat.dwBBitMask);	if (BitCount(ddsdDisplayMode.ddpfPixelFormat.dwRGBAlphaBitMask)) {		dwAb = BitCount(ddsdDisplayMode.ddpfPixelFormat.dwRGBAlphaBitMask);		dwAs = BitShift(ddsdDisplayMode.ddpfPixelFormat.dwRGBAlphaBitMask);	} else {		dwAb = 0;		dwAs = 0;	}	// Query for available display modes	ddlogMessage(DDLOG_INFO, "\n");	ddlogMessage(DDLOG_INFO, "Display Modes:\n");	// Pass 1: Determine count	iEnumCount = 0;	hRes = IDirectDraw4_EnumDisplayModes(				lpDD4,				0,				NULL,				NULL,				EnumDisplayModesCallback);	if (FAILED(hRes)) {		ddlogError(DDLOG_ERROR, "dglBPFL: EnumDisplayModes failed", hRes);		goto clean_up;	}	if (iEnumCount == 0) {		ddlogMessage(DDLOG_ERROR, "dglBPFL: No display modes found");		goto clean_up;	}	glb.lpDisplayModes = (DDSURFACEDESC2 *)calloc(iEnumCount,												sizeof(DDSURFACEDESC2));	if (glb.lpDisplayModes == NULL) {		ddlogMessage(DDLOG_ERROR, "dglBPFL: DDSURFACEDESC2 calloc failed");		goto clean_up;	}	glb.nDisplayModeCount = iEnumCount;	// Pass 2: Save modes	iEnumCount = 0;	hRes = IDirectDraw4_EnumDisplayModes(				lpDD4,				0,				NULL,				(void *)glb.lpDisplayModes,				EnumDisplayModesCallback);	if (FAILED(hRes)) {		ddlogError(DDLOG_ERROR, "dglBPFL: EnumDisplayModes failed", hRes);		goto clean_up;	}							  // Query for IDirect3D3 interface	hRes = IDirectDraw4_QueryInterface(				lpDD4,				&IID_IDirect3D3,				(void**)&lpD3D3);	if (FAILED(hRes)) {		ddlogError(DDLOG_ERROR, "dglBPFL: QueryInterface (D3D3) failed", hRes);		goto clean_up;	}	ddlogMessage(DDLOG_INFO, "\n");	ddlogMessage(DDLOG_INFO, "ZBuffer formats:\n");	// Pass 1. Count the ZBuffer pixel formats	hRes = IDirect3D3_EnumZBufferFormats(				lpD3D3,				&glb.d3dGuid,				d3dEnumZBufferFormatsCallback,				NULL);	if (FAILED(hRes))		goto clean_up;	if (glb.nZBufferPFCount) {		glb.lpZBufferPF = (DDPIXELFORMAT *)calloc(glb.nZBufferPFCount,												sizeof(DDPIXELFORMAT));		if(glb.lpZBufferPF == NULL)			goto clean_up;		// Pass 2. Cache the ZBuffer pixel formats		iEnumCount = 0; // (Used by the enum function)		hRes = IDirect3D3_EnumZBufferFormats(					lpD3D3,					&glb.d3dGuid,					d3dEnumZBufferFormatsCallback,					glb.lpZBufferPF);		if (FAILED(hRes))			goto clean_up;	}	// Remove stencil support for boards which don't work for AutoCAD;	// Matrox G400 does not work, but NVidia TNT2 and ATI Rage128 do... (DaveM)	if (IsStencilSupportBroken(lpDD4)) {		for (i=0; i<iEnumCount; i++)			if (glb.lpZBufferPF[i].dwFlags & DDPF_STENCILBUFFER)				glb.nZBufferPFCount--;	}	// One each for every ZBuffer pixel format (including no depth buffer)	// Times-two because duplicated for single buffering (as opposed to double)	glb.nPixelFormatCount = 2 * (glb.nZBufferPFCount + 1);	glb.lpPF = (DGL_pixelFormat *)calloc(glb.nPixelFormatCount,										sizeof(DGL_pixelFormat));	if (glb.lpPF == NULL)		goto clean_up;	//	// Fill in the pixel formats	// Note: Depth buffer bits are really (dwZBufferBitDepth-dwStencilBitDepth)	//		 but this will pass wierd numbers to the OpenGL app. (?)	//	pfTemplateHW.pfd.iPixelType		= dwPixelType;	pfTemplateHW.pfd.cColorBits		= dwDisplayBitDepth;	pfTemplateHW.pfd.cRedBits		= dwRb;	pfTemplateHW.pfd.cGreenBits		= dwGb;	pfTemplateHW.pfd.cBlueBits		= dwBb;	pfTemplateHW.pfd.cAlphaBits		= dwAb;	pfTemplateHW.pfd.cRedShift		= dwRs;	pfTemplateHW.pfd.cGreenShift	= dwGs;	pfTemplateHW.pfd.cBlueShift		= dwBs;	pfTemplateHW.pfd.cAlphaShift	= dwAs;	lpPF = glb.lpPF;	// Fill in the double-buffered pixel formats	for (i=0; i<(glb.nZBufferPFCount + 1); i++, lpPF++) {		memcpy(lpPF, &pfTemplateHW, sizeof(DGL_pixelFormat));		if (i) {			lpPF->iZBufferPF		= i-1;			lpPF->pfd.cDepthBits	= glb.lpZBufferPF[i-1].dwZBufferBitDepth;			lpPF->pfd.cStencilBits	= glb.lpZBufferPF[i-1].dwStencilBitDepth;		}	}	// Fill in the single-buffered pixel formats	for (i=0; i<(glb.nZBufferPFCount + 1); i++, lpPF++) {		memcpy(lpPF, &pfTemplateHW, sizeof(DGL_pixelFormat));		if (i) {			lpPF->iZBufferPF		= i-1;			lpPF->pfd.cDepthBits	= glb.lpZBufferPF[i-1].dwZBufferBitDepth;			lpPF->pfd.cStencilBits	= glb.lpZBufferPF[i-1].dwStencilBitDepth;		}		// Remove double-buffer flag. Could use XOR instead...		lpPF->pfd.dwFlags &= (~(PFD_DOUBLEBUFFER));		// Insert GDI flag for single buffered format only.		lpPF->pfd.dwFlags |= PFD_SUPPORT_GDI;	}#endif // _USE_GLD3_WGL	// Lets dump the list to the log	// ** Based on "wglinfo" by Nate Robins **	ddlogMessage(DDLOG_INFO, "\n");	ddlogMessage(DDLOG_INFO, "Pixel Formats:\n");	ddlogMessage(DDLOG_INFO,		"   visual  x  bf lv rg d st  r  g  b a  ax dp st accum buffs  ms\n");	ddlogMessage(DDLOG_INFO,		" id dep cl sp sz l  ci b ro sz sz sz sz bf th cl  r  g  b  a ns b\n");	ddlogMessage(DDLOG_INFO,		"-----------------------------------------------------------------\n");	for (i=0, lpPF = glb.lpPF; i<glb.nPixelFormatCount; i++, lpPF++) {		sprintf(buf, "0x%02x ", i+1);		sprintf(cat, "%2d ", lpPF->pfd.cColorBits);		strcat(buf, cat);		if(lpPF->pfd.dwFlags & PFD_DRAW_TO_WINDOW)      sprintf(cat, "wn ");		else if(lpPF->pfd.dwFlags & PFD_DRAW_TO_BITMAP) sprintf(cat, "bm ");		else sprintf(cat, ".  ");		strcat(buf, cat);		/* should find transparent pixel from LAYERPLANEDESCRIPTOR */		sprintf(cat, " . "); 		strcat(buf, cat);		sprintf(cat, "%2d ", lpPF->pfd.cColorBits);		strcat(buf, cat);		/* bReserved field indicates number of over/underlays */		if(lpPF->pfd.bReserved) sprintf(cat, " %d ", lpPF->pfd.bReserved);		else sprintf(cat, " . "); 		strcat(buf, cat);		sprintf(cat, " %c ", lpPF->pfd.iPixelType == PFD_TYPE_RGBA ? 'r' : 'c');		strcat(buf, cat);		sprintf(cat, "%c ", lpPF->pfd.dwFlags & PFD_DOUBLEBUFFER ? 'y' : '.');		strcat(buf, cat);		sprintf(cat, " %c ", lpPF->pfd.dwFlags & PFD_STEREO ? 'y' : '.');		strcat(buf, cat);		if(lpPF->pfd.cRedBits && lpPF->pfd.iPixelType == PFD_TYPE_RGBA) 		    sprintf(cat, "%2d ", lpPF->pfd.cRedBits);		else sprintf(cat, " . ");		strcat(buf, cat);		if(lpPF->pfd.cGreenBits && lpPF->pfd.iPixelType == PFD_TYPE_RGBA) 		    sprintf(cat, "%2d ", lpPF->pfd.cGreenBits);		else sprintf(cat, " . ");		strcat(buf, cat);		if(lpPF->pfd.cBlueBits && lpPF->pfd.iPixelType == PFD_TYPE_RGBA) 		    sprintf(cat, "%2d ", lpPF->pfd.cBlueBits);		else sprintf(cat, " . ");		strcat(buf, cat);			if(lpPF->pfd.cAlphaBits && lpPF->pfd.iPixelType == PFD_TYPE_RGBA) 			sprintf(cat, "%2d ", lpPF->pfd.cAlphaBits);		else sprintf(cat, " . ");		strcat(buf, cat);			if(lpPF->pfd.cAuxBuffers)     sprintf(cat, "%2d ", lpPF->pfd.cAuxBuffers);		else sprintf(cat, " . ");		strcat(buf, cat);			if(lpPF->pfd.cDepthBits)      sprintf(cat, "%2d ", lpPF->pfd.cDepthBits);		else sprintf(cat, " . ");		strcat(buf, cat);			if(lpPF->pfd.cStencilBits)    sprintf(cat, "%2d ", lpPF->pfd.cStencilBits);		else sprintf(cat, " . ");		strcat(buf, cat);			if(lpPF->pfd.cAccumRedBits)   sprintf(cat, "%2d ", lpPF->pfd.cAccumRedBits);		else sprintf(cat, " . ");		strcat(buf, cat);		if(lpPF->pfd.cAccumGreenBits) sprintf(cat, "%2d ", lpPF->pfd.cAccumGreenBits);		else sprintf(cat, " . ");		strcat(buf, cat);			if(lpPF->pfd.cAccumBlueBits)  sprintf(cat, "%2d ", lpPF->pfd.cAccumBlueBits);		else sprintf(cat, " . ");		strcat(buf, cat);			if(lpPF->pfd.cAccumAlphaBits) sprintf(cat, "%2d ", lpPF->pfd.cAccumAlphaBits);		else sprintf(cat, " . ");		strcat(buf, cat);			/* no multisample in Win32 */		sprintf(cat, " . .\n");		strcat(buf, cat);		ddlogMessage(DDLOG_INFO, buf);	}	ddlogMessage(DDLOG_INFO,		"-----------------------------------------------------------------\n");	ddlogMessage(DDLOG_INFO, "\n");#ifndef _USE_GLD3_WGLclean_up:	// Release COM objects	RELEASE(lpD3D3);	RELEASE(lpDD4);	RELEASE(lpDD1);	// Popup warning message if non RGB color mode	if (dwDisplayBitDepth <= 8) {		ddlogPrintf(DDLOG_WARN, "Current Color Depth %d bpp is not supported", dwDisplayBitDepth);		MessageBox(NULL, szColorDepthWarning, "GLDirect", MB_OK | MB_ICONWARNING);	}#endif // _USE_GLD3_WGL}// ***********************************************************************void dglReleasePixelFormatList(){	glb.nPixelFormatCount = 0;	if (glb.lpPF) {		free(glb.lpPF);		glb.lpPF = NULL;	}#ifndef _USE_GLD3_WGL	glb.nZBufferPFCount = 0;	if (glb.lpZBufferPF) {		free(glb.lpZBufferPF);		glb.lpZBufferPF = NULL;	}	glb.nDisplayModeCount = 0;	if (glb.lpDisplayModes) {		free(glb.lpDisplayModes);		glb.lpDisplayModes = NULL;	}#endif // _USE_GLD3_WGL}// ***********************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -