LiangliangNan / Easy3D

A lightweight, easy-to-use, and efficient C++ library for processing and rendering 3D data
GNU General Public License v3.0
1.35k stars 243 forks source link

WritePNG #157

Closed zhihaowangcg closed 1 year ago

zhihaowangcg commented 1 year ago

hello, I use the screenshot function and the saved PNG image has a very low resolution. Therefore, I want to save an image that is higher than the resolution of my screen display, how can I achieve that?

LiangliangNan commented 1 year ago

https://github.com/LiangliangNan/Easy3D/blob/e81a5f1ca8b15a92000bd01869e4477c994c4f86/easy3d/viewer/viewer.cpp#L1468 In the above function, multiple the width and height of the framebuffer by the same scaling factor (>1.0, e.g., 2.0, 5.0)) will do the trick.

zhihaowangcg commented 1 year ago

Thank you very much for your quick reply. Sorry, maybe the description of my previous question was not comprehensive. I'll describe it again now: When I use the snapshot function, the generated image is still blurred even when I enlarge the model to the maximum, so I'd like to ask how to generate a higher resolution image. By the method you just used, the resolution of the image can be increased, but the clarity of the image is not improved.

LiangliangNan commented 1 year ago

What do you mean by "clarity" of image? Can you show post your images here (Please show two images: one with the default resolution and the other one with the increased resolution)?

zhihaowangcg commented 1 year ago

easy3d easy3d1 Here I give the experimental results of Tutorial_201_Viewer_imgui, where easy3d is the result of the original program implementation and easy3d1 is the result of the implementation by the method you mentioned before. Here is the code I modified according to your previous method:

bool Viewer::snapshot(const std::string& file_name, bool bkwhite) const { int w, h; glfwGetFramebufferSize(window, &w, &h); ////////////////////////////////////////// double factor = 2.0; w = ceil(w factor); h = ceil(h factor); ////////////////////////////////////////// FramebufferObject fbo(w, h, samples_); fbo.add_color_buffer(); fbo.add_depth_buffer();

Although the resolution of the result is increased (800600->16001200), the display content is not correspondingly larger and the final image quality&clear is not improved.

LiangliangNan commented 1 year ago

Indeed, the viewer size was not changed accordingly.

Now I have enhanced the snapshot function and made the scaling factor an argument. The updated code is in the dev branch (NOT the main branch). You can specify it in the following line (changing 1.0f to 2.0f or any other number greater than 1.0f). https://github.com/LiangliangNan/Easy3D/blob/c0d33778dfda22322ac1320a7bbbe6ea1a6e4241/easy3d/viewer/viewer.cpp#L1464 Please let me know if it works (and if so, I will push the changes to the main branch).

zhihaowangcg commented 1 year ago

Now it does work! It would be more perfect if the related factor change could be implemented in the base class, e.g. ViewerImGui class. For example: explicit ViewerImGui( const std::string& title = "Easy3D ViewerImGui", int samples = 4, int gl_major = 3, // must >= 3 int gl_minor = 2, // must >= 2 bool full_screen = false, bool resizable = true, int depth_bits = 24, int stencil_bits = 8, int width = 1200, int height = 600, float scaling = 3.0f );

LiangliangNan commented 1 year ago

I would leave it to the users of Easy3D. In practice, people may want to increase the resolution after a preliminary one. So ideally it is expected to have a popup dialog asking the user to provide the relevant parameters.

I will close this issue now.

zhihaowangcg commented 1 year ago

Indeed, thank you very much for your help!