Jump to content

  • Log In with Google      Sign In   
  • Create Account


Wonderfully simple OpenGL UI


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Jan Wassenberg   Members   -  Reputation: 997

Like
2Likes
Like

Posted 17 May 2014 - 01:57 AM

Here's a brief writeup of a simple (9 KLOC, 340 KB binary) but capable and portable OpenGL GUI:

http://wassenberg.dreamhosters.com/blog/2014-05-17/wonderfully-simple-gui/

 

Obligatory screenshot: ui.png

 

Header files are attached: Attached File  ui_headers.zip   5.62KB   30 downloads

 

I'd love to get a discussion going on any perceived shortcomings of this approach, missing features,

alternative libraries that didn't show up in my search, and your thoughts in general.


E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3

Sponsor:

#2 NightCreature83   Crossbones+   -  Reputation: 2669

Like
0Likes
Like

Posted 17 May 2014 - 10:09 AM

Well where are the cpp files that implement all of the features with just the interface there isn't much to discuss to be honest. Also this will only work for 2d UI, what about 3d UI like this:

 

What about controller input?

 

How is the UI constructed, from code, other filed, can I override how a button is drawn easily or which shader is being used to render with?


Edited by NightCreature83, 17 May 2014 - 10:10 AM.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, Mad Max

#3 Jan Wassenberg   Members   -  Reputation: 997

Like
0Likes
Like

Posted 17 May 2014 - 12:29 PM

Let's see how far we can get talking about the interface :)

Ooh, that's a pretty one. Looks like three different modes - main menu as extruded 3d text, then the oblique view, then the white 2d one for actually entering text. It's easy enough to get something like the second one by rendering the UI output to texture and incorporating that into some other scene. I'm more interested in `serious' apps that don't need fancy presentation, though.

Controller button input is easily supported by calling Interaction::OnKeyDown with a real or fake corresponding SDL key code.

"other filed"? You mean whether any data files are necessary? The font renderer has a binary blob that's bundled with the executable (on Linux, it'd be a standalone file), same for the shaders.

If you want ALL buttons to look different, that's an easy change in Painter::DrawButton and Layout::ButtonSize (if you're also changing the default size). This is probably debatable, but I prefer separating size, presentation and control logic. What's the use case for switching shaders?

Here's the code that drives the demo UI. It's simple enough that auto-generation of code is not necessary :D
Note the standard IMGUI if (Button()) { it_was_clicked; } pattern.

static void DoUI(Interaction& p_Interaction, Canvas& p_Canvas, TextPainter& p_TextPainter)
{
    Layout layout(p_Interaction.windowSize);
    Painter painter(p_Canvas, p_TextPainter);
    UI ui(p_Interaction, layout, painter, p_TextPainter);

    layout.BeginGroup(GROUP_LEFT_DOWNWARDS);

    static bool showOptions = true;
    ui.CheckBox(L"Show options", showOptions);
    if (showOptions)
    {
        layout.BeginGroup(GROUP_TOP_RIGHTWARDS | GROUP_NO_MARGIN);

        static bool enableBlending = true;
        ui.CheckBox(L"Enable blending", enableBlending);
        if (enableBlending)
        {
            static float value = 4.0f;
            ui.Slider(1.0f, 16.0f, value);
        }

        layout.EndGroup();

        std::vector<UString> labels;
        labels.push_back(L"YCoCg-DXT5");
        labels.push_back(L"DXT1");
        labels.push_back(L"RGBA");

        static int listSelected = 0;
        ui.ListBox(&labels[0], labels.size(), listSelected);

        layout.BeginGroup(GROUP_TOP_RIGHTWARDS);

        ui.Label(L"Format");
        static int formatIdx;
        ui.ComboBox(&labels[0], labels.size(), formatIdx);

        layout.EndGroup();
    }

    layout.EndGroup();

    if (showOptions)
    {
        layout.BeginGroup(GROUP_RIGHT_DOWNWARDS);

        static bool panelUnfold = true;
        if (ui.BeginPanel(L"Panel", panelUnfold, GROUP_DEFAULT))
        {
            static int selected;
            ui.RadioButton(L"Radio1", 0, selected);
            ui.RadioButton(L"Radio2", 1, selected);
            static bool checked1, checked2; 
            ui.CheckBox(L"Check1", checked1);
            ui.CheckBox(L"Check2", checked2);

            ui.EndPanel();
        }

        if (ui.Button(L"Do things"))
        {
            SDL_Log("clicked\n");
        }

        static UString buf(L"edit box");
        ui.LineEdit(buf);

        layout.EndGroup();
    }

    p_Canvas.Draw();
}

E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3

#4 Jan Wassenberg   Members   -  Reputation: 997

Like
0Likes
Like

Posted 18 May 2014 - 10:35 AM

Minor rendering update per feedback received (thanks!)..

Radio button+slider larger, more corner rounding, different accent color.

Attached Thumbnails

  • ui2.png

E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS