glewInit function throws error code 0x0000007F (C++)

0

First, I created an old OpenGL context to load OpenGL extensions. After that, I tried to create a new OpenGL context, but function 'wglCreateContextAttribsARB' threw error code 0xC007000D. So I locked where the error was and I saw glewInit is the function which throws the error code 0x0000007F, but glewInit returns GLEW_OK, which means that there was any error in glewInit...

PIXELFORMATDESCRIPTOR *PixelFormat = new PIXELFORMATDESCRIPTOR[1];
    HWND *hFakeWnd = new HWND[1];
    int ChoosenPixelFormat = 0;
    UINT NumFormats = 0;

    *hFakeWnd = CreateWindowEx(0, cWindow.lpszClassName, L"Fake", 0, 0, 0, 1, 1, HWND_DESKTOP, NULL, GetModuleHandle(NULL), NULL);

    ZeroMemory(PixelFormat, sizeof(PIXELFORMATDESCRIPTOR));
    PixelFormat->nSize = sizeof(PIXELFORMATDESCRIPTOR);
    PixelFormat->nVersion = 1;
    PixelFormat->iPixelType = PFD_TYPE_RGBA;
    PixelFormat->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    PixelFormat->cColorBits = 32;
    PixelFormat->cDepthBits = 24;
    PixelFormat->cStencilBits = 8;
    PixelFormat->iLayerType = PFD_MAIN_PLANE;

    hDC = GetDC(*hFakeWnd);

    if(hDC == NULL) {
        PostErrorMessage(hWnd, "Error getting a device context from a window!");
        return false;
    }

    ChoosenPixelFormat = ChoosePixelFormat(hDC, PixelFormat);

    if(!ChoosenPixelFormat) {
        PostErrorMessage(hWnd, "Error choosing a valid pixel format (old)!");
        return false;
    }

    if(!SetPixelFormat(hDC, ChoosenPixelFormat, PixelFormat)) {
        PostErrorMessage(hWnd, "Error setting a pixel format (old)!");
        return false;
    }

    hRC = wglCreateContext(hDC);

    if(!hRC) {
        PostErrorMessage(hWnd, "Error creating an old OpenGL context!");
        return false;
    }

    wglMakeCurrent(hDC, hRC);

    //MessageBoxA(hWnd, (char *)glGetString(GL_VERSION), "Version", MB_OK | MB_ICONERROR);
    glewExperimental = true;

    if(glewInit() != GLEW_OK) {
        PostErrorMessage(hWnd, "Error linking OpenGL functions!");
        return false;
    }

    destroyOpenGLContext(*hFakeWnd, hDC, hRC);

    hDC = GetDC(hWnd);

    if(hDC == NULL) {
        PostErrorMessage(hWnd, "Error getting a device context from a window!");
        return false;
    }

    const int *AttribList = new int[] {
        WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
        WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
        WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
        WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
        WGL_COLOR_BITS_ARB, 32,
        WGL_DEPTH_BITS_ARB, 24,
        WGL_STENCIL_BITS_ARB, 8,
        0
    };

    if(!wglChoosePixelFormatARB(hDC, AttribList, NULL, 1, &ChoosenPixelFormat, &NumFormats)) {
        PostErrorMessage(hWnd, "Error choosing a valid pixel format (new)!");
        return false;
    }

    const int *ContextAttribList = new int[] {
        WGL_CONTEXT_MAJOR_VERSION_ARB, 4, 
        WGL_CONTEXT_MINOR_VERSION_ARB, 5, 
        0
    };

    hRC = wglCreateContextAttribsARB(hDC, NULL, ContextAttribList);

    char error[9];
    int nError = GetLastError();
    _itoa_s(nError, error, (size_t)9, 16);
    PostErrorMessage(hWnd, error);

    if(!hRC) {
        PostErrorMessage(hWnd, "Error creating an OpenGL context (new)!");
        return false;
    }

    wglMakeCurrent(hDC, hRC);

    delete[] AttribList;
    delete[] ContextAttribList;
    delete[] PixelFormat;
    delete[] hFakeWnd;

    return true;
c++
opengl
glew
asked on Stack Overflow Jun 18, 2015 by Seyro97 • edited Jun 18, 2015 by Seyro97

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0