Some of the C graphics libraries are great, but I've yet to find a simple GUI that makes it easy to port some older BASIC programs that I want to be able to keep working with. I've created several iterations of my own GUI library, but have never been satisfied with the results. That's the main reason I keep investigating cross-platform GUIs, to see if someone's found a better way to do it. Of the various designs, the ideas behind the immediate mode GUIs seem the most useful for the type of programs I'm targeting. However, I can't seem to find one GUI library that provides a simple way to do what I want. So, I've decided to revisit my old GUI library designs but eliminate some of the framework constraints and some of the object oriented elements. Instead, I'm looking at a more procedural approach that uses concepts from immediate mode GUIs.

Even though I'm avoiding popular C/C++ GUI libraries, I'm not starting completely from scratch and writing everything myself. There are plenty of good graphics libraries that are very portable and make a great basic starting point for a GUI. One of the libraries I've been very impressed with is SDL. It makes a great base for porting software. I've also done a lot of work with PicoGL (a TinyGL fork). It's a convenient way to make OpenGL more portable and avoid some of the version issues. It works on low resource platforms such as handheld devices that don't have high performance video driver support. I've often found OpenGL and Mesa slow on older computers and low resource systems. PicoGL provides very good performance on these types of systems. While using Win32 is not as portable as I would like, it's not that hard to get an OpenGL window up and running on Win32. That easily allows switching between Win32/OpenGL and SDL (1.2.15 or SDL 2.x)/PicoGL. SDL can work on a variety of platforms and PicoGL can work with SDL or with other options such as nano-x, X11 or vesa framebuffer. It shouldn't be too hard to take the output from PicoGL to use with the Android bitmap API either. Another possible option for a backend is Allegro. Like SDL, it works on a variety of platforms. It would be nice to switch between SDL and Allegro as backends depending on which works best for a particular platform without needing to redesign an entire application.

The PDCurses/ncurses API provides a standard way to create console based programs that work well on a variety of platforms from DOS to Windows to FreeBSD to Linux. However, it provides only text support and no real graphics support. While it's great for porting programs written to work with it, I don't think it's the best option to use as a GUI backend. I recently came across TinyCurses which provides a subset of the API and uses SDL as a backend. PDCurses also offers SDL as a backend option. I couldn't help thinking, once a decent GUI design was finalized, it wouldn't be too hard to provide a subset of functionality similar to PDCurses/ncurses. That would allow for easy porting of some PDCurses/ncurses based applications to any platform the GUI library works on.

So, why not just use OpenGL as the backend to design a GUI library? After considering the pros and cons, I decided I don't want to be tied specifically to OpenGL as an API for 2D graphics. While it's very popular and available on several platforms, the changes from a fixed function pipeline to a programmable pipeline with its own shading language make it hard to port programs from one version to another. PicoGL makes use of old fixed function pipeline concepts. Windows OpenGL also uses the older design. Mobile devices and WebGL make use of the newer concepts and the ability to harness the GPU to do more processing. Many developers seem to be abandoning the older concepts and embracing the new programmable pipeline design. However, that leaves some nice older applications that were designed for earlier versions of OpenGL that won't port easily to the newer versions. They might require a complete redesign and rewrite. Using PicoGL is one way to make it easier to port such applications. It can do software rendering to a bitmap which can then use more modern methods (including later versions of OpenGL or SDL 2.x) to transfer the bitmap to the screen. While the idea of using OpenGL as the portable backend for a GUI library sounds good, dealing with version differences and what versions may be available on which platforms does not make it the best option for a complete cross-platform portable solution. Instead, I prefer the concept of being able to switch out backends to use what works well on a particular platform. The GUI library should encapsulate the rendering as much as possible to avoid needing to rewrite applications in order to switch to another backend.

On the other hand, many GUI libraries and some other rendering libraries (such as SDL) offer ways to interoperate with a graphics library like OpenGL. While I want my GUI library code to be cross-platform, I don't want to limit a developer to using just that API. If a programmer wants to use OpenGL or SDL2_gfx or some other library to handle 2D/3D graphics, I'd like the GUI to be able to interoperate with that choice. It would mean that the resulting application would be less portable. However, if an application is already designed to utilize SDL2_gfx, OpenGL or some other library that could work compatibly with the GUI library, it could make adding some GUI functionality to an existing application much easier.

