示例#1
0
文件: win32.go 项目: sixteng/goGLPro
func (window *Win32Window) GetHDC() unsafe.Pointer {
	if window.hdc != nil {
		return unsafe.Pointer(&window.hdc)
	}

	window.hdc = C.GetDC(window.hwnd)

	px := C.PIXELFORMATDESCRIPTOR{
		dwFlags:    0x00000001 | 0x00000020 | 0x00000004,
		iPixelType: 0,
		cColorBits: 32,
		cDepthBits: 32,
		iLayerType: 0,
	}

	px.nSize = (C.WORD)(unsafe.Sizeof(px))

	pxFormat := C.ChoosePX(window.hdc, &px)
	if pxFormat == 0 {
		return nil
	}

	res := C.SetPixelFormat(window.hdc, pxFormat, &px)
	if res == 0 {
		return nil
	}

	return unsafe.Pointer(&window.hdc)
}
示例#2
0
// Find a pixel format with no antialiasing, if not needed or not supported
func BestChoosePixelFormat(hdc C.HDC, bitsPerPixel uint, settings *ContextSettings) C.int {
	// Setup a pixel format descriptor from the rendering settings
	descriptor := C.PIXELFORMATDESCRIPTOR{
		nSize:        C.PIXELFORMATDESCRIPTOR_size,
		nVersion:     1,
		iLayerType:   C.PFD_MAIN_PLANE,
		dwFlags:      C.PFD_DRAW_TO_WINDOW | C.PFD_SUPPORT_OPENGL | C.PFD_DOUBLEBUFFER,
		iPixelType:   C.PFD_TYPE_RGBA,
		cColorBits:   C.BYTE(bitsPerPixel),
		cDepthBits:   C.BYTE(settings.DepthBits),
		cStencilBits: C.BYTE(settings.StencilBits),
	}
	if bitsPerPixel == 32 {
		descriptor.cAlphaBits = 8
	}

	// Get the pixel format that best matches our requirements
	return C.ChoosePixelFormat(hdc, &descriptor)
}