2012-11-29 158 views
2

我正在C++上編寫一些OpenGL 3程序,現在我的筆記本電腦Lenovo Thinkpad e320(Intel HD Graphics 3000)出現問題。它可以在我的電腦上正常工作(ATI Radeon HD 5870)。錯誤附近OpenGL創建渲染上下文失敗

守則如下:

bool GLWindowCreate(const char *title, int width, int height, bool fullScreen){ 
... 
    g_hRC = wglCreateContextAttribsARB(g_hDC, 0, attribs); 
    if (!g_hRC || !wglMakeCurrent(g_hDC, g_hRC)) 
    { 
     LOG_ERROR("Creating render context fail (%d)\n", GetLastError()); 
     return false; 
    } 
... 
} 

所有編譯罰款,我看到在日誌文件中此錯誤。

我使用Windows 8(PC和筆記本電腦)。對筆記本電腦的顯卡支持OpenGL 3.我發現有關我需要關閉硬件加速同樣的問題,一些答案,但似乎沒有辦法在Win做到這一點8.

補充:

整個窗口創建功能:

bool GLWindowCreate(const char *title, int width, int height, bool fullScreen) 
{ 
    ASSERT(title); 
    ASSERT(width > 0); 
    ASSERT(height > 0); 

    WNDCLASSEX   wcx; 
    PIXELFORMATDESCRIPTOR pfd; 
    RECT     rect; 
    HGLRC     hRCTemp; 
    DWORD     style, exStyle; 
    int     x, y, format; 

    memset(&g_window, 0, sizeof(g_window)); 

    memset(&g_input, 0, sizeof(g_input)); 

    PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL; 

    // attributes for OpenGL context 
    int attribs[] = 
    { 
     WGL_CONTEXT_MAJOR_VERSION_ARB, 3, 
     WGL_CONTEXT_MINOR_VERSION_ARB, 3, 
     WGL_CONTEXT_FLAGS_ARB,   WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, 
     WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, 
     0 
    }; 

    // timer init 
    QueryPerformanceFrequency(&g_qpc); 
    ASSERT(g_qpc.QuadPart > 0); 

    g_timerFrequency = 1.0/g_qpc.QuadPart; 

    g_hInstance = (HINSTANCE)GetModuleHandle(NULL); 

    memset(&wcx, 0, sizeof(wcx)); 
    wcx.cbSize  = sizeof(wcx); 
    wcx.style   = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; 
    wcx.lpfnWndProc = (WNDPROC)GLWindowProc; 
    wcx.hInstance  = g_hInstance; 
    wcx.lpszClassName = GLWINDOW_CLASS_NAME; 
    wcx.hIcon   = LoadIcon(NULL, IDI_APPLICATION); 
    wcx.hCursor  = LoadCursor(NULL, IDC_ARROW); 

    if (!RegisterClassEx(&wcx)) 
    { 
     LOG_ERROR("RegisterClassEx fail (%d)\n", GetLastError()); 
     return false; 
    } 

    style = WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; 
    exStyle = WS_EX_APPWINDOW; 

    x = (GetSystemMetrics(SM_CXSCREEN) - width)/2; 
    y = (GetSystemMetrics(SM_CYSCREEN) - height)/2; 

    rect.left = x; 
    rect.right = x + width; 
    rect.top = y; 
    rect.bottom = y + height; 

    AdjustWindowRectEx (&rect, style, FALSE, exStyle); 

    // creating window 
    g_hWnd = CreateWindowEx(exStyle, GLWINDOW_CLASS_NAME, title, style, rect.left, rect.top, 
     rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, g_hInstance, NULL); 

    if (!g_hWnd) 
    { 
     LOG_ERROR("CreateWindowEx fail (%d)\n", GetLastError()); 
     return false; 
    } 

     // get window descriptor 
    g_hDC = GetDC(g_hWnd); 

    if (!g_hDC) 
    { 
     LOG_ERROR("GetDC fail (%d)\n", GetLastError()); 
     return false; 
    } 

    memset(&pfd, 0, sizeof(pfd)); 
    pfd.nSize  = sizeof(pfd); 
    pfd.nVersion = 1; 
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; 
    pfd.iPixelType = PFD_TYPE_RGBA; 
    pfd.cColorBits = 32; 
    pfd.cDepthBits = 24; 

    // get pixel format 
    format = ChoosePixelFormat(g_hDC, &pfd); 
    if (!format || !SetPixelFormat(g_hDC, format, &pfd)) 
    { 
     LOG_ERROR("Setting pixel format fail (%d)\n", GetLastError()); 
     return false; 
    } 

    // creating temp context 
    // to get wglCreateContextAttribsARB function 
    hRCTemp = wglCreateContext(g_hDC); 
    if (!hRCTemp || !wglMakeCurrent(g_hDC, hRCTemp)) 
    { 
     LOG_ERROR("Сreating temp render context fail (%d)\n", GetLastError()); 
     return false; 
    } 

    OPENGL_GET_PROC(PFNWGLCREATECONTEXTATTRIBSARBPROC, wglCreateContextAttribsARB); 

    // delete temp context 
    wglMakeCurrent(NULL, NULL); 
    wglDeleteContext(hRCTemp); 

    // creating OpenGL 3 context 
    g_hRC = wglCreateContextAttribsARB(g_hDC, 0, attribs); 
    if (!g_hRC || !wglMakeCurrent(g_hDC, g_hRC)) 
    { 
     LOG_ERROR("Creating render context fail (%d)\n", GetLastError()); 
     return false; 
    } 

    int major, minor; 
    glGetIntegerv(GL_MAJOR_VERSION, &major); 
    glGetIntegerv(GL_MINOR_VERSION, &minor); 
    LOG_DEBUG("OpenGL render context information:\n" 
     " Renderer  : %s\n" 
     " Vendor   : %s\n" 
     " Version  : %s\n" 
     " GLSL version : %s\n" 
     " OpenGL version : %d.%d\n", 
     (const char*)glGetString(GL_RENDERER), 
     (const char*)glGetString(GL_VENDOR), 
     (const char*)glGetString(GL_VERSION), 
     (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION), 
     major, minor 
    ); 

    if (!OpenGLInitExtensions()) 
     return false; 

    GLWindowSetSize(width, height, fullScreen); 

    return true; 
} 
+2

我們需要查看更多的上下文創建代碼,以瞭解發生了什麼。 –

+0

「聯想** Thikpad **」? – genpfault

+1

更正了:) – Anatoly

回答

1

我意外地發現了一個決定。問題是有:

int attribs[] = 
    { 
     WGL_CONTEXT_MAJOR_VERSION_ARB, 3, 
     WGL_CONTEXT_MINOR_VERSION_ARB, 3, 
     WGL_CONTEXT_FLAGS_ARB,   WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, 
     WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, 
     0 
    }; 

英特爾高清顯卡3000僅支持的OpenGL 3.1,而不是3.3的,所以我不得不改變

WGL_CONTEXT_MINOR_VERSION_ARB, 3, 

WGL_CONTEXT_MINOR_VERSION_ARB, 1, 

謝謝大家和擔心難過,希望我的問題解決方案能夠幫助別人