Hi,
I am running the same code in different system, it works on window 7 os on the contrary it fails on win10 os. While I debug the code and find that the code step to wglMakeCurrent, no exceptions thrown, no vaule returned, it seems jump out of code.
Can anyone help? Thanks a lot.
BOOL CData::initOpenCL()
{
if (!m_pWnd)
{
m_pWnd = new CMessageWnd();
}
return m_clRender->initOpenGL(m_pWnd->GetDC());
}
BOOL NRender::initOpenGL(HDC hdc)
{
m_hDC = hdc;
if (!_setupPixelFormat(m_hDC))
return FALSE;
m_hRC = ::wglCreateContext(m_hDC);
if (m_hRC == NULL)
return FALSE;
if (!wglMakeCurrent(m_hDC, m_hRC))
return FALSE;
GLenum err = glewInit();
if (err != GLEW_OK)
return FALSE;
return TRUE;
}
BOOL NRender::_setupPixelFormat(HDC hdc)
{
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_GENERIC_FORMAT |
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer
8, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
int pixelformat;
if ((pixelformat = ChoosePixelFormat(hdc, &pfd)) == 0)
{
return FALSE;
}
if (SetPixelFormat(hdc, pixelformat, &pfd) == FALSE)
{
return FALSE;
}
return TRUE;
}
The following is CMessageWnd class implement:
CMessageWnd::CMessageWnd(void)
{
m_hInstance = GetModuleHandle(NULL);
MyRegisterClass(m_hInstance);
m_hwnd = InitInstance(m_hInstance, SW_HIDE);
if (m_hwnd)
m_hdc = ::GetDC(m_hwnd);
}
CMessageWnd::~CMessageWnd(void)
{
if (m_hdc && m_hwnd)
{
::ReleaseDC(m_hwnd, m_hdc);
}
}
BOOL MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wcex.lpfnWndProc = (WNDPROC) WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = NULL;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = NULL;
if (!RegisterClassEx(&wcex))
{
std::cout << "Failed To Register The Window Class." << std::endl;
return FALSE;
}
return TRUE;
}
HWND InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd=0;
DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
DWORD dwStyle = WS_OVERLAPPEDWINDOW; // Windows Style
//hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
// CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values
WindowRect.left = (long)0; // Set Left Value To 0
WindowRect.right = (long)50; // Set Right Value To Requested Width
WindowRect.top = (long)0; // Set Top Value To 0
WindowRect.bottom = (long)50; // Set Bottom Value To Requested Height
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size
if (!(hWnd = CreateWindowEx(dwExStyle, // Extended Style For The Window
szWindowClass, // Class Name
szTitle, // Window Title
dwStyle | // Defined Window Style
WS_CLIPSIBLINGS | // Required Window Style
WS_CLIPCHILDREN, // Required Window Style
0, 0, // Window Position
WindowRect.right - WindowRect.left, // Calculate Window Width
WindowRect.bottom - WindowRect.top, // Calculate Window Height
NULL, // No Parent Window
NULL, // No Menu
hInstance, // Instance
NULL))) // Dont Pass Anything To WM_CREATE
{
std::cout << "Window Creation Error!" << std::endl;
return hWnd;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return hWnd;
}