Skip to content

wglGetProcAddress in wgl.c introduces a dependency on OpenGL32.lib #534

Description

@bellenot

Hello,

When generating wgl.c, there is this part of the code:

static GLADapiproc glad_wgl_get_proc(void *vuserptr, const char* name) {
    GLAD_UNUSED(vuserptr);
    return GLAD_GNUC_EXTENSION (GLADapiproc) wglGetProcAddress(name);
}

Where using wglGetProcAddress introduces a direct dependency on OpenGL32.lib (i.e. one needs to links against it)
I think something similar to the following code should be generated:

typedef void* (GLAD_API_PTR *GLADwglprocaddrfunc)(const char*);

static GLADapiproc glad_wgl_get_proc(void *vuserptr, const char* name) {
    GLAD_UNUSED(vuserptr);
    GLADapiproc result = NULL;
    void *handle = (void*) LoadLibraryA("opengl32.dll");
    GLADwglprocaddrfunc wgl_get_proc_address_ptr = (GLADwglprocaddrfunc) GetProcAddress((HMODULE) handle, "wglGetProcAddress");
    if (wgl_get_proc_address_ptr != NULL)
        result = GLAD_GNUC_EXTENSION (GLADapiproc) wgl_get_proc_address_ptr(name);
    return result;
}

I tested it and it works just fine.
Then we (the ROOT project at CERN) can get rid of a special case for Windows where we have to link against OpenGL32.lib only because of that function call.
Thanks in advance!

Cheers, Bertrand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions