Open heartsg opened 4 years ago
I'm interested in this topic since I also do graphics programming just like many other programmers around the globe.
As of now (v1.7.4), nana's graphics implementation is written in files inside source/paint
folder. By looking at graphics.cpp
, we would instantaneously realize that nana uses graphics device interface (GDI) on Windows, and Xlib on other platforms.
The functionalities that GDI and Xlib offer are somewhat primitive, as they were implementated around decades ago. They are very popular and surely not deprecated yet but seems pretty outdated. The good thing about them is they are widely supported, also not so difficult to use.
I suppose professional game developers use popular game engines like Unreal Engine or Unity. Those game engines's developers know quite a lot about modern 3D computer graphics, DirectX, OpenGL, Vulkan and so on. So anyone who seriously want to code cutting-edge staffs, they should never rely on nana's graphics routines because nana's graphics routines are primarily purposed to render gui widgets.
Aside from hardcore professionalism, there are a lot of alternative ways to draw images on computer screen. Personally, I still use GDI on Windows and recently (around an year-ish ago?) started using Direct2D. And just today, I tried Skia.
Here's the sample code to use Skia.
I've thought building the library would be time consuming so I obtained skia.lib
via https://github.com/rust-skia/skia-binaries
There are advantages and disadvantages in every decisions. For example, if nana would use Skia library, its binary size will increase for sure.
I just found out that paint::pixel_buffer
has a limited ability to rotate an image. It can only rotate counterclockwise, without clipping.
paint::image img {"path/to/image"};
paint::graphics g_img {img.size()};
img.paste(g_img, {0, 0});
paint::pixel_buffer pixbuf {g_img.handle(), rectangle{img.size()}};
paint::pixel_buffer rotated {pixbuf.rotate(45, colors::white)}; // 45 degrees angle
Rotation is almost a defecto implementation for any simple game engine. For example, for python pygame, you can use
pygame.transform.rotate
to rotate an image.nana has a beautiful interface which is quite attractive as an alternative framework to teach children programming skills by games (the others include python & scratch). It's probably better to extend the paint & graphics functionality a little bit.
I did a simple experiment according to (which uses HDC and HBITMAP), https://www.codeguru.com/cpp/g-m/gdi/article.php/c3693/Rotate-a-Bitmap-at-Any-Angle-Without-GetPixelSetPixel.htm,
Using the current interface provided (I am not sure whether this is the best way or not), it seems too troublesome.