aviks / minifb.jl Goto Github PK
View Code? Open in Web Editor NEWRender pixels on screen
License: MIT License
Render pixels on screen
License: MIT License
minifb appears to compile perfectly fine on Alpine Linux with or without the CMake -DUSE_WAYLAND_API=ON
option.
Might be an init problem?
MWE: Execute the following step-by-step:
window = mfb_open_ex("my display", 800, 600, MiniFB.WF_RESIZABLE)
mfb_update(window, rand(Int32, 800, 600))
mfb_update(window, ones(Int32, 800, 600).*typemax(Int32))
mfb_update(window, zeros(Int32, 800, 600))
The first call to mfb_update
doesn't seem to do anything -- you'll only see a while and then a black screen.
Clicking the close button on a running window kills the REPL. Ctrl-C in the REPL stops the process updating the window but doesn't close the window. Clicking the close button in this case does not kill the REPL.
Julia Version 1.5.1
Commit 697e782ab8 (2020-08-25 20:08 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: AMD EPYC 7702P 64-Core Processor
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-9.0.1 (ORCJIT, znver2)
Environment:
JULIA_NUM_THREADS = 64
JULIA_EDITOR = "/usr/share/code/code"
When attempting to modify a field in a struct variable that is captured from the enclosing scope MiniFB crashes. If the struct variable is global then MiniFB doesn't segfault.
See the function onkeypress below for the assignment that causes the segfault.
version info:
Julia Version 1.5.2
Commit 539f3ce943 (2020-09-23 23:17 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: AMD EPYC 7702P 64-Core Processor
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-9.0.1 (ORCJIT, znver2)
Environment:
JULIA_NUM_THREADS = 64
JULIA_EDITOR = "/usr/share/code/code"julia> using MiniFB
minimum working example:
julia> mutable struct Simple
a::Float64
end
julia> function mwe()
width = 600
height = 600
window = mfb_open_ex("Luxor -> MiniFB", width, height, MiniFB.WF_RESIZABLE)
t = Simple(1.0)
function onkeypress(window::Ptr{Cvoid}, key::mfb_key, mod::mfb_key_mod, ispressed::Bool)
t.a += 1 #this causes the segfault. If t is a global variable no segfault
return nothing
end
mfb_set_target_fps(60)
mfb_set_keyboard_callback(window, onkeypress)
while mfb_wait_sync(window) # The Luxor `@imagematrix` macro creates a 2D matrix of Color objects in ARGB32 format, which is exactly what MiniFB requires
buffer = Luxor.@imagematrix begin
Luxor.background("grey40")
end 600 600
# The image matrix created by Luxor is, in standard Julia convention, column first. The buffer
# expected by MiniFB is row first. The call to `permutedims` makes that change.
state = mfb_update(window, permutedims(buffer, (2, 1)))
# Exit when the user closes the window.
if state != MiniFB.STATE_OK
break
end
end
mfb_close(window)
end
mwe (generic function with 1 method)
julia> mwe()
Window created using X11 API
signal (11): Segmentation fault
in expression starting at REPL[5]:1
unknown function (ip: 0x7f7e8800cfc3)
Allocations: 11027408 (Pool: 11024513; Big: 2895); GC: 24
Segmentation fault (core dumped)
julia> using MiniFB
julia> include(joinpath(pathof(MiniFB),"..","..","example","Plasma.jl"))
Window created using X11 API
# closed the window with esc after a couple seconds
julia> macro m()
end
malloc(): mismatching next->prev_size (unsorted)
signal (6): Aborted
in expression starting at none:0
The example used in the repository for minifb uses the function mfb_update_ex
. This function slightly differs from from mfb_update
, as it includes 2 extra arguments stating the current size of the frame buffer.
Why is this function missing from the Julia API? I could not locate the function within the dylib located within the Artifacts folder.
Thanks!
Might be nice to catch that somehow so it just throws an error.
Is there a way of checking the window is still open, or can we set a callback for when it closes?
Tried to run the code example here: https://juliagraphics.github.io/Luxor.jl/dev/howto/livegraphics/
("Open and run the first window in its own thread:")
Got this:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow should only be instantiated on the main thread!'
*** First throw call stack:
libc++abi: terminating due to uncaught exception of type NSException
[30629] signal (6): Abort trap: 6
in expression starting at none:0
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
I find that closing the window created by MiniFB using the Close button works OK, but if I press Escape, the Julia process seems to get "stuck". Is there a way of disabling or ignoring Escape?
Might be a Mac-only thing i suppose..
I'm trying to get mouse button and key press information for the window without using callbacks.
I'm using the following functions:
mouse_button_buffer = MFB.mfb_get_mouse_button_buffer(window)
key_buffer = MFB.mfb_get_key_buffer(window)
They both are of type Ptr{UInt8}
. How do I actually use them to know if and which a key / mouse button has been pressed?
Also, nothing seems to happen to the unsafe_load
ed values when I press or mouse buttons or keyboard keys. Is that the correct way to use these functions?
Full code available at https://github.com/Sid-Bhatia-0/SimpleIMGUIExample/tree/00e52da38c97e0753711fe9d8c1d546239461e04.
Which makes it somewhat annoying to develop on the REPL. However, calling a second mfb_window_open
will clear up the old window and launch the new, so iterative development is still possible. The other option is to always run from the shell.
Asked upstream: emoon/minifb#44
First of all, thank you for creating this wrapper package. I really like the simplicity of minifb.
On the minifb repository, I see commits in the source code that are more recent than the last release of MiniFB.jl
.
I am not familiar with how MiniFB.jl
was created from minifb, so this is a beginner level question. I am curious to know when and how would MiniFB.jl
incorporate changes from the original minifb library? I saw that there is MiniFB_jll, but even over there, the last commit seems to be long back.
Thanks.
When I install MiniFB on julia 1.8 (taken the original binary build from the official julia website) I get the following error.
julia> mfb_open_ex("My Window", 400, 400, MiniFB.WF_RESIZABLE)
libGL error: MESA-LOADER: failed to open radeonsi: /usr/bin/../lib/julia/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /usr/lib/dri/radeonsi_dri.so) (search paths /usr/lib/dri, suffix _dri)
libGL error: failed to load driver: radeonsi
libGL error: MESA-LOADER: failed to open swrast: /usr/bin/../lib/julia/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /usr/lib/dri/swrast_dri.so) (search paths /usr/lib/dri, suffix _dri)
libGL error: failed to load driver: swrast
X Error: BadMatch
Request Major code 150 (GLX)
Request Minor code 5 ()
Error Serial #41
Current Serial #41
Replacing the symlink in /usr/lib/julia for libstdc++.so.6
which points to libstdc++.so.6.0.29
with the system library (libstdc++.so.6.0.30
) I can get MiniFB to work.
cd /usr/lib/julia/
sudo rm libstdc++.so.6
sudo ln -s /usr/lib/libstdc++.so.6.0.30 libstdc++.so.6
[cc649173] MiniFB v0.1.1
Julia Version 1.8.0
Commit 5544a0fab76 (2022-08-17 13:38 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 16 ร AMD Ryzen 7 5700X 8-Core Processor
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-13.0.1 (ORCJIT, znver3)
Threads: 1 on 16 virtual cores
Would you be interested in having helper methods to set the callback functions which automatically create the function pointer with @cfunction
? Since the signature is fixed by the library we can just assume that the user is passing a valid method.
Eg. we could define:
function mfb_set_keyboard_callback(window, keyboard::Function)
keyboard_c = @cfunction(keyboard, Cvoid, (Ptr{Cvoid}, mfb_key, mfb_key_mod, Bool))
mfb_set_keyboard_callback(window, keyboard_c)
end
Let me know if that would be good to have, and if the naming, or something else would need to be changed
I am not able to produce a partially transparent drawing, no matter which value for alpha i use
example:
using MiniFB
WIDTH=800
HEIGHT=600
window = mfb_open_ex("My Window", WIDTH, HEIGHT, MiniFB.WF_RESIZABLE)
buffer = zeros(UInt32, WIDTH*HEIGHT)
alpha = 0
while true
x = reinterpret(UInt32, [UInt8(100),UInt8(0),UInt8(0), UInt8(alpha%255)])[1]
alpha += 1
buffer = fill(x, WIDTH*HEIGHT)
state = mfb_update(window,buffer)
if state != MiniFB.STATE_OK
break
end
end
How do i detect if a key is held down on every new frame, rather than having to wait for the keyrepeat to kick in?
When testing the example Noise.jl on wayland the window does not close after pressing the close button.
The function noise()
however is terminates.
[cc649173] MiniFB v0.1.1
Julia Version 1.8.0
Commit 5544a0fab76 (2022-08-17 13:38 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 16 ร AMD Ryzen 7 5700X 8-Core Processor
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-13.0.1 (ORCJIT, znver3)
Threads: 1 on 16 virtual cores
wayland 1.21.0-1
This is on OpenBox on X11 and Linux, with Julia 1.5.1, running the "plasma" example.
The window comes up and I can see the visualization. Clicking on the window's "close" button does nothing. Forcing it to close from the window manager, I get this:
julia> plasma()
Window created using X11 API
X connection to :0 broken (explicit kill or server shutdown).
0[~] $
julia> plasma()
Window created using X11 API
XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":0"
after 1481 requests (1477 known processed) with 0 events remaining.
0[~] $
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.