Skip to content
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

Preventing black screen while refreshing text #20

Open
unre4l opened this issue Mar 29, 2021 · 5 comments
Open

Preventing black screen while refreshing text #20

unre4l opened this issue Mar 29, 2021 · 5 comments

Comments

@unre4l
Copy link

unre4l commented Mar 29, 2021

Hi,
i measure values every second an print them onto the screen. To clear old values i first fill the screen black and then draw the text. That results in a visible "refresh" effect, everything is black and the text slowly appears again line per line.
Is it possible to draw everything in a frame buffer and then paint the screen at once? So that there isn't a completly black screen for one frame. Thanks and cool library!

@nopnop2002
Copy link
Owner

nopnop2002 commented Mar 29, 2021

Is it possible to draw everything in a frame buffer and then paint the screen at once?

What is a frame buffer?
Do you mean all Pixel data?

If you want to partially rewrite the text on the screen, write the same text in the same color as the background and it will disappear.

uint16_t color;
lcdFillScreen(dev, BLACK);
uint8_t ascii[20];

color = RED;
strcpy((char *)ascii, "Direction=0");
lcdDrawString(dev, fx, 0, 60, ascii, color);

.
.
.
.

color = BLACK;
strcpy((char *)ascii, "Direction=0");
lcdDrawString(dev, fx, 0, 60, ascii, color); // text is disappear.

@unre4l
Copy link
Author

unre4l commented Mar 29, 2021

Do you mean all Pixel data?

Kind of. My goal is to have:

Frame 1     ->   Frame 2
| text A |       | text B  |  

But what is possible is:

(draw text)      (draw clearing rect)       (draw text)
Frame 1     ->   Frame 2               ->   Frame 3
| text A |       |        |                 | text B  |  

If you want to partially rewrite the text on the screen, write the same text in the same color as the background and it will disappear.

Thanks for the example, but unfortunately it wont solve the problem. The frame inbetween the text draw calls has to be a black rectangle (or black text) to clear the previous text. So there is always one frame before new text can appear.
If one could write all pixel data in a buffer[screen_x][screen_y] and swap all pixel in one draw call, a refresh frame to clear old data wont be necessary, because one can clear and draw on the buffer and flush at once to the screen so no intermediate frame would be visible.

@nopnop2002
Copy link
Owner

nopnop2002 commented Mar 29, 2021

If one could write all pixel data in a buffer[screen_x][screen_y] and swap all pixel in one draw call,

There is lcdDrawMultiPixels().
You will draw RED square.

uint16_t PixelData[16][16];

for (int x=0;x<16;x++);
  for (int y=0;y<16;y++);
    PixelData[x][y] = RED;
  }
}

for (int y=0;y<16,y++) {
  lcdDrawMultiPixels(&dev, 0, y, 16, PixelData[[0][y]);
}

The generator for text bitmaps is GetFontx().

@unre4l
Copy link
Author

unre4l commented Mar 30, 2021

The lcdDrawMultiPixels solves my problem. Thanks!
I scrolled through your code and found an even simpler solution.

//if (dev->_font_fill) lcdDrawPixel(dev, xx, yy, dev->_font_fill_color);
This line does exactly what i was looking for. Although refreshing is slower, there is no flickering! 👍

@nopnop2002
Copy link
Owner

This is done if _font_fill is valid:

if (dev->_font_fill) lcdDrawFillRect(dev, x0, y0, x1, y1, dev->_font_fill_color);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants