-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Exporting as Image #89
Comments
This will be possible after we merge #80. The PR introduces a If you need it right now, you could try using the |
This is great work! When do you think you’ll merge it into master? |
I can try to merge it in a bit! It should be a matter of resolving conflicts and writing docs for the new |
Done! The changes should be now in EDIT: By the way, the current |
Awesome, thanks! I won’t get a chance to test until some time, but will definitely let you know if there are issues |
Would you provide some documentation on how to draw a mesh to a canvas within the Game::draw method? I'm not sure if its a bug, but I can't seem to save an image that has the content of the mesh, i.e. the image always comes out as solid black. let width = frame.width() as u16;
let height = frame.height() as u16;
let gpu = frame.gpu();
let mut canvas = Canvas::new(gpu, width, height).unwrap();
mesh.draw(&mut canvas.as_target(gpu));
let image = canvas.read_pixels(gpu);
image.to_rgb().save("test.png").unwrap(); ^This is my current code. |
Oh, that should work. I think I know what is going on: Could you try drawing on the canvas in one frame, and then reading the pixels and saving the image during the next one (i.e. in different |
I have been able to reproduce the issue and fix it in #92. Let me know if it works, and we will merge it! EDIT: By the way, remember to clear the canvas before drawing! You can use |
Awesome! My code seems to work now! And I believe it does clear on creation (happens every frame) since I don't explicitly call clear and no artifacts carry over between frames. However, would it be more performant to create and draw to one canvas instance which would be used repeatedly across frame calls? I don't particularly need the performance for image exporting since the event occurs rarely, but I'm still curious. |
Are you exporting multiple frames in a row? In that case, yes. It would avoid allocating/deallocating a new texture every frame. However, if you want to keep the canvas size in sync, you will need to worry about recreating it whenever the window is resized. Also, be aware that exporting every frame can quickly perform a lot of write operations. If you are exporting a single frame rarely as part of a UI interaction, creating the canvas on demand just to save it afterwards should be perfectly fine. |
This is probably outside of the scope of the game engine, but is it possible to use the current target or frame as an image type from the Image crate? My goal is essentially to save the frame as an image file. Thanks
The text was updated successfully, but these errors were encountered: