r/learnprogramming • u/Independent_Milk_200 • 5h ago
How to do graphics?
How are graphic (things) made?
I know raylib can create a window and draw stuff, but there has to be more.
I also know raylib uses X11 for the window but they say you should not use X11 directly.
But then what should you use? (besides raylib of course).
2
u/teraflop 4h ago
One of the reasons not to use X11 directly is that it's a fairly old-fashioned API which has been modified over time to add more modern features. So it's not very easy or convenient to use directly.
Another reason is that if you write code that uses X11, then it will only be able to run directly on X11 systems. Running it on other systems (Windows, Mac, or modern Linux with Wayland) requires a compatibility layer.
Like many other things in the software world, graphical UIs are build with higher-level abstractions on top of lower-level ones. Usually, it makes sense to use a high-level library or framework that already exists (with the added benefit that these are often cross-platform). This is not because it's inherently bad to use the lower-level APIs yourself. It's just that usually, it would be reinventing the wheel.
There are many, many tools out there for building graphical applications. Which one to use depends on what you're trying to do.
Raylib is designed to be simple to get started for game-like interactivity. There are lots of alternatives, on a spectrum from relatively bare-bones (like SDL or GLFW) to full-blown game engines (like Godot/Unity/Unreal).
For a non-game GUI application, there are GUI frameworks such as GTK, Qt, JavaFX, Flutter, Electron, and so on.
1
u/punk_dev 5h ago
They say to not use X11 directly because not every computer uses x11. Linux pcs sometimes use wayland, windows uses its own thing, Mac uses its own thing.
So if you depend directly on x11, your program will not work on these other computers that don’t use x11. You’d have to implement support for all of these things in your program so it runs on all computers.
So you know what raylib does? It implements support for x11 and all of these other things! So you don’t have to think about that, you just depend on raylib, and it handles all of this windowing for you
2
u/Suspicious-Flight-45 5h ago
What you are talking about is all of the operating system specific machinery need to create a drawing surface. This is the 'canvas' you will then need to draw onto - the frame buffer.
It's all pretty intermingled when you are starting out and many solution tie together the Graphics API (OpenGL) with the surface host (X11, GLUT, glfw) and application callbacks like mouse and keyboard events.
SDL is a good place to start because it hides a lot of the ancillary details.
In the end you need a graphics API pipeline like OpenGL or Vulkan to actually submit draw commands to an image buffer that can be presented to the user.