xealits
xealits

Reputation: 4566

SDL3 CMake cannot configure OpenGL support on Linux

I am trying to build a C++/CMake app with SDL3 as git submodule on Ubuntu 24.04, but it cannot configure OpenGL support. I follow the example and add the SDL_OpenGL=ON option and the path to libGL.so (just in case):

git submodule add [email protected]:libsdl-org/SDL.git lib/SDL

CMakeLists.txt:
...
set(SDL_OPENGL ON)
set(SDL_OPENGLES OFF)
list(APPEND CMAKE_PREFIX_PATH "/usr/lib/x86_64-linux-gnu/")
# that's where libGL.so sits:
# /usr/lib/x86_64-linux-gnu/libGL.so

add_subdirectory(lib/SDL EXCLUDE_FROM_ALL)

...
target_link_libraries(mylib PRIVATE SDL3::SDL3)

At CMake configuration, it does not seem to find OpenGL:

$ cmake -DCMAKE_BUILD_TYPE=Debug -S./ -B./build -G Ninja
...
-- SDL3 was configured with the following options:
-- 
-- Platform: Linux-6.8.0-47-generic
-- 64-bit:   TRUE
-- Compiler: /usr/bin/cc
-- Revision: SDL3-3.3.0-release-3.2.6-18-g2c7c3d4d7
-- Vendor:   
-- 
-- Subsystems:
-- <all ON>
--
-- Options:
...
--   SDL_OPENGL                  (Wanted: ON): OFF
--   SDL_OPENGLES                (Wanted: OFF): OFF
...
-- 
-- If something was not detected, although the libraries
-- were installed, then make sure you have set the
-- CMAKE_C_FLAGS and CMAKE_PREFIX_PATH CMake variables correctly.
...

It does not say anything else about OpenGL during CMake configuration. It complains about not finding LibUSB and FFmpeg. But nothing about OpenGL.

And at runtime it indeed fails on window creation with SDL_WINDOW_OPENGL flag in a constructor that sets up the SDL context like this:

#define macro_test_critical(condition, log_fail_message) \
if (condition) { \
    log(log_level::CRITICAL, (log_fail_message)); \
    exit(1); \
}

SDL_Window *gSDLWindow{nullptr}; // a private member

ContextSDL::ContextSDL() {
macro_test_critical(SDL_Init(SDL_INIT_VIDEO) < 0, "SDL_INIT_VIDEO failed") else {
    log(log_level::DEBUG, "SDL_INIT_VIDEO success");
}

// prepare OpenGL attributes
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 6);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

// multisampling for anti-aliasing
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);


gSDLWindow = SDL_CreateWindow("OpenGL Window",
                              m_ScreenWidth, m_ScreenHeight,
                              SDL_WINDOW_OPENGL);

macro_test_critical(gSDLWindow == nullptr,
    std::string("SDL_CreateWindow failed: ") + std::string(SDL_GetError())) else {
    log(log_level::DEBUG, "ContextSDL::ContextSDL created OpenGL window");
}

...
}

The error is "SDL not configured with OpenGL/GLX support":

$ ./main
log level 1: ContextSDL::ContextSDL(int, int) at /....cpp:26 SDL_INIT_VIDEO success
log level 5: ContextSDL::ContextSDL(int, int) at /....cpp:51 SDL_CreateWindow failed: SDL not configured with OpenGL/GLX support

I think that OpenGL is there:

$ glxinfo | grep OpenGL
OpenGL vendor string: AMD
OpenGL renderer string: AMD Radeon Graphics (radeonsi, renoir, LLVM 19.1.1, DRM 3.59, 6.11.0-17-generic)
OpenGL core profile version string: 4.6 (Core Profile) Mesa 24.2.8-1ubuntu1~24.04.1
OpenGL core profile shading language version string: 4.60
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.6 (Compatibility Profile) Mesa 24.2.8-1ubuntu1~24.04.1
OpenGL shading language version string: 4.60
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 24.2.8-1ubuntu1~24.04.1
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:

The graphics driver is amdgpu.

I've installed all suggested build dependencies of SDL. And these libraries are installed:

$ sudo apt install libgl-dev libglx-dev mesa-common-dev mesa-utils freeglut3-dev
...
libgl-dev is already the newest version (1.7.0-1build1).
libglx-dev is already the newest version (1.7.0-1build1).
mesa-common-dev is already the newest version (24.2.8-1ubuntu1~24.04.1).
mesa-utils is already the newest version (9.0.0-2).
freeglut3-dev is already the newest version (3.4.0-1build1).
...

How to make it find and configure OpenGL? Does it miss some library, some path?

Upvotes: 0

Views: 16

Answers (0)

Related Questions