Drawing/updating custom widget as a pixel array

Two questions:

What is the best way to draw/update a custom widget (using its NanoVG context) using a “pixel approach”; in other words I have the pixels in a bidimensional int array (ARGB format) and I would like to transfer it to the widget as fast as possible? Is there an example somewhere?

How many times per second the draw( args ) is called?

Thank you in advance!

surface to surface blitting (you write offscreen and blit at redraw time)

the redraw is 60 times a sec (but if IIRC can be changed)

the default offscreen widget is a good example

Thank you; what nanovg api do you mean with “blit” ? I searched for “nanovg blit”, but found nothing.

Also searched for “offscreen” (widget) in the VCV source code but found nothing. Is it a plugin ?

maybe the correct name is something like TransparentBuffer? All the VCV controls use it. Also, my “colors” plugin basically blits a random monochrome bitmap onto the screen, so It’s a super easy to understand way to do this:


Super dumb code is here: SquinkyVCV/NoiseDrawer.h at main · squinkylabs/SquinkyVCV · GitHub


Thank you! I’ll try with:

void myDrawImage(NVGcontext* vg, float x, float y, float w, float h ) {
  static int img = -1;
  if ( img == -1 ) {
    img = nvgCreateImageRGBA(vg, IMG_SIZE, IMG_SIZE, 0, data);
  } else {
    nvgUpdateImage(vg, img, data);
  imgPaint = nvgImagePattern(vg, x, y, w,h, 0, img, 1.0f);
  nvgRect(vg, x, y, w, h);
  nvgFillPaint(vg, imgPaint);
1 Like

Yeah, once you discover that the basic things it to put a bitmap in memory and use “fill” to blast part of it onto the screen then the rest can be figured out with tinkering and asking the internet. At least that’s the approach I used :wink:

1 Like