I’ve seen a lot of tutorials on how to do this, but I’m still having no luck. I see a few that mention needing to pass a -lopengl32 or -lgl flag to gcc. Do I need to provide libraries to go with those, or does SDL handle it?
I can’t for the life of me get this thing to compile…
GNAT is by far the most popular Ada compiler. The good news is, it’s closely related to gcc in much that same way that g++ is, so linking is largely the same. The command line switches for gnatmake are a superset of those for gcc, so anything you can pass to gcc you can also pass to gnatmake.
The specific error I’m seeing is everything comes up as undefined reference. Undefined reference to glEnable, undefined reference to glBegin, etc etc.
I think one of the tricks here is that Ada normally requires a reference to exist at link time for its bindings, even if you scope the bound subprogram until such time that it would never exist until the reference does. So I’ve been trying a few tricks to see what works.
I’ll give some of these others a go–or really, the built-in OpenGL method of getting a function pointer seems like it could work–but I wanted to eliminate any low hanging fruit like I just was missing a binary completely, lol.
On Windows you might still have to link to Microsoft’s OpenGL 1.whatever stub. It’s been a long time since I tried to do anything with OpenGL on Windows, and I’ve never tried it on Windows with anything other than MSVC.
GLAD, like GLEW, is just a helper for loading OpenGL function pointers so you don’t have to write all that code yourself. But you have to initialize them and load the function pointers before calling any OpenGL functions.
I don’t find that to be necessary. All I have in my link options are the usual -lmingw32 -mwindows and it finds OpenGL at runtime. That’s not really surprising, since opengl32.dll is in \windows\system32 so is in the default DLL search path.
The GLAD header is automatically generated based on what you input on the website, so it’s hard to read for a human.
IDK about Ada, but in C you include glad.h before anything else that might include an OpenGL header, and specifically do not include SDL_opengl.h
Once you’ve created your OpenGL context with SDL, you initialize GLAD before calling any OpenGL functions. You pass the init function a pointer to whatever function loader you’re using. Generally, if you’re using SDL then use SDL’s, like: