Graphics Library with real-time display in Julia?

There are a lot of (excellent) libraries to static vector graphics. A lot of them have functionality to play the graphics back as gif or animations.

I want to make a real-time simulation. Perhaps think of it as a game dev project? With sprites interacting as per a certain rules, with a certain amount of user interaction to be needed.

I have considered GLMakie but it’s a very heavy library and a little slow. I might be doing things inefficiently but just for the sake of knowing… Are there any better libraries than Makie? I don’t want there to be ugly plot axes laying around. A good time control (frame by frame animations kinda thing?) Stable fps. High speed.

Can anyone help?

I have had some moderate success using Cairo.jl, which is better suited to low level graphics operations than Makie. I recall figuring out a way to get it to render frames in real-time to a Gtk window in real-time using Gtk.jl, with user interaction (like clicks), although I don’t recall the exact details. I might be able to dig up my old code if you’re interested.

I also have used Layered.jl which is an interesting approach to 2D rendering, adding vector graphics to 2D layers and composing them together (based on Cairo I believe?). Not sure it’s got real-time capabilities, however.

2 Likes

Maybe GameZero.jl could be useful in your case for a game-like interface.

Usually I like using Pluto notebooks with PlutoUI.jl combined with Plots or Makie for interactive visualization, but this may not be what you’re looking for.

GLMakie works well for me (flight simulator), but you have to make sure not to create objects in a loop, but just to move and turn them…

Hehe funny to see Layered.jl mentioned, that’s what I was doing before Makie. Haven’t looked at it in ages but got some nice graphics out of it at the time. Was less meant for plotting, more for artsy things

1 Like

Oh, that’s surprising, please report! GLMakie should be one of the fastest plotting libraries on the market… If not it should be a bug, or wrong usage :wink:

1 Like

Btw, there is GitHub - ashwani-rathee/Miner.jl: Voxel World Simulator written with Makie in Julia, which is using Makie for Minecraft and it works quite well :wink:

3 Likes

Please do! I would very well love that.

Layered.jl… hmmmm My first idea was something similar… using Luxor to creat svgs and stack them on top of each other. Never figured out how to do that. (yes I know I’m a noob, I have used Julia for a very short amount of time. Hoping to learn :))

Did you ever figure out how to play them back in real time… as if a live video preview?

yeah isn’t exactly what I want. Also, GameZero isn’t the most optimum thing to use… as the creators themselves said it’s just a means for beginners to learn.

Exactly… I looked into Observables… Kinda got over my head tbh. But in any case…

Say I want to animate a bunch of dots fade into the screen one after the other. I would use a for loop like for dot in 1:100 create(dot). Or something. But that’s too slow and laggy.

Hey btw… this might be a totally dumb question and forgive me but…

Is Cairo capable of making videos or just static images?
Like in pretty much all the libraries I’ve seen that create animation, Cairo is used to create the images. And then they are stacked into a video using FFMPEG.

Which is almost all I want except I don’t want to do it as a pretender. But a real time one!

That is probably the case… I’ve mentioned the thing I’m doing in a reply above. But also, I am really confused with how to time things with a clock in Makie. The Minecraft thing blew my mind off though! JEEZ!

1 Like

On second thought… Can I actually use Plots.jl without the axes on the screen? How do I turn them off?
I figured Makie uses it under the hood anyway. Wouldn’t it be better? And again… How then do I make Real-time Simulation out of it… Say of a bunch of particles moving around (While experiencing gravity doe to one another)

By any chance mate, do you (or anyone else?) know how they even create these windows to preview images? Can’t I simply use native Julia code to create a window or something and put information into the buffer (No idea what that is… just some gibberish I saw online)

You can try imgui + implot for complex interactive GUIs: Julia MWE using CImGui.jl and ImPlot.jl · GitHub

1 Like

Here’s something with GLMakie you can play around with:

using GLMakie
using GLMakie.Makie.Animations


scene = Scene(camera = campixel!, resolution = (600, 600))
points = map(a -> 300 .+ 200 .* Point2f(cosd(a), sind(a)), 1:3:360)
t = Observable(0.0)

anim = Animation([0, 2], Makie.to_color([:transparent, :red]), sineio(; n = 2, yoyo = true))
loop = Loop(anim, 0, 0, typemax(Int))

colors = lift(t) do t
    map(eachindex(points)) do i
        loop(t + i/30)
    end
end
scatter!(scene, points, color = colors)

screen = display(GLMakie.Screen(), scene)
start = time()
@async begin
    while isopen(screen)
        t[] = time() - start
        sleep(1/30)
    end
    println("done")
end

2 Likes

Raylib is the other alternative: GitHub - chengchingwen/Raylib.jl: Julia wrapper for the raylib videogames programming library

Here is an example: Active Ball Regressor · GitHub

1 Like

You mean Makie uses Plots.jl under the hood? Certainly not ^^ GLMakie uses OpenGL “under the hood” :wink:

1 Like

Why is it a dependency then?