Advertisement

GUI - OS & Hardware Cross-Platform, Written In C

Started by March 21, 2021 12:11 AM
11 comments, last by Nordmann 3 years, 6 months ago

Hello,

Is there a way to write vector GUI code only in C which is very easy to port to all major platforms, while retaining the same GUI to screen ratio? My goal is Mac OS, Windows, Linux, and smartphones.

For game dev and other apps, I want to make my C programs as much cross-platform as possible without digging to find special libraries. It is best for me to write once and move on and much as I can. I looked into OpenGL but I want strictly C coding until I reach a good level of skill in the language. I want to see how advanced I can go in C game development.

I have seen libraries and software for cross-platform GUI written in C++, C#, Python, etc., but nothing in recent years written only in C. Is it impossible to write cross-platform GUI exclusively in C or is this information strictly esoteric?

Any positive opinion on this would be appreciated.

Clinton

Nordmann said:
I looked into OpenGL but I want strictly C coding

The OpenGL API is in C, so what's your issue with it? It's not that i'm 100% sure there aren't any, as i moved to C++ before starting using OpenGL IIRC.
Vulkan is C too. (Just to let you know - not recommended for anything meant to be practically simple.)

Usually you want to separate your GUI from rendering it. To render, a GUI lib only needs a small number of callbacks to draw primitives like lines, triangles, eventually with texture for text, and scissor rectangles for clipping. Any gfx lib supports those, and it should be easy to use your GUI with any rendering backend.

ImGui is a good example (https://github.com/ocornut/imgui),​ it comes with examples of integration to OpenGL. VK and DX. Those examples themselves utilize application frameworks to abstract OS and gfx content creation, which might be interesting too as it helps to get started while focusing on things that actually matter. ImGui is pretty C style too, maybe you can use just that.

Nordmann said:
Is it impossible to write cross-platform GUI exclusively in C or is this information strictly esoteric?

It's possible, there just seems no need for it. You can mix C and C++. There is no reason to restrict yourself to only C. Doing so has no benefit for learning, and likely you only make it hard and cumbersome for yourself in some cases.

Personally i started with C after using some crap like Basic on home computers, and i loved it. It was the perfect language. I have learned C++ too pretty quickly, but it did not really change my programming. Did not like things like Inheritance for example. So i remained a C programmer at heart for decades. I used some C++ features, e.g. class methods, but not so much more. This is true for many, and i think this practice even has a name: ‘C with Classes’.
Only in recent years i try to catch up a bit with modern C++. I realize i have missed a lot, and it really really helps with producibility. Still, i would recommend to get started with C, focus on problem solving / algorithms, and dive into language features a bit later / on demand.
IMO that's good practice, but when it gets to the point so it becomes hard to use libraries, then you are pedantic and restricting yourself for no benefit.

Advertisement

@JoeJ I have read on the internet about Apple and Microsoft phasing out OpenGL support. I understand that legacy versions still work into the future for quite some time, even if they completely drop support. As a side comment, in my opinion, dropping OpenGL support will actually lead to more momentum toward Linux, being that some people have had enough of the IT acrobatics. It also makes Game Engines look more attractive, particularly for mobiles. I intend on using a lot of C for game dev and also free lance business app development to help make a living. C is obviously still going very strong in general. I think more functionally, so it suits me better than a lot of overhead abstraction. Plus I want to build my own libraries for performance and familiarity reasons.

Thank you, Clinton

Nordmann said:
C is obviously still going very strong in general.

Sure. I only meant this does not necessarily rule out using some C++ as well, similar to how i had to use Java / Objective C to make a game for mobiles. No way around that, if i liked it or not.

Nordmann said:
I have read on the internet about Apple and Microsoft phasing out OpenGL support.

It will still work on top of their whatever current API. Well, at least i'm sure MS does - they care about backwards compatibility. If Apple does not, somebody will make it work for them, like it happened with Vulkan.

For games that's ofc. a problem because probable performance losses, but on the other hand GPU driver teams can drop a huge pile of legacy bloat and focus on DX12/VK, which is good.

But do we talk about games or about a GUI framework? I wonder why you aske specific about GUI, but not about how to render graphics in general?

Nordmann said:
I have read on the internet about Apple and Microsoft phasing out OpenGL support

Forget about Apple, they shoot thmselves into abyss with their strict denial of using industry standards and the market share of Mac OS X games is quite low, espeically since they started a bitchfight with Epic Games (Unreal Engine).

Microsoft on the other hand is true, they dropped OpenGL support BUT it isn't a major thing because this was related to the built-in GL drivers they had up to GL 2. All major vendors AMD, NVIDIA and Intel still offer GL Drivers for their Hardware and also Vulkan support. Would be bad if they won't because they participate in the Khronos Group, which maintain GL and Vulkan.

I'm writing a GUI Framework at the moment as well, to be used for our tools and the game engine too. Trust me when I say that rendering isn't the major point of it. You have enougth work to do without ever touching a graphics API to define how your UI is declared, how layouting works and in which way it interacts with your code. You can btw. read my post here https://gamedev.net/forums/topic/709375-ui-framework

Oh, i see i've got that OpenGL thing totally wrong. Already forgotten the MS software opengl32.dll is no more since quite some time.

Advertisement

You mean in-game GUI or general desktop application GUI?

gtk+ is written in C.

Apple doesn't have the guts to kill off OpenGL. Instead, the coder is faced with a thousand warnings when compiling OpenGL/GLUT applications on Mac OS X.

Go with C++ code. It works on all of the platforms that you mention.

I used some C++ features, e.g. class methods, but not so much more. This is true for many, and i think this practice even has a name: ‘C with Classes’.

If I remember correctly C with classes was the original name of C++ or rather a precursor to it developed by Bjarne Stroustrup himself.

Gnollrunner said:

I used some C++ features, e.g. class methods, but not so much more. This is true for many, and i think this practice even has a name: ‘C with Classes’.

If I remember correctly C with classes was the original name of C++ or rather a precursor to it developed by Bjarne Stroustrup himself.

You're right. What he's referring to is called C style C++.

This topic is closed to new replies.

Advertisement