SDL2 does not natively support removing only the title bar while keeping the borders. When you use the SDL_WINDOW_BORDERLESS
flag, all decorations, including the title bar and borders, are removed.
If you need this functionality, you’ll need to use platform-specific APIs to modify the window style directly. For example, on Windows, you could use the Win32 API to customize the WS_BORDER
and WS_CAPTION
flags of the window.
However, this approach bypasses SDL2’s abstraction and ties your code to a specific platform.
Here’s an example of creating a completely borderless window in SDL2 (no title bar or borders):
#include <SDL.h>
int main() {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* Window{SDL_CreateWindow(
"No Title Bar",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
800, 600,
SDL_WINDOW_BORDERLESS
)};
SDL_Delay(3000);
SDL_DestroyWindow(Window);
SDL_Quit();
}
To keep the borders but remove the title bar, a workaround is to simulate borders using custom rendering inside the client area. Alternatively, look into platform-specific APIs if this functionality is critical.
Answers to questions are automatically generated and may not have been reviewed.
An introduction to managing SDL2 window decorations, borders, and client areas.
Comprehensive course covering advanced concepts, and how to use them on large-scale projects.
View Course