0

I want to use OpenGL without GLFW, the docs say that I need to add opengl32.lib to linker dependencies.

How do I specifically import OpenGL and use it, where is opengl32.lib and how do I add it to my CMakeLists.txt or link in Visual Studio's properties?

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • It depends on the version of OpenGL you want to use. For any recent feature, you have to dynamically load OpenGL at runtime. `opengl32.lib` is useless for any OpenGL >=2 feature – SpacePotatoes May 13 '22 at 08:09
  • 1
    @SpacePotatoes You can use all of opengl with just *opengl32.lib*. That dynamic loading is done with `wglGetProcAddress` which comes from *opengl32.lib*. – vandench May 13 '22 at 13:40
  • @van dench indeed you're right. I've forgotten this point, since I was using `glad` which dynamically loads `opengl32`. – SpacePotatoes May 13 '22 at 15:28
  • @SpacePotatoes I have linked the directory but it acts a bit weird, it gives me the defines but gives an error on everything else, also includes just fine. i have followed dench 's comment but that answer states that i must also link to the header files and put dll files on my dir if needed but i don't know where the header files and the dll's are, i just put opengl32.lib into my linker->Additional Dependencies. Also i couln'd find wglGetProcAddress but thats not that important since everything i need is in gl.h –  May 13 '22 at 15:50
  • @user19068953 Whether you have included the header file `windows.h`? The Windows functions that support Microsoft's implementation of OpenGL in Windows must include the header file Windows.h. – Jeaninez - MSFT May 16 '22 at 01:47
  • Upon closer inspection, ~these are loafers~ this is not actually a great duplicate... – user253751 May 16 '22 at 15:36

1 Answers1

2

You can use the find-module shipped with cmake using find_package(OpenGL). When OpenGL is found, you can use the target OpenGL::GL to link your executable against opengl32.lib. See the official doc for more targets.

find_package(OpenGL REQUIRED)
add_executable(myApp main.cpp)
target_link_libraries(myApp OpenGL::GL)
local-ninja
  • 1,198
  • 4
  • 11