-
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
any way to use this live? #12
Comments
You're right: this module quite only serves for server side image manipulation (at least for now). You can probably copy the image data to some window frame buffer or something, in fact I've done this exact before by putting raw image data on a window opened using I do not have any experience with SDL, but I'll try looking into that. At the moment, WebGPU in Deno does not have any way to render to a window. There were little progress to support SwapChain for plugins which would allow rendering directly to a window, but as plugins died, so is the progress on that right now (which is pretty sad, I really wanted that...) Btw as for |
It seems like sdl2 does not really have support for in-memory images (so I would need to make a new image file every frame, which just sounds horrible for performance and disk-thrashing.) More than that it uses a funny TCP-based interop system (rather than ffi or native plugin) so I dunno, it may be kind of a bad path. I have worked with SDL in the past, in C, and could probly make a simple little lib in rust that has a really simple api:
I like your idea of winit, too, but I can't quite tell what is needed to draw an image on the window. |
Ok! Here is what I'm gonna do: I will make a deno FFI-wrapper lib for minifb that works with this lib. It has a very simple API, and is cross-platform. That way users can do offline rendering with canvas, as it is, or use that to make a window. Seems like a pretty good best-of-all-worlds solution, and it might be useful for other deno non-canvas things. Still not quite sure how to distribute my rust lib with the deno ts file. Will need to do some research. |
Hmm, I fought with it for a long time, and limitations in deno ffi (no buffers, strings or arrays!) and my lack of familiarity with rust made this super-hard for me. My start to it is here. I might come back to it, but this just seems impossibly stupid to get a really simple thing done. |
|
For this purpose, I've just added a |
That's awesome! How did you get it talking between deno & rust lib? That is where I gave up. I had a dumb little rust main that could popup a window like that, but couldn't figure out how to send a simple string for window-title, or a buffer that could be modified in deno-space. I guess I missed |
I think maybe my remaining issue is rust-side (and not knowing how to expose the right types), but it seems to me like this might be doable right now with a |
I updated deno_minifb to follow this, and it feels like I got a bit further, but I still get this error on deno-side:
This is with It's having issue with this: const lib = Deno.dlopen(path, {
window_new: {
parameters: ["buffer", "usize", "usize"],
result: "usize"
},
window_update: {
paramaters: ["usize", "buffer", "usize", "usize"],
result: "void"
}
}) for this: extern crate minifb;
use minifb::Window;
use minifb::WindowOptions;
#[no_mangle]
pub extern "C" fn window_new(title: &String, width: &usize, height: &usize) -> usize {
let win =
&mut Window::new(title, *width, *height, WindowOptions::default()).unwrap_or_else(|e| {
panic!("{}", e);
});
return win as *const _ as usize;
}
#[no_mangle]
pub extern "C" fn window_update(
window: &mut Window,
buffer: &mut Vec<u32>,
width: &usize,
height: &usize,
) {
window.update_with_buffer(&buffer, *width, *height).unwrap();
} |
Ah, sorry, just looked closer at your screenshot. You are using |
I've built Deno from this PR: denoland/deno#11648 also haven't got much far with rendering yet, there seems to be something up with window hanging up / not responding. I can PR my progress after cleaning it up |
So after investigating more, seems like |
It was |
So canvas buffer is for sure RGBA, but minifb seems to look for BGRA. I'm not sure how we can work around this.. |
I think it's RGB (they call it I found this in the comments of the source: fn from_u8_rgb(r: u8, g: u8, b: u8) -> u32 {
let (r, g, b) = (r as u32, g as u32, b as u32);
(r << 16) | (g << 8) | b
} Maybe the best thing would be to convert |
Ah, I think this probably has something to do with endianness since the |
Awesome! love to play with the code. |
You wanna PR to the deno_minifb library? |
Yeah, I'll do PR in a bit |
I think I would like to eventually add the other minifb stuff (mouse and key handling, mostly, would be useful.) Without the deno buffer PR being merged, and also no callbacks, it will probly take a bit for my lib to be useful, but it seems like a nice general but minimal cross-platform way to do this kind of thing in deno. |
I have some ideas for event loop for mouse and key handling stuff, I would love to help with that |
Like I said, rust is not my strong-suit. I will add you as a collab, and you can do whatever makes sense, no PR needed. |
Since this feature is gonna be implemented by external libs, I'll close this issue for now |
Lately, I have been working on node-raylib (it needs to be updated to latest raylib), as an alternative, so I am happy to transfer deno-minifb to you, since you are doing all the work on it, anyway! node-raylib isn't a nice familiar canvas API, but raylib runs very well on the pi, and is pretty simple to use, and node-raylib is still in javascript, so it should meet my needs of "easy to use library for making minigames on pi device", even if it does require learning a new js API to draw things on screen. |
@konsumer deno sadly does not run on a raspberry pi denoland/deno#2295. It helps to give that issue a 👍 if you want to see it worked on though |
bummer |
When I first saw this, I thought it might be a way to open a live canvas context and draw on the screen. It seems like from the examples, it's all offline (create canvas, draw on it, then save image.)
Is there interest in a live canvas? I am pretty new to deno & rust, but have dabbled with rust, and have a lot of experience with node. I'd love to help. It'd be awesome to be able to make a fast native game with roughly the same API as browser. What would be involved? Maybe sdl2 or something with webgpu?
The text was updated successfully, but these errors were encountered: