-1

I'm loading OpenGL with Glad (in combo with GLFW), and calling native functions by loading them in with LoadLibrary/GetProcAddress and casting to a function pointer in C#. Here is an example:

nint glad = LoadLibrary("glad.dll");

... // code to setup glad, using gladLoadGLLoader with GLFW's glfwGetProcAddress

delegate* unmanaged[Cdecl]<int, void> glClear = 
    (delegate* unmanaged[Cdecl]<int, void>)GetProcAddress(glad, "glad_glClear");

glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // read access violation

I can use this method to call GLFW functions and Glad functions successfully, but when I try to call, for example glClear, C# throws a read access violation. I think this is because Glad/GLFW loaded opengl32.dll, and it was not directly through the C# application, so how do I work around this and still call GL functions through Glad?

bquack-l
  • 59
  • 4

0 Answers0