Why do I need to link against opengl32 when I have glew32? - c++

Why do I need both the libopengl32.dll and the libglew32 libraries when compiling an OpenGL program? What's the difference between the libraries and why do I need both?

You do not (always) need both the libopengl32.dll and the libglew32 libraries when compiling an OpenGL program. You need both when compiling a GLEW program (which implies also being an OpenGL program since GLEW builds upon OpenGL). For some people, this difference is academic since they would never consider writing an OpenGL program without the convenience of GLEW (et al.). However, GLEW is not required by OpenGL.
Your OpenGL library is the base upon which your GLEW library depends. You can use OpenGL without GLEW, but you cannot use GLEW without OpenGL. If your program uses GLEW, then you need to link your GLEW library because you are using it, and you need to link your OpenGL library because GLEW (and probably your code as well) uses that. If you are using pure OpenGL with no elements of GLEW, you need just to link your OpenGL library.

Related

Why doesn't SFML require OpenGL libraries?

I know that SFML is a 2D OpenGL library, but why does programs using SFML not require opengl32.dll or glew.dll?
I created library.lib and library.dll, which use external functions from GLEW and FreeGLUT. Then, I created test_library.exe and linked my library to this program.
After compiling (successfully) I realized that this program requires some DLLs from my library.
How do I use external symbols from missing DLLs just like SFML?

OpenGL functions missing in SFML environment

Following this tutorial I was trying to manage my OpenGL buffers for an OpenGL context I created using SFML, under a visual studio environment. I installed SFML and Glew in their latest versions, did correct linking, and I am able to work with primitives like OpenGL glClear, glBegin and glVertext3d.
However there is plenty of other OpenGL functions that I can t seem to be able to call like glEnableVertexAttribArray or glBindBuffer and I would like to understand why. I noticed that the default OpenGL version set by SFML context is 4.6 but I can t find proper documentation for these functions on khronos website for this version. Moreover my visual studio doesn t even recognize theses functions as part of any library but I might have missed some includes given that I rely on SFML/OpenGL.hpp. Documentation on SFML side is very ligth on this subject...
Thanks !
I am able to work with primitives like OpenGL glClear, glBegin and glVertext3d. However there is plenty of other OpenGL functions that I can t seem to be able to call like glEnableVertexAttribArray or glBindBuffer and I would like to understand why.
The reason for this is that the opengl32 library on windows only provides OpenGL 1.1 functionality, everything else is brought in by your graphics card driver. To actually access these functions, windows provides a function to load them. However, writing all the declarations and loading all functions is a lot of work (See Load OpenGL Functions in the OpenGL Wiki) so libraries exist which do this for you, one such library is glew, "The OpenGL Extension Wrangler Library". After you created your OpenGL context (which SFML does), you must call glewInit() which then loads all the other functions. The declarations for those functions are also provided by glew, so make sure to include the glew header instead of your systems or SFMLs opengl header.

Error in emscripten when including glfw and opengl [duplicate]

I have just started using Emscripten and would like to start using GLFW and other libraries. I am completely lost on how to build, link, and use other libraries with Emscripten.
I have tried following the instructions on the Emscripten site but have they haven't helped me any.
http://kripken.github.io/emscripten-site/docs/compiling/Building-Projects.html#using-libraries
Is there any place with detailed instructions on how to use libraries with Emscripten? Or specifically GLFW?
Emscripten provide itself very few libraries. Those libraries are the minimum to get some OperativeSystem functionality on emscripten C++ code (audio, input, video)
libc: standard library for C
libc++: standard library for C++
SDL: SimpleDirectmediaLayer (SDL 1.X a opensource cross-platform project)
GLES2: OpenGL ES 2 API
GLFW: GLFW 2.X
For example, the standard way to include OpenGLES2 in Emscripten is:
#include <GLES2/gl2.h>
While to include GLFW:
#include <GL/glfw.h>
There's some crap in that, because if you want to use the more recent version of GLFW you just can't because Emscripten provides only 1 version of the library and you have to stick with that (unless Emscripten do a update for that and you update Emscripten).
You can compile libraries for emscripten only if that libraries can be compiled using one(or more) of the libraries listed above. (or if you know how to wrap javascript funciontalities and expose them through C interface)
Also, try to avoid templates only libraries when using Emscripten, they literally generate a lot of bloat code you could easily increase executable size by several MBs: This is a problem if you were already using Boost or UBLAS.
Since GLFW is not one of the libraries that are automatically linked, you should link it with:
-lglfw
You can find an example OpenGL project using Emscripten here:
https://github.com/QafooLabs/emscripten-opengl-example
you can inspect linker flags by opening the makefile

Running OpenGL without installing?

I am writing an OpenGL based game. It includes just these two libraries: glew, glfw3. In order to run it the user must obviously have OpenGL installed, an assumption which I'd like to bypass.
I've gathered all the appropriate binaries inside the game directory and tried linking to these libraries locally but the compiler claims undefined reference to all their functions. Am I doing something wrong or is it just impossible? I'm using Windows but it fails on Linux for the same reason.
OpenGL is not a library you install, it's an API that's implemented as part of the driver. Your compiler complaining about symbols not resolving is completely unrelated to the situation on the end user's computer. And in your case it simply sounds that you did not tell the compiler / linker which libraries and API interfaces to link into your program binary; your compiler is hence complaining, that some of the internal references don't redolve.
So here it goes: OpenGL is not something you ship with your program, it's part of the graphics drivers and your program must use whatever OpenGL version is installed on the user's machine. For this you dynamically link against libGL.so by passing the compiler-linker option -lGL.
GLEW is a helper library that post-loads dynamically all OpenGL functions not found in the system OpenGL ABI, which hence are not exported through the public symbol table of libGL.so. Rather they're to be loaded dynamically using glXGetProcAddress – a rather tedious task. Be advised that GLEW has some serious issues when it comes to OpenGL-3 and later core profiles.
GLFW is a simplistic framework library for setting up a window having an OpenGL context.
GLEW and GLFW are safe to link statically with your program, and I recommend you do that. Instead of using the -l… flag, add libGLEW.a and libGLFW.a to the list of source files / compilation units to be linked.

OpenGL: VBO functions are not defined

I'm trying to use OpenGL VBO's, but the functions associated with their use, glGenBuffersARB() for instance, are all undefined. Immediate mode functions are fine of course, it's only these.
I'm using VS2010, with the SFML library. One of the include headers in that library includes both <GL/gl.h> and <GL/glu.h>, and the executable is linked against glu32.lib and opengl32.lib
Why are only these functions missing, and how would I be able to include their use?
GLEW will define them, as will other GL extension libraries.
Information can be found here: http://www.opengl.org/resources/features/OGLextensions/
Using an extension that includes new function call entry-points is harder in Win32 because you must first request the function pointer from the OpenGL ICD driver before you can call the OpenGL function.
GLEW does this for you.