blob: dc4fae15077f0ad3b7c6fda798e343eea776a89d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/************************************************************************
Support code for handling various tasks under Win32
$Id: wintools.cxx 427 2004-09-27 04:45:31Z garland $
************************************************************************/
#include <gfx/win/wintools.h>
namespace gfx
{
HGLRC create_glcontext(HDC dc)
{
HGLRC context = wglCreateContext(dc);
if( context )
{
if( !wglMakeCurrent(dc, context) )
{
// Destroy context if it fails to bind
wglDeleteContext(context);
context = NULL;
}
}
return context;
}
int set_pixel_format(HDC dc)
{
PIXELFORMATDESCRIPTOR pixelDesc;
//
// These are the important fields of the PFD
//
pixelDesc.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pixelDesc.nVersion = 1;
pixelDesc.dwFlags =
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER | PFD_STEREO_DONTCARE;
pixelDesc.iPixelType = PFD_TYPE_RGBA;
pixelDesc.cColorBits = 24;
pixelDesc.iLayerType = PFD_MAIN_PLANE;
//
// According to the docs, these can be/are ignored.
//
pixelDesc.cRedBits = 8;
pixelDesc.cRedShift = 16;
pixelDesc.cGreenBits = 8;
pixelDesc.cGreenShift = 8;
pixelDesc.cBlueBits = 8;
pixelDesc.cBlueShift = 0;
pixelDesc.cAlphaBits = 0;
pixelDesc.cAlphaShift = 0;
pixelDesc.cAccumBits = 0;
pixelDesc.cAccumRedBits = 0;
pixelDesc.cAccumGreenBits = 0;
pixelDesc.cAccumBlueBits = 0;
pixelDesc.cAccumAlphaBits = 0;
pixelDesc.cDepthBits = 32;
pixelDesc.cStencilBits = 0;
pixelDesc.cAuxBuffers = 0;
pixelDesc.bReserved = 0;
pixelDesc.dwLayerMask = 0;
pixelDesc.dwVisibleMask = 0;
pixelDesc.dwDamageMask = 0;
int pixel_format = ChoosePixelFormat(dc, &pixelDesc);
if( !pixel_format )
{
// Try and guess a decent default pixel format
pixel_format = 1;
if( !DescribePixelFormat(dc, pixel_format,
sizeof(PIXELFORMATDESCRIPTOR), &pixelDesc) )
return NULL;
}
if( !SetPixelFormat(dc, pixel_format, &pixelDesc) )
return NULL;
return pixel_format;
}
} // namespace gfx
|