Do I have to include the opengl binaries separately to use opengl in sdl?

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…

No, SDL will load OpenGL at runtime for you, if your system has it installed in the usual place.

What OS? What compiler? How are you creating your OpenGL context and loading the OpenGL functions?

I’m trying to use GLEW but I don’t think that’s working either. But neither does directly binding to SDL_opengl.h. I’m up for pretty much anything at this point.

Use something like Glad instead of GLEW.

What specifically are the error messages the compiler is giving?

I’m not familiar with GNAT, what language is this?

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.

Is there some documentation on how to use GLAD? I’m taking a look at the header and it’s… pretty hard to read.

Is sdl2main its own binary? It keeps saying it can’t find it when I try to compile the lazyfoo example. It would have been nice to have a compile command on the tutorial.

How about this, what IS its own binary? Just SDL and the extensions, or…?

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:

if(gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress)) {
  // success
} else {
  // failure