Programming for Linux


In this article you will discover differences in programming for Linux platform with Nitisa framework. As you will see there are almost none.



Introduction

Linux operating systems are different from Windows. They lack many features Windows has. For instance, there are no any standard dialogs to select color, setup font, printing, and so on. Even creating simple true modal dialog window for the application is not possible for Linux. Moreover, all linuxes are different. If something work on one of them it doesn't mean it will work on another one. There is always at least one Linux implementation which works in the way you completely could not predict. We have been trying to achieve as much as possible having the limited set of tools on Linux and are going to try implementing missing features by our own to provide you with powerful and easy to use instruments to create GUI applications on Linux systems as well.

To develop applications using Nitisa framework for Linux platforms you have first install on the Linux machine some packages Nitisa depends on. You can find the list in the requirements article.

Platform classes for Linux of the Nitisa framework work with X11 subsystem, which is available on most Linux with graphical interface. If your Linux doesn't have it, the only way for you to get Nitisa work in this case is to implement platform dependent classes for your Linux from scratch.

Code

Despite all the limitations of the Linux operating systems we made it possible for you to write code as much the same as on the Windows. The only difference is project settings. Compare source codes for application initialization for Linux, Windows and Android.

Linux

#include "Platform/Core/Application.h" 
...
int main()
{
    nitisa::CApplication app;
    Application->CreateForm(&form);
    Application->setMainForm(form);
    Application->Run();
    return 0;
}

Windows

#include "Platform/Core/Application.h"
...
int main()
{
    nitisa::CApplication app;
    Application->CreateForm(&form);
    Application->setMainForm(form);
    Application->Run();
    return 0;
}

Android

#include "Platform/Core/Application.h"
...
void android_main()
{
    nitisa::CApplication app;
    Application->CreateForm(&form);
    Application->setMainForm(form);
    Application->Run();
    return 0;
}

As you can see the there is no difference between Linux and Windows but there is a little difference for Android.

Debugging

If you develop your linux application in Visual Studio and use another Linux machine(either real or virtual one) you might want to debug your application using its great debugging features. Sure you can try to do it and it will work fine for console applications but it won't work for graphical ones. That is because Visual Studio connects to remote machine via ssh and thus there is no graphical subsystem in this case. It means no window can be created and thus application with modern GUI cannot be properly started. Anyway, if it could you would not see anything as there is no such possibility in using Visual Studio with Linux. So, if you want to debug GUI application built with Nitisa framework for Linux platform, you have to use some debugger directly on Linux machine. For example, you can use gdb.

You can also use Visual Studio Code. Debugging of Nitisa applications works good with it as well.

When using real, not virtual one, machine with Linux, you usually won't have any trouble. But many developers have only one PC and use virtual ones. That is okay. You still may develop and debug applications with Nitisa using virtual machine(VM). But you need to know there could be trouble with linking. In some cases required library libGL.a is missing on virtual machines. To solve this you may link with libGL.so.1 instead(number can be different depending on you Linux installation; we hope you know where to search). To do this you have to change the OpenGL input library in project settings like shown below.

Linking with specific library in Linux project

All virtual machines support only a very old OpenGL features(for the moment of writing of this article(2021 year) the maximum known supported OpenGL version was 3.3). The Nitisa Linux OpenGL renderer from Platform package requires at least OpenGL 3.1. It means on some Virtual Machines you may use applications created with Nitisa as usual. We recommend to use Hyper-V as it supports OpenGL 3.3. Virtual Box is a bad choice as it supports only OpenGL 2.1. Fortunately there is still a way to run applications on it and see them properly drawing all your GUI forms. To achieve this you can use Mesa 3D library version override and software rendering features. All you need is to run your application using command MESA_GL_VERSION_OVERRIDE=4.3 MESA_GLSL_VERSION_OVERRIDE=400 LIBGL_ALWAYS_SOFTWARE=true ./YourApplicationName.out. The rendering may be very slow, especially first time. You have to be patient. On some virtual machines first rendering appeared only after a minute or two but next ones were very fast in our tests.