-
Notifications
You must be signed in to change notification settings - Fork 591
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
How to draw images with rawfb? #46
Comments
I think https://github.com/Immediate-Mode-UI/Nuklear/blob/master/demo/x11_rawfb/nuklear_rawfb.h#L1010 I hacked around it like this to make an NK_API void
nk_rawfb_drawimage(const struct rawfb_context *rawfb,
const int x, const int y, const int w, const int h,
const struct nk_image *img, const struct nk_color *col)
{
struct nk_rect src_rect;
struct nk_rect dst_rect;
src_rect.x = img->region[0];
src_rect.y = img->region[1];
src_rect.w = img->region[2];
src_rect.h = img->region[3];
dst_rect.x = x;
dst_rect.y = y;
dst_rect.w = w;
dst_rect.h = h;
if (img->handle.ptr == NULL) { // probably a dangerous assumption?
nk_rawfb_stretch_image(&rawfb->fb, &rawfb->font_tex, &dst_rect, &src_rect, &rawfb->scissors, col);
return;
}
struct rawfb_image rimg = {
.pixels = img->handle.ptr,
.w = img->w,
.h = img->h,
.pitch = img->w*sizeof(uint32_t),
.pl = PIXEL_LAYOUT_XBGR_8888,
.format = NK_FONT_ATLAS_RGBA32,
};
nk_rawfb_stretch_image(&rawfb->fb, &rimg, &dst_rect, &src_rect, &rawfb->scissors, &nk_none);
} Then using it: void *ptr = <raw RGBA buffer>;
struct nk_image img = nk_image_ptr(ptr);
img.w = w;
img.h = h;
img.region[2] = w;
img.region[3] = h;
nk_image(&ctx, img); Other bits that tripped me up for a while:
|
This is great feedback! Could you please make a PR with the suggestions and findings? The backends are mainly for demonstration purposes as everybody has slightly different needs. Therefore they might be incomplete or less tested. Our main focus is on the library itself (just |
Will do, but I've hacked around elsewhere too, such as extending nk_rawfb_init for loading other fonts, and adding an endianness check. Something PR-worthy may come out of it eventually! In my case rawfb is drawing directly to an SDL2 streaming texture, which is then displayed over a window background drawn with the vanilla SDL2 renderer. |
Fwiw, I've failed to get around to doing a PR for rawfb and probably won't now, sorry. Ended up replacing most of the rawfb code with Cairo software rendering: https://github.com/seanpringle/nuklear_cairo |
No problem. Btw. feel free to make a PR with x11-cairo backend (or wayland-cairo - didn't look at the source, so don't know which one 😉) - we're not strict about backend implementations and merge anything what makes sense for future users. Cairo is certainly an interesting backend! |
I am trying out Nuklear on a raw frame buffer (boot loader environment - U-Boot).
I can see examples of how to create an nk_image and draw it for openGL, but I cannot figure out how it works with nuklear_rawfb.h
It seems to draw fonts but I am not sure how to make it draw images. Is there an example?
The text was updated successfully, but these errors were encountered: