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
|
Context(const std::string name, std::string rName, unsigned int rW, unsigned int rH, void* param, void* param2 = nullptr)
{
for(unsigned int i = 0; i < 512; i++)
keys.push_back(false);
memset(&keys[0], 0, 512);
data1 = nullptr;
data2 = nullptr;
data3 = nullptr;
data4 = nullptr;
resWidth = rW;
resHeight = rH;
#if(_WIN32)
pf = 0;
WNDCLASSEX wcex;
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, //Flags
PFD_TYPE_RGBA, //The kind of framebuffer. RGBA or palette.
32, //Colordepth of the framebuffer.
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
32, //Number of bits for the depthbuffer
8, //Number of bits for the stencilbuffer
0, //Number of Aux buffers in the framebuffer.
PFD_MAIN_PLANE,
0,
0, 0, 0
};
// param is the hInstance
// param2 is not used.
data4 = param;
memset(&wcex, 0, sizeof(WNDCLASSEX));
HWND hWnd = nullptr;
HDC hDC = nullptr;
HGLRC hRC = nullptr;
//std::wstring wclassName(rName.begin(), rName.end());
wchar_t* wclassName = new wchar_t[rName.size()];
for(unsigned int i = 0; i < rName.size(); i++)
wclassName[i] = rName[i];
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); // Load The Default Icon
wcex.hIcon = LoadIcon (nullptr, IDI_WINLOGO);
wcex.hIconSm = nullptr;
wcex.hInstance = (HINSTANCE)data4;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.lpszClassName = wclassName;
wcex.lpszMenuName = nullptr;
wcex.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC;
//Register Window Class
DWORD e = GetLastError();
if(!RegisterClassEx(&wcex)) {throw CF::Error("CF::Video::Context::Context() - Failure registering window class.");}
//Create Windows
hWnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,
wcex.lpszClassName,
std::wstring(name.begin(), name.end()).c_str(),
WS_BORDER,
CW_USEDEFAULT,
CW_USEDEFAULT,
resWidth,
resHeight,
nullptr,
nullptr,
wcex.hInstance,
nullptr);
if(!hWnd) {throw CF::Error("CF::Video::Context::Context() - Failure creating window.");}
store::data = this;
hDC = GetDC(hWnd);
pf = ChoosePixelFormat(hDC, &pfd);
if(pf == 0) {throw CF::Error("CF::Video::Context::Context() - Could not find pixel format.");}
SetPixelFormat(hDC, pf, &pfd);
// Get a context
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
// Set the data pointers to the appropriate value
data1 = hRC;
data2 = hDC;
data3 = hWnd;
data4 = param;
//Show Window and Update Window
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
delete[] wclassName;
#endif
}
|