# SDL2 GUI (same window)

I have a problem: I working on a simple game and want to use some GUI (think of simple input for player name, etc). I've googled a lot of GUIs that can be used with SDL, but:

1. Most of them are using OpenGL while I'm using SDL2 render system. Docs say I can't mix these two, so I need to render GUI in a separate window. I know I can make it borderless and always-on-top, but I still need to manage this as a separate window (e.g. if main window moves, I need to move the gui window, etc, basically, I need to implement the childing myself). That makes me sad.

2. Those few which are using SDL as render (without OpenGL) either abandoned / unfinished / can't be compiled / etc or I can't figure out how to mix them with my rendering.

What I want to achieve: to render GUI in some place on the screen (think of a sidebar) and game stuff on the rest of the screen. Like:

SDL_Window* w = ...;
SDL_Renderer * r = ...;

while(running)
{
renderGui(r, 0, 0, 100, 100); // Minimap located at 0,0 of size 100
renderGameScreen(r, 100, 100, 100, 100); // Rest of the game located at 100, 100
}


Is there a way to do that? How GUI supposed to be used in alongside the SDL? May be my design is broken.

Sorry, I'm completely novice and may mix the things. Thanks.

Update:

1. nanogui-sdl - it uses opengl context, I was not able to mix it with SDL 2d render: it either flickers (because opengl and sdl fight for the screen and over-drawing the contents) or just draws the either thing: ui or game screen. Moreover, it crashes on some controls (like color-picker) and significantly affects rendering time (it drops 2-3 times when I add nanogui rendering with a couple of basic widgets)

2. nuklear - the same thing as with nanogui

3. I was not able to compile ToT KiWi - there are some syntax error (like #elsif instead of #else if or #elif so I'm not ever sure it can be compiled at all).

I'm going to try: imgui, kiss and gwen (gwork).

In the end, I can switch my drawing to opengl (fortunately I need some basic primitives, like circles, rectangles, triangles, etc, nothing complex) if I can't find a UI to work with SDL 2d render.

Update 2:

Sorry for not selecting the answer - was very busy during the week. I marked answer as accepted. I also tried to upvote both answers, since they are both useful, but I don't have enough reputation to do that. Thanks.

For those who wondering is I solve the problem: yes, kind of. I've switched over to SFML. I really like SDL and know it's very stable and mature, but I really need basic graphics for my pet project, so I'm OK with SFML too. It makes working with OpenGL a bit easier, so I can adopt the GUI library.

• I understand the need for a third party gui that can integrate painless with your game. The examples provided in the answers so far should be considered as options. Regarding the minimap, I don't think the controls/widgets provided by any GUI can help to render it, maybe if there is a GUI that provides drawing functions over a canvas, but there are separate libraries for that (cairo, etc). I will look into providing an example as answer. SDL supports clip regions (SDL_RenderSetClipRect), so implementing the minimap without a GUI library should be possible without a lot of work. – Hatoru Hansou Nov 27 '17 at 21:13