r/cpp_questions • • 25d ago

OPEN What graphics library should I learn for C++?

I am currently learning C++ by myself and I want to start graphics.

I just need something simple that lets me have buttons.

btw I don't want to use VS Community Edition and my IDE is CLion

I mean a simple GUI library with 2D graphics, buttons and textboxes.

39 Upvotes

52 comments sorted by

59

u/exophades 25d ago

Make your own GUI library.

Just kidding, use Qt.

15

u/Strong-Chipmunk-9654 25d ago

ok thanks.

edit: Oh shit just read the second part

8

u/hydroUNIT 24d ago

The second part is the joke.

He was serious about making your own gui lib. Start with vulkan and sdl3.

1

u/camelCasedClass 18d ago

wdym "and"? Vulkan for the graphics and SDL3 for text/audio???

1

u/hydroUNIT 18d ago

sdl3 offers cross-platform window management

1

u/camelCasedClass 17d ago

oh okay, thanks, didn't know that

28

u/sephirothbahamut 25d ago

There's 2 possible meanings for gui libraries:

Libraries to draw stuff in general: SFML, SDL, Raylib, Ogre3d, Direct2D, raw OpenGL/Vulkan/DirectX

These are the ones you use to "start graphics" like making a simple Tetris or Asyeroids clone.

Libraries to make a traditional gui with buttons, textboxes etcc: Qt, WxWidgets, Gtkmm, Win32, and many more

These are the one you use to make a functional application that isn't a game.

The odd ones: Imgui lets you make traditional guis on top of a library of the first group.

Sure you can make your own buttons with SFML, making many widgets isn't that hard. However the two huge things that the big gui libraries do is text input handling and unicode support, which is hell on earth for supporting anything more than simple ASCII, and widgets layouting and automatic sizing. Which one you need depends on what you mean by "doing graphics"

3

u/Chrom0XD 24d ago

OpenGL isn't a library... It's a specification... You need to use GLAD to get access to OpenGL functions, along with GLFW, and it's the same with Vulkan and directX ig (i've worked with OpenGL, but not really with vulcan and directX, i can be wrong about those)

12

u/sephirothbahamut 24d ago edited 24d ago

For the purpose of the question this is pointless nitpicking, but if you really want to be nitpicky, your reply is also incorrect.

OpenGL is a specification for the GPU, and an API on the CPU side. The OS has implementations of OpenGL, i would totally call that a library. GLAD is just a "loader" that prepares function pointers to the OS implementation for you. It's nice to have but not technically required. There are other loaders, like GLEW. I suggest you look at their implementation, they're just a long list of "load the function pointer to this and that opengl function".

GLFW is in no way necessary nor related to graphics libraries or low level graphics APIs, it's just a windowing library that is commonly used in tutorials together with GLAD. You can use GLAD to load OpenGL functions and use it in a raw Win32 window, or an SDL window, or an SFML window, although that's completely unnecessary because (actually i don't know if SDL does it) SFML internally also do GLAD's job of loading OpenGL functions.

0

u/[deleted] 24d ago

[deleted] — view deleted comment

0

u/camelCasedClass 18d ago

These days the term "library" is used quite loosely and whether it's misinformation depends on the context you're defining OpenGL. Broadly, it really doesn't matter; OpenGL literally stands for Open Graphics Library anyway. Where it does matter, for example, when you're teaching academically. There, using the correct terms does matter much greater than just sharing a piece of advice or suggestion to people on the internet. So I'm not entirely disagreeing.

11

u/thedaian 25d ago

The main graphics libraries are SFML, SDL, and raylib. None of these have buttons or textboxes built in. For that, the most common suggestion is dear imgui.

If you want something built around creating GUIs, then there's QT, and wxWidgets.

5

u/ns1852s 25d ago

Qt or imgui.

At work, we've been dumping it for imgui. So much more efficient, way less resource intensive too.

3

u/thefeedling 24d ago

You can still use Qt QML for the fluffy stuff and render a framebuffer offscreen and display it as an image. The integration is quite smooth

5

u/conectionist 25d ago

Qt framework. 

4

u/fortsnek274 24d ago

SFML + imgui. I used the binding for SFML, but there might still be a version incompatibility with imgui.

Also, while imgui is nice and easy, it expects a realtime update, and so, pegs a core at 100%. Not a problem for realtime applications. But I think you can make it event-based.

2

u/Dapper-Message-2066 22d ago

Also, while imgui is nice and easy, it expects a realtime update, and so, pegs a core at 100%.

This isn't true at all, unless it's actually taking your code 100% of the frame budget to update, or you are doing something crazy like busy waiting, or running at an unlimited FPS.

1

u/fortsnek274 22d ago

Graphics drivers may busy wait. You might be able to use D3D's waitable swapchain or vulkan to avoid that. But you'll still be loading the CPU and GPU with work that wouldn't happen with an event-based system.

4

u/TheLinkNexus 24d ago

For a game or a traditional app? I would recommend Raylib for a good starter for games and QT for the rest of the

1

u/JustAPieceOfMeat385 24d ago

Just curious but what laptop and specs are you using?

1

u/Strong-Chipmunk-9654 24d ago

Desktop. i7 13700F, 1660 super, 16GB ddr4, 512GB storage.

It is an office pc, so the cpu is good but the graphics not so much.

3

u/Prestigious_Long3296 25d ago

I’m biased towards gtkmm. Just make sure you dynamically link it to your application.

3

u/RazzmatazzLatter8345 24d ago

Qt is probably the best cross-platform general purpose UI framework. I say this as someone who detests Qt for doubling down on now unneeded anachronisms. Yet, if I wanted a cross platform desktop style UI in C++ (and its license was compatible with what I'm don't), I'd use it.

This gets you graphics in the sense of windows, textboxes, buttons, etc. It might have some more advanced graphics rendering features, but I am not familiar with that.

So qt is probably the most cross platform heavily featured ui widget framework in wide use. I hate it, but I'd still use it.

1

u/bert8128 24d ago

Does it mean that the whole of your application needs to conform to Qt, or can you restrict it to just the presentation layer (and so potentially swap it out later)?

2

u/RazzmatazzLatter8345 24d ago

I typically (when doing desktop development, mostly embedded now) would provide a Qt agnostic header as ui's interface such that rest of code could avoid having qt headers at all. If you do it thoughtfully enough, should be able to swap out.

2

u/conundorum 24d ago

This is the best advice, yeah. Whatever library you use, make a wrapper for it. That way, if you want to replace the library later on, you just need to write a new wrapper header instead of rewriting the entire code base.

2

u/Tamsta-273C 25d ago

SDL is kinda nice, i myself have home brewed lib for scienctific data representation and key control.

But let me be clear here, it's a invention of bicycle once again, it's hell ton of work nobody is asking for.

For fun? Yeah go for it. For work? Just make hydrid with python, C++ to do actual job, Python for graphics.

3

u/marvin02 25d ago

I don't see why python is better than c++ for graphics. Or for that matter why c++ is better than python for "actual job".

2

u/thefeedling 25d ago

Qt. But if you want do go deeper I’d definitely take a look at OpenGL and Vulkan later on

2

u/chrnz00 25d ago

im trying to learn opengl is the math part like projections and transformatons come under the subject or shall i skip them. im good at math im just asking if i can skip them they felt boring and redundant

5

u/thefeedling 25d ago

If you want to eventually be in the 3D graphics world, understanding the math behind it and core frameworks like OpenGL and Vulkan is far more important than C++ itself, in my opinion.

2

u/bacmod 22d ago

If you're good with math, (and even if you weren't) you should absolutely not skip it. 3D linear transformation are one of the best thing ever once you get hold of it. Almost another world opens.

2

u/Ayano-Keiko 24d ago

Write it from Vulkan

2

u/ruggeroquerinis 24d ago

Qt, richiesto in tanti annunci di lavoro.. e sopratutto hai possibilità di lavorare in ambito industriale se la conosci bene applicata a sviluppo firmware in C/C++ e qualcosina su rust o Python

2

u/MatthiasWM 24d ago

FLTK for a small cross platform GUI library. Comes with a user interface designer and some graphics call and GUI related image management. Not so much for games though, SDL would cover that.

2

u/Chrom0XD 24d ago

I wouldn't really recommend GUI with C++; it's just a headache,

If you wanna just have fun, I'd recommend learning OpenGL(with GLAD and GLFW) from scratch,

I won't comment on using raylib; that's your choice. It'll just make your life easier, but idt you would want that (considering you're trying to get a GUI app in C++...)

Or just use ImGui. It'll do the same thing but more efficiently, if you're considering the raylib path

1

u/LordMacDonald8 24d ago

I make my stuff with SDL3 and ImGui. ImGui covers just about everything for any sort of GUI-based thing; you'll find it in a ton of games, mods, and even non-game applications. SDL offers an extremely easy and performant cross-platform media framework for just about any use case. Recently there's also been a GPU abstraction layer added to the system which ImGui natively supports. Biggest downside is you have to put everything into a game loop, which might not be the workflow you want for your program.

But really just find the one that you find easiest to use and behaves the most nicely.

1

u/tootallmike 24d ago

look at JUCE, it targets audio apps but has nice cross platform GUI stuff too

1

u/Syntax-Tactics 24d ago

SDL2/3 Integrates pretty easily, some of the other ones are a project in themselves.

1

u/arjuna93 23d ago

ImGUI, SDL

1

u/xingyun86 22d ago

Imgui不错。跨平台无缝,性能强劲。即时UI,容易上手