I definitely know what I'm looking for in a cross-platform GUI. I want a simple, portable way to get text, menus, forms, file/directory picker dialog functionality to the screen. I'd like to make use of Freetype fonts. I want an internationalized way to display text and for users to input text. The text strings will probably involve a library such as gettext. I want the options to use keyboard input for those of us who prefer keyboard commands to get their work done and mouse/touchscreen input for devices such as mobile phones where a real keyboard may not be available. I need to be able to access graphics and audio information from a file system or from a zipped file (such as .apk file on Android). I don't care if the look and feel matches what's in style for a particular device or operating system. I just want it to be user-friendly and ergonomically designed.

If you're interested in GUI design or working on a GUI or gaming library of your own, I'd love to compare notes on the subject. Have an idea for what C library might make a good backend for a portable, cross-platform C based GUI? Let me know. Feel free to discuss design issues or other C/C++ topics on the CppDesign mailing list or contact me to compare design notes and share ideas ( http://www.distasis.com/connect.htm ).
I'm always on the look-out for a simple to use, lightweight, portable GUI library. I've put together several lists of available C/C++ GUI libraries. (For instance: http://www.distasis.com/cpp/scrlib.htm ) I've also tried out and experimented with several GUI and text user interface libraries. It's difficult to find one that will let you get a new application up and running or an old one ported to C/C++ quickly. Most GUIs seem to get in the way of development or complicate it.

I still keep debating whether to create my own GUI library in projects or use what's currently available. There's no point in creating your own if there's something better out there. That's the main reason I continue to look for interesting GUI libraries. However, I've yet to find that "something better" that I really enjoy working with.

With that in mind, here's another list of GUI libraries. This time I've limited the field to C only libraries that are highly portable. Since many lighter GUIs use various graphics libraries and other frameworks as backends, I'm including information on graphics libraries that can be used for GUI development as well.


Graphics libraries often used with GUIs:


Some lightweight GUI libraries use graphics libraries as backends to improve portability and decrease library code size. Popular graphics backends written in C include SDL (Simple DirectMedia Layer) and Allegro.

SDL

https://www.libsdl.org/
SDL2_ttf provides TrueType text support for SDL.
https://www.libsdl.org/projects/SDL_ttf/
SDL2_ttf provides internationalization support using a UCS-2 character set. I have patches to support the UTF-32 character set.
http://www.distasis.com/cpp/lmports.htm

Allegro

https://www.allegro.cc/about

AGG

Anti-Grain Geometry library is also used as a graphics backend. Some projects stick with the older version of AGG 2.4 which has a BSD license.
https://en.wikipedia.org/wiki/Anti-Grain_Geometry

Nano-X/Microwindows

Nano-X is highly portable and can work on a wide variety of platforms including DOS and embedded systems. It makes it easier to port X11 and Win32 applications by providing a subset of those APIs (with nano-x/NX11 or microwindows).
https://github.com/ghaerr/microwindows
https://github.com/georgp24/microwindows-android-bin
https://github.com/ghaerr/nxlib

OpenGL

I've seen several lightweight GUI and screen libraries designed for OpenGL. However there are issues with portability to different versions of OpenGL or OpenGLES. Projects like freeglut and GLFW try to make OpenGL easier to use for cross-platform development. There are also several libraries that work with the freetype library and add TrueType font support including ftgl, ftgles, GLTT, freetype-gl, OGFLT
http://freeglut.sourceforge.net/
https://www.glfw.org/

PicoGL

I like PicoGL (a fork of tinyGL) for OpenGL development. It's a subset of OpenGL. It supports several backends including SDL, nano-x, X11 and vesa framebuffer. Since it's software based, it ports well to hand-held devices and other systems that may not have rich hardware support for graphics.
http://people.openmoko.org/jserv/graphics/

I've made several updates and additions to PicoGL including adding some missing OpenGL functionality, SDL 2.x support, bug fixes including a fix for lighting bug in the gears demo. It includes enough OpenGL support to port Emilia pinball. I haven't uploaded my changes to the Internet yet, but if anyone's interested, feel free to contact me about it.


GUI and text user interface options:


PDCurses with SDL backend

This is an option I really like. I've been experimenting with using this for development. I have BSD libmenu and libform working with it too. PDCurses can be used to create a text user interface and SDL can add graphics capabilities.
https://github.com/wmcbrine/PDCurses

TinyWidgets

Lightweight GUI with graphical screen designer. Uses nano-x as a backend. While the original project is dated, there's been some recent development by some of the nano-x developers.
http://tinywidgets.sourceforge.net/
https://github.com/ghaerr/microwindows/tree/master/src/contrib/TinyWidgets

nuklear

This looks promising. Has several backends including GLFW, SDL, Win32, X11, SFML, allegro, nanovg.
https://github.com/Immediate-Mode-UI/Nuklear
https://github.com/vurtun/nuklear
https://github.com/vurtun/nuklear/issues/202
There are also projects that combines nuklear and raylib:
https://github.com/RobLoach/raylib-nuklear
https://github.com/tcfunk/raylib-nuklear

raygui

Another promising cross-platform option. It has support tools to help create layouts. It works on a variety of systems including mobile devices. There's also raylib (a graphics/video game library used by raygui) and raudio (for audio support). The raylib library uses OpenGL/GLFW for graphics support.
https://github.com/raysan5/raygui

c_ugui

Immediate mode GUI using Raylib.
https://github.com/Aurumaker72/c_ugui

nanovg

nanovg is a 2D vector drawing library by the developer of nanosvg (popular svg parsing library). The examples show GUI elements. Other GUI libraries (including nuklear and oui-blendish) also use this as a backend option.
https://github.com/memononen/nanovg
https://bitbucket.org/duangle/oui-blendish/src

GTK+

GTK+ is one of the more popular GUI libraries. However, while each new major version came with added features, it also came with a lot of added complexity. Some distributions use older versions of GTK+ (no longer in development) in order to cut down on complexity. While there were several applications written with this library, it's hard to find up-to-date, supported applications that still use an older version of GTK+.

Amigo Linux is still using GTK 1.2 and has patched some applications to keep them working.
ftp://distro.ibiblio.org/amigolinux/misc/Amigo%20Linux%20Project.html

I've also seen some patches to GTK 1.2 to keep it more up-to-date.
https://github.com/dimkr/gtk
https://github.com/tindzk/GTK

Another interesting GTK+ based option, there were some ports of GTK+ that use the ncurses backend.
https://atrey.karlin.mff.cuni.cz/~pavel/cursed/cursed.html
https://sourceforge.net/projects/zemljanka/files/

If you're interested in more up-to-date GTK+ versions that try to avoid some of the bloat and unneeded dependencies, check out these forks for GTK 2 and a minimal ATK to use with GTK 3:
https://github.com/stefan11111/gtk2
https://github.com/stefan11111/atk


XForms Toolkit

http://xforms-toolkit.org/

LessTif

https://sourceforge.net/projects/lesstif/

Kiss_sdl

GUI toolkit for SDL.
https://github.com/actsl/kiss_sdl

kiss-nanovg-sdl

Based on kiss-sdl but modified to support svg using nanovg.
https://gitlab.com/Mis012/kiss-nanovg-sdl

KiWi

GUI toolkit for SDL.
https://github.com/mobius3/KiWi

RetroGui

Minimalistic GUI library based on SDL.
https://gitlab.com/Pix3l/RetroGui

rouziclib

Works with SDL and other libraries.
https://github.com/Photosounder/rouziclib

Green-GUI

GUI for SDL 1.2 written in C99.
https://github.com/Laurefinwe/Green-GUI

swk

Minimalist widget kit for SDL.
https://oldgit.suckless.org/swk/files.html

WidgetSDL2

C99/SDL2 Cross-platform GUI using include headers.
https://github.com/nuchida7727/WidgetSDL2

uGI

Micro Graphical User interface. Needs SDL2.
https://github.com/wernsey/uGI

SDL GUI

Simple SDL GUI libraries, mainly targeted toward Windows.
https://github.com/David-H-Bolton/sdlgui

CGUI

GUI toolkit using allegro.
http://cgui.sourceforge.net/index.html

Win32

I've seen several C applications written with the Win32 API. That might not sound very portable for platforms other than Windows. However, keep in mind that X11 users have access to winelib and Microwindows offers some Win32 API compatibility. I have been able to get some programs written using a Win32 backend to port and run fine on Microwindows/nano-x.

Otk (Open Tool Kit)

C and OpenGL GUI.
https://sourceforge.net/projects/otk/

IUP

https://sourceforge.net/projects/iup/

LCUI

https://github.com/lc-soft/LCUI

sgui

https://github.com/AgentD/sgui

libui

https://github.com/andlabs/libui

libui-ng
https://github.com/libui-ng/libui-ng

GraphApp

http://enchantia.com/software/graphapp/

Microraptor GUI

https://github.com/hodefoting/mrg

Micro-GUI (ugui)

https://github.com/ryankurte/micro-gui

microui

https://github.com/rxi/microui

FTK

https://github.com/xianjimli/ftk

EasyGui for embedded systems

https://github.com/MaJerle/EasyGUI

m2klib

https://github.com/olikraus/m2tklib

Milkymist Gui Toolkit

https://github.com/m-labs/mtk

mGui

http://web.tiscali.it/morello/MGui/index.html

RGFW

https://github.com/ColleagueRiley/RGFW

RSGL

https://github.com/ColleagueRiley/RSGL

Yzone

http://lifesoft.chat.ru/yzone/

GUISlice

https://github.com/ImpulseAdventure/GUIslice

newt

https://pagure.io/newt

notcurses

https://github.com/dankamongmen/notcurses

vtk

https://github.com/vktec/vtk

Agar

GUI toolkit using SDL. I've read several posts about it being buggy and not well supported. I've personally had no luck porting it to certain platforms.

STFL

Use with PDCurses, ncurses or similar libraries to provide common controls and widgets.
http://www.clifford.at/stfl/

CDK

Curses Development Kit.
https://invisible-island.net/cdk/cdk.html

Widget Curses ToolKit

Ncurses TUI widget toolkit library.
https://github.com/stfsux/libwctk



This list is in no way comprehensive. If you know of other highly portable, strictly C GUI or text user interface libraries, please mention them. If you're working on your own GUI library, would like to discuss C/C++ GUI libraries and development or other C/C++ related topics, feel free to continue the conversation on the CppDesign mailing list.
I've been searching technical books and articles to find out more about writing programs for Android using the native development toolkit (NDK) and C/C++. Finding relevant information is extremely difficult. Most sources just say to use Android Studio (or for older articles, use Eclipse) and do not go into any details as to how things work beyond the IDE or wrapper script. It's extremely difficult to find documentation that explains what's going on underneath.

I'm working on porting some Open Source projects already written in C/C++ to Android. So, I find it extremely frustrating when the typical advice I read is to avoid the NDK and use Java (or Kotlin). References that state that usually go on to say that Java (or Kotlin) really is not that much slower than C/C++, so you would be getting no significant gain in performance by using it. That leads me to believe that there has to be some gain in performance (even if it is not what the authors deem 'significant') or the articles wouldn't be mentioning that C/C++ was considered faster in the first place. Such articles typically go on to state that it's much harder to work with the NDK and one is better off using languages recommended by Google. However, for developers who prefer C/C++ over Java or Kotlin development and who are already aware of potential pitfalls of the C/C++ languages and how best to avoid them, those developers could be far more proficient and productive using C/C++ over other options. So, why recommend avoiding the NDK and C/C++? Why not encourage developers to use the languages and tools they can leverage to their best advantage?

Speaking of using tools that developers are most productive with, I already have a cross-platform build system that greatly reduces the time I spend building and porting Open Source libraries. I wanted to be able to use my build system. However, IDEs (like Android Studio) don't integrate well with automated build systems. It took a lot of digging through articles and books on Android, but I was pleased to find out how to create a standalone tool chain to build Android C/C++ applications.

I was surprised at the lack of support for cross-platform compiling of certain Open Source libraries. It's difficult to find Android builds and patches to common Open Source libraries. Also, based on my experiences porting Open Source projects to Windows, I wonder how many Open Source library developers would welcome adding patches to make builds of their libraries for Android work out of the box. My past experience has proved that many library developers would prefer not to add support for more platforms. That means I'll probably end up adding my patches to my LM BLD scripts ( http://www.distasis.com/cpp/lmbld.htm ) rather than seeing the fixes I've submitted added in to the libraries themselves.

So, as I work my way through porting various Open Source applications to Android, I thought I'd share the few useful resources I found that help clarify how to build and share C/C++ Open Source applications on Android.

The best documentation I've located to date and the one I'd refer anyone interested in C/C++ programming for Android to is this one:
http://www.hanshq.net/command-line-android.html
It explains where to get the NDK and other needed libraries. It walks you through how to create an Android package (apk file) via the command line. It gives a good example of how to build a C application that can get a developer started.

If you're on a Linux system, you can use the package manager to download a version of Java. You'll need it to create Android packages. For Windows users, one option is to download a portable version of Java and make sure it's in your development path.
https://portableapps.com/apps/utilities/jdkportable

The Android developer web site actually has some decent information on how to create a stand-alone C/C++ toolchain. You currently need Python to create the toolchain, but they actually supply a version of Python for operating systems that don't easily offer one.
https://developer.android.com/ndk/guides/standalone_toolchain.html#selecting_your_toolchain
See also:
https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
http://mobilepearls.com/labs/native-android-api/ndk/docs/STANDALONE-TOOLCHAIN.html

When creating the stand-alone toolchain, you'll need to know what API you're targeting. More information on that is provided elsewhere:
https://source.android.com/setup/build-numbers
Typical choices are to target the latest if you want to use all the newest features in Android or target an early enough version that the results will work on a majority of the Android devices out there. Which version is best will change over time as the majority of users buy newer devices and new innovations are added to newer APIs. Even though you mention the API when creating the standalone toolchain, the only place the information seems to be stored is in the llvm wrapper. So, you may need to add -D__ANDROID_API__ and the API you want to support to your compiler flags.

You'll also need to decide whether you want to target 32 or 64 bit platforms. Keep in mind that 32 bit code will work on 64 bit platforms, but the reverse is not true. There seems to be better support for large file access on 64 bit platforms though. Note that Google is pushing for latest API targets and 64 bit support for projects that will submitted to the Google Play Store. You'll need to build your application for each target you wish to support. So, if you want your programs to work on Android devices with arm chips or x86 based chips, you'll need to build libraries and applications for more than one system.

Google is also moving toward unified headers so they don't have to support a version of the C and C++ header files for each API they support. Depending on what version of the NDK you're using, you may want to add --unified-headers when creating your standalone toolchain.

I find it useful to know what native C/C++ functionality/which libraries are supported for various versions/APIs of Android:
https://developer.android.com/ndk/guides/stable_apis

I thought this site had a good series of posts on how to port a SDL based application to Android:
http://blog.stuff-o-matic.com/post/2013/10/20/ASGP-s-Android-Port-Part-IV%3A-building-the-APK

If you're interested in using dynamic libraries, this site had some useful information:
https://www.andriydruk.com/post/introduction-to-c-for-android-developers/

Testing the results you built may be difficult. My experience with using MoSync to build C/C++ Android applications showed how slow testing an application with an emulator could be. If you install Android Studio, it gives the option to install Intel HAXM (hardware accelerated execution manager). This can help speed up Android emulation. You can find HAXM and more information on it at the Intel web site.

You can also use VirtualBox and an Android virtual machine image for testing.
Android-X86 ( http://www.android-x86.org/ ) can provide images that work with targets compiled for x86 machines.

Another option is to use adb (Android Debug Bridge) to test the results on an actual Android device. Now that Windows Subsystem for Android is available, you can also us it to run Android apps and use adb to side load the applications you want to test. Here are a couple of articles that give examples of how to work with adb:
http://nickdesaulniers.github.io/blog/2016/07/01/android-cli/
http://codeblog.vurdalakov.net/2016/12/build-and-run-native-c-cpp-android-apps-with-ndk.html

One thing to keep in mind if you're going to test on your own Android device is that Developer options must be activated on that device first. Here's an article on how to do that:
https://www.embarcadero.com/starthere/xe7/mobdevsetup/android/en/enabling_usb_debugging_on_an_android_device.html

You can also build or access Open Source console applications (even without turning on developer options) when you have a terminal emulator app installed on your system. This gives applications you're running in the terminal emulator (even one's you've built from source) the same rights at the terminal emulator. You can use command line or console based applications (such as those built with pdcurses/ncurses/netbsd-curses) with a terminal emulator. There are several terminal emulators available from the Google Play Store or F-Droid. Try some out and see which you like best.

One of the terminal emulator projects has a github project with information on some common Open Source library packages including commands for building and patches needed to compile. One thing to watch out for is that some of their patches are made directly to the standalone toolchain header files. If you don't have similar patches or add extra patches to the library's build script, you may not be able to compile successfully. One of these fixes is to help work-around 64 bit file handling support on 32 bit systems. Some Open Source projects don't build properly or need major work-arounds to handle this with earlier versions of the Android API for 32 bit systems. More information on how the Termux terminal emulator project builds their Open Source libraries and programs is available at their github site:
https://github.com/termux/termux-packages/tree/master/packages

Another interesting resource if you want to see how various C/C++ projects are built and what patching might be needed is this one:
https://github.com/pelya/commandergenius
It uses SDL 1.2/1.3 ported to Android and includes several Open Source libraries and several popular Open Source applications including DOSBox, Milkytracker, grafx2 and a SDL based X server.

A developer I correspond with wrote his own tutorial on how to build C/C++ applications using Allegro and Nano-X. He covers a lot of useful material about the NDK and C/C++ development including how to call Java functions from C/C++ and vice versa. He also explains how to use Allegro on Android.
https://wiki.allegro.cc/index.php?title=Running_Allegro_applications_on_Android

Libraries such as SDL, Allegro and Nano-X provide support for building GUI applications on Android. Nano-X offers a subset of X11 functions so GUIs like FLTK and WxWidgets will work. PDCurses can be used in conjunction with SDL. Applications built using any of these libraries could potentially be ported to Android. Not all C/C++ applications provide interfaces that are user friendly for Android or for smaller screens and devices that may lack physical keyboards. However, if you create a well designed, portable interface for your program, there's no reason why it shouldn't work well on Android systems as well as PCs (Linux, Windows, BSD, etc.). Here's more information on some GUI libraries that work on Android:
https://github.com/georgp24/microwindows-android-bin
https://wiki.libsdl.org/Android
http://liballeg.org/readme.html

More recently, I ran across Android Apps in C. It uses Android Studio which is a lot of overhead if you just want to build an application. Also seems to use WSL on Windows instead of direct development on Windows. Seems to use the standard android_native_app_glue code. However, there may be other tips and tricks that are useful when creating a C/C++ application for Android. The project is at:
https://github.com/cnlohr/rawdrawandroid

That's pretty much all my searches have turned up as far as resources I've found useful for building C/C++ applications targeted to Android devices. If you have other reference recommendations that explain how things actually work (rather than glossing over the details and using a GUI interface), please let me know. If you'd like to share or compare notes on patches, compiler/linker options for building various Open Source libraries and applications, I'd enjoy hearing from you. You can discuss C/C++ Android development further with me and other interested developers on the CppDesign mailing list.

April 2025

S M T W T F S
  12345
6789101112
13141516171819
20212223242526
27282930   

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 23rd, 2025 09:35 am
Powered by Dreamwidth Studios