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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
bool Graphic::setupGL(char *t,int bw,int bh,int w,int h,int bpp)
{
title = t;
width = w;
height = h;
beginW=bw;
beginH=bh;
bits = bpp;
HINSTANCE hInstance = GetModuleHandle(NULL);
WNDCLASSEX wc;
unsigned int pixelFormat;
DWORD style;
wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "CNSmesher";
if (!RegisterClassEx(&wc))
{
displayMsgBox("Registering error",true);
return false;
}
style = WS_OVERLAPPEDWINDOW;
RECT rect;
rect.left = 0; rect.top = 0;
rect.right = width; rect.bottom = height;
AdjustWindowRectEx(&rect, style, FALSE, 0);
if (!(hwnd = CreateWindowEx(
WS_EX_APPWINDOW,
"CNSmesher",
title,
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | style,
beginW,beginH,
rect.right - rect.left,
rect.bottom - rect.top,
NULL,
NULL,
hInstance,
NULL)))
{
killGL();
displayMsgBox("Create window error",true);
return false;
}
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(pfd),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
bits,
0, 0, 0, 0, 0, 0, // Color bits
0, 0, // Alpha bits
0, 0, 0, 0, 0, // Accumulation bits
16, // Depth buffer
0, // Stencil buffer
0, // Auxillary buffer
PFD_MAIN_PLANE,
0, // reserved
0, 0, 0 // Layer masks
};
if (!(hdc = GetDC(hwnd)))
{
killGL();
displayMsgBox("Get DC error",true);
return false;
}
if(!(pixelFormat = ChoosePixelFormat(hdc, &pfd)))
{
killGL();
displayMsgBox("Chosing pixel format error",true);
return false;
}
if (!SetPixelFormat(hdc, pixelFormat, &pfd))
{
killGL();
displayMsgBox("Setting pixel format error",true);
return false;
}
if (!(hrc = wglCreateContext(hdc)))
{
killGL();
displayMsgBox("Creating context error",true);
return false;
}
if (!wglMakeCurrent(hdc, hrc))
{
killGL();
displayMsgBox("Making current rendering error",true);
return false;
}
ShowWindow(hwnd, SW_SHOW);
SetForegroundWindow(hwnd);
SetFocus(hwnd);
resize(width, height);
return initSpace();
} |
Partager