C language > Graphics programming

Nuklear immediate mode GUI - C and small

(1/3) > >>

Eggy:
Hello, all!

I just discovered Pelles C today, and I am very happy to have a minimal C with such a great IDE!

I am trying to learn a lot from the ground up, so minimalism is my mantra. I know how to program console apps in C, but now I am moving to graphics. I have a little OpenGL experience in other languages, but I found this immediate-mode GUI called Nuklear

https://github.com/vurtun/nuklear

...and I was wondering if anybody could look at it briefly and maybe let me know where to start? I have tried a dozen or so things, but I have not been able to get the example or one of the examples working with Pelles C. I tried the Example on the readme page at the very bottom.

Here is the code so far from the page:


--- Code: ---#define NK_IMPLEMENTATION
#include "nuklear.h"


/* init gui state */
struct nk_context ctx;
nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font);

enum {EASY, HARD};
int op = EASY;
float value = 0.6f;
int i =  20;

struct nk_panel layout;
nk_begin(&ctx, &layout, "Show", nk_rect(50, 50, 220, 220),
    NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE);
{
    /* fixed widget pixel width */
    nk_layout_row_static(&ctx, 30, 80, 1);
    if (nk_button_text(&ctx, "button", NK_BUTTON_DEFAULT)) {
        /* event handling */
    }

    /* fixed widget window ratio width */
    nk_layout_row_dynamic(&ctx, 30, 2);
    if (nk_option(&ctx, "easy", op == EASY)) op = EASY;
    if (nk_option(&ctx, "hard", op == HARD)) op = HARD;

    /* custom widget pixel width */
    nk_layout_row_begin(&ctx, NK_STATIC, 30, 2);
    {
        nk_layout_row_push(&ctx, 50);
        nk_label(&ctx, "Volume:", NK_TEXT_LEFT);
        nk_layout_row_push(&ctx, 110);
        nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f);
    }
    nk_layout_row_end(&ctx);
}
nk_end(ctx);


--- End code ---

Thanks for any help you may lend me here.

Rob

Scripter:

--- Quote from: Eggy on July 28, 2016, 07:47:06 PM ---I just discovered Pelles C today, and I am very happy to have a minimal C with such a great IDE!

I am trying to learn a lot from the ground up, so minimalism is my mantra. I know how to program console apps in C, but now I am moving to graphics. I have a little OpenGL experience in other languages, but I found this immediate-mode GUI called Nuklear

--- End quote ---

Pelles C is a full development environment. I've been using it exclusively for about 8 years now and have created a number of small to medium size projects with it. Most everything you need is provided but there are a few things you will need to make GUI mode programming easier...

Probably the most important lesson is that "GUI code ain't nothing like console code". For all it's dissimilarities it might as well be two different programming languages... but C being the workhorse it is, handles it all very nicely.

If you want to learn GUI mode C you will need to learn about message queues and tossers as well as  a very different program structure for windows. It's more complicated than console... but not that hard once you understand it.

Here are a couple of tutorials and books to get you started...

http://www.winprog.org/tutorial/start.html
https://www.geekbooks.me/book/view/programming-windows-5th-edition

You will also want a copy of the Windows SDK (Software Development Kit). The best one to start with is in the link below. It downloads (free) as an ISO file and covers you up to Windows 7.  I would not recommend starting with the "latest and greatest" as Windows 8 introduced those annoying tiles and Windows 10 has a mess of other stuff that makes programming both more restrictive and more complex. You can always move forward when confidence permits.

https://www.microsoft.com/en-ca/download/details.aspx?id=8442

If you want to integrate the SDK into the Pelles IDE you can get "addins" for the task here...

http://www.johnfindlay.plus.com/pellesc/addin/addin.html

Near the bottom you will find a collection titled simply "ADDINS" this will give you what you need to integrate the  SDK for F1 searches from the code editor and also a set of better tools to edit and create workspaces.

Hope this helps...


Eggy:
Thank you for such an informative reply.

I had programmed win 32 GDI years ago for very small toy programs, so I am familiar with it.

I am leaning more towards things like a minimal OpenGL GUI, or slightly higher-abstracted GUI kits made with SDL2, SFML, or GLFW. I saw Nuklear and thought it would be great for my game jams to develop quick GUIs interactively and leave it that way for these competitions, not a polished endware.

Even GIMP is using GEGL, and Blender3D has always had their GUI in OpenGL allowing transparency on the various user windows or system windows you can have open.

Today I saw libui for C, and I am going to have to try that.

Nuklear is not as built up as Dear imGui is, but that is C++. I cannot get the demo/example to work in GCC or Pelles yet, so it is me, not Pelles! I was hoping somebody else may have an interest in it to get me past the first hurdle of running the demo. I am not very knowledgeable about the Pelles setup (yet!).

Thanks again for your reply. I will be sure to share back what progress, if any, I make.

Rob

Scripter:

--- Quote from: Eggy on July 30, 2016, 01:26:10 PM ---Thank you for such an informative reply.

I had programmed win 32 GDI years ago for very small toy programs, so I am familiar with it.

I am leaning more towards things like a minimal OpenGL GUI, or slightly higher-abstracted GUI kits made with SDL2, SFML, or GLFW. I saw Nuklear and thought it would be great for my game jams to develop quick GUIs interactively and leave it that way for these competitions, not a polished endware.

Even GIMP is using GEGL, and Blender3D has always had their GUI in OpenGL allowing transparency on the various user windows or system windows you can have open.

Today I saw libui for C, and I am going to have to try that.

Nuklear is not as built up as Dear imGui is, but that is C++. I cannot get the demo/example to work in GCC or Pelles yet, so it is me, not Pelles! I was hoping somebody else may have an interest in it to get me past the first hurdle of running the demo. I am not very knowledgeable about the Pelles setup (yet!).

Thanks again for your reply. I will be sure to share back what progress, if any, I make.

Rob

--- End quote ---

You're welcome.  I try to be helpful...

Of course there is one other source of excellent information about Pelles C ... the help file.  It's one of the best I've ever seen.

I suppose the only additional suggestion I can make here is that you should give the Windows API a try. It's the most direct way to work with windows and Pelles C will get you right down to the nuts and bolts of it very nicely. If you aren't a "quick and dirty" specialist, you may find the added depth quite useful.

My experience with both Object Oriented Programming (OOP) and multiple levels of abstraction would seem to indicate that most of the time all these techniques succeed in doing is bloating your code and introducing new bugs. Certainly they are not faster or easier to use. At some point in all these many layers of code, these so called "high level" development kits *still* have to call the Windows functions to make things happen... so why not go right to the source?

Take a peek at my website... download the "Portable Editor"... note the file sizes.  Yes, that's a fully unicode enabled, drag and drop, 64 bit notepad in less than 128k .... and... almost a third of that (46k) is the high colour 256x256 Win7 icon.  You won't do that with high level libraries.

I think (perhaps incorrectly) that most people avoid the Windows API because they don't understand it. I would suggest that is a challenge to learn not a cue to run... but that's just me.

frankie:
The idea behind nuklear seems good, but the implementation is really poor.
Something declared as ANSI-C cannot have code in header files  >:(. This is the nemesis of a standard compliant code!
Said that, the code is clearly wrote using C++ habits in many other aspects. This leads to problems when using a C only compiler as PellesC (of course if you use VC it will happily compile).
To check the capability of this code I attach an hacked piece demonstrating GDI.

Navigation

[0] Message Index

[#] Next page

Go to full version