Hey. I am creating an OpenGL context in a DLL, but I cannot figure out how to also use the OpenGL functions in my .exe program that load this DLL.
Ensure that the context is current before calling any OpenGL functions. The DLL may need to export functions that the application can use to do this. Also: if you’re using GLEW to access functions which aren’t part of OpenGL 1.1, you should probably link it as a DLL; otherwise the library and application will end up with separate copies of the function pointers and both copies will need to be initialised.
When I use the OpenGL function in the DLL everything works well. but when I try to use opengl func in .exe , it cannot find the opengl function. I have to export every OpenGL function, what do I need from a DLL?
Yes. i use GLFW/OpenGL/glad
I haven’t used GLAD myself, but looking at the generated glad.h file I suspect that you need to define
GLAD_GLAPI_EXPORT_BUILD before including glad.h in the DLL and define
GLAD_GLAPI_EXPORT before including glad.h in the application. This should cause the symbols to be declared with the
dllexport attribute in the DLL and the
dllimport attribute in the EXE.