GLIMGUI released

March 26, 2014

Ages ago I wrote a nice article about how I searched for a simple GUI system for a game that I was working at the time. I ended up writing my own GUI system that was using the IMGUI approach and I am still very happy with this. It indirectly inspired @the_vrld to create Quickie which is an IMGUI system for my favourite 2D game framework LÖVE.

In the article I had written that I plan to release a simple library that can be used as a starting point for more advanced IMGUI explorations. Turns out I never did publish it so here we go:

Grab the code from: https://bitbucket.org/MartinFelis/glimgui.

It is licensed under the MIT license and as said very basic but with ~500 lines it should also be very easy to adjust and extend it. It is written in plain C and only depends on OpenGL and glut. Only ASCII strings are supported but if you have a fully featured unicode rendering function available it should be very easy to plug it in (look at glimgui_printxy(float x, float y, const char str*, ...)).

Here are some screenshots (very basic but easy-peasy to pimp): main_menu options

And here the full source code for the UI including the button logic that was used for the screenshots:

void draw_ui () {
  glimgui_prepare ();

  // Drawing of the GUI

  // We have two GUIs that are indicated by the global gui_layout value
  if (gui_layout == 0) {
    glimgui_label (99, "Main Menu", 20, 20, 1, 1); 

    if (glimgui_button (1, "Some Button", 220, 100, 180, 50)) {
      printf ("Some Button was pressed!\n");
    }

    if (glimgui_button (2, "Options", 220, 180, 180, 50)) {
      glimgui_clear();
      gui_layout = 1;
      printf ("Switching to Options!\n");
    }

    if (glimgui_button (3, "Quit", 220, 380, 180, 50)) {
      printf ("Quit!\n");
      glutDestroyWindow(window_id);
    }
  } else {
    glimgui_label (99, "Options", 20, 20, 1, 1); 

    if (glimgui_button (1, "Some Other Button", 220, 100, 180, 50)) {
      printf ("Some Other Button was pressed!\n");
    }

    glimgui_label (98, "Enter your name:", 150, 180, 1, 50);

    static char name[32] = { "IMGUI fan\0" };

    if (glimgui_lineedit (2, name, 16, 290, 195, -1, 20)) {
      printf ("Changed name value: '%s'\n", name);
    }

    glimgui_label (97, "Enter your age:", 150, 210, 1, 50);

    static char age[32] = { "99\0" };

    if (glimgui_lineedit (3, age, 3, 290, 225, -1, 20)) {
      printf ("Changed age value: '%s'\n", age);
    }

    if (glimgui_button (4, "Back", 220, 380, 180, 50)) {
      printf ("Switching back!\n");
      glimgui_clear();
      gui_layout = 0;
    }
  }

  glimgui_finish ();
}

Nice, ey?