I will provide you with some examples of how to use VGA functionalities, including how to manage page buffering for transparent text or moving objects. However, before proceeding, it's essential to update the firmware. This update is necessary to run the examples I'll be demonstrating.
You can perform an over-the-air (OTA) update of the firmware using the following link:
[Local Link Removed for Guests]
To update, copy and paste this link into the configuration page, then click SAVE and then click on OTA update.
The new firmware brings several enhancements, notably the ability to import 16-bit BMP images. These images are about 30% smaller compared to 24-bit images and come in either 565 or 1555 formats, supporting a transparent background.
This format proves highly advantageous for importing images on top of others, creating a delightful superposition effect.
I have also added the capability to save images to disk using the command "VGA.SAVE "filename.bmp"," but be mindful that each image occupies approximately 600KB at a resolution of 640x480 so you risk to saturate the internal flash disk rapidly.
For efficient storage and retrieval, I strongly recommend using an SD card, which is significantly faster.
To proceed, it's necessary to provide some preliminary theoretical explanations. First and foremost, the VGA output represents a portion of dedicated memory for the projected image. This memory can be modified to alter the image displayed on the screen. The memory's structure is such that each pixel occupies 8 bits, equivalent to 1 byte.
The system employs a color format known as "332". In this notation, 3 bits are allocated to the red channel, another 3 bits to the green channel, and 2 bits to the blue channel. Thanks to this configuration, up to 256 distinct colors can be represented.
The choice of this color format is a compromise between efficient use of memory, chip resources and the number of GPIOs used..
It's important to note that the ESP32 has a limited amount of memory available. For instance, to support a resolution of 640x480 pixels, approximately 300KB of memory is required. This constraint presents a significant challenge, in particular when the memory is already used for the other functionalities (Wifi, disk, ...).
Fortunately, the ESP32-S3 variant offers the capability to utilize DMA mode on external PSRAM memory. This choice opens doors to a potential additional 8 megabytes of memory. Nonetheless, it's crucial to recognize that access to this external memory is slower than internal memory, affecting the overall system performance.
Despite this limitation, the expanded memory provided by the external PSRAM—amounting to 8 megabytes—enables the creation of different memory "pages,". This approach facilitates writing to one page while displaying another, allowing for smooth and visually smooth transitions for users.
Additionally, images can be imported in JPEG and BMP formats. In the case of BMP format, the feature to import images with transparent backgrounds has been added. This feature allows for seamless image overlaying without any visible edges and paving the way for image usage as objects (sprites) that can be animated fluidly.
Traditionally, to create the display, various parts that are intended to be shown are drawn on the screen. Consequently, a user observing the screen will see these objects draw one after another. This effect can be unpleasant, particularly when updating text of significant size, such as a long text. In such cases, users cannot help but notice a bothersome "flash" as the complete update unavoidably takes time.
To surpass this limitation, a straightforward mechanism can be implemented using three distinct pages.namely page 0, page 1, and page 2). Initially, a background image is loaded into Page N°2, which serves only as a reference. Subsequently, this image is copied to Page 0, and all parts to be overlaid onto the image are drawn. At this point, the composed image is displayed on the screen. From here onwards, copying Page N°2 into Page 1 can be performed, with all overlaid parts being redrawn while the user continues to observe Page 0. As soon as the content of Page 1 is completed, the content of Page 1 can be shown to the user. Then, the process repeats by copying the content of Page N°2 into Page 0, and so on.
This approach circumvents the intermediate updates that caused user disturbance, offering a continuous and seamless visual experience.
This first example try to show this process :
Code: [Local Link Removed for Guests]
''demo transparent text
vga.pinout 4,5,6, 7,15,16, 17, 18, 8,3
vga.delete
tft.loadfont "/fonts/FreeSansBold20pt7b.bin", 10
tft.loadfont "/fonts/FreeMonoBold24pt7b.bin", 11
vga.init 2, 3 '640x480 3 buffers
vga.WritePage 0 ' active
vga.fill black
vga.text.align ALIGN_MID_MID
vga.text.draw "Transparent Text", 320, 240, 11
vga.showpage 0 'shows the page 0
vga.show 'refresh the cache memory (and flush the cache memory)
pause 3000
vga.writepage 2 'select to write into page 2
vga.image "/img/aircraft.jpg"
act = 0
while 1
vga.writepage act 'active the writing page
vga.copy 2, act ' copy the reference image into the active page
vga.text.draw "Random " + str$(rnd(10000)), 100, 100
vga.showpage act 'shows the final result (and flush the cache memory)
pause 100
act = 1 - act 'invert the page
wend