FabGL
ESP32 Display Controller and Graphics Library
VGA/DoubleBuffer/DoubleBuffer.ino

Show double buffering usage

/*
Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - <http://www.fabgl.com>
Copyright (c) 2019-2022 Fabrizio Di Vittorio.
All rights reserved.
* Please contact fdivitto2013@gmail.com if you need a commercial license.
* This library and related software is available under GPL v3.
FabGL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FabGL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FabGL. If not, see <http://www.gnu.org/licenses/>.
*/
#include "fabgl.h"
fabgl::VGAController DisplayController;
fabgl::Canvas canvas(&DisplayController);
#define DOUBLEBUFFERING 1
struct Test {
virtual ~Test() { };
virtual void update() = 0;
virtual bool nextState() = 0;
virtual int testState() = 0;
virtual char const * name() = 0;
};
#include "ballstest.h"
#include "polygonstest.h"
#include "spritestest.h"
void setup()
{
DisplayController.begin();
DisplayController.setResolution(VGA_320x200_75Hz, -1, -1, DOUBLEBUFFERING);
//DisplayController.moveScreen(-8, 0);
// get a font for about 40x14 text screen
canvas.selectFont(&fabgl::FONT_8x8);
canvas.setGlyphOptions(GlyphOptions().FillBackground(true));
}
void loop()
{
static int64_t stime = esp_timer_get_time();
static int FPS = 0;
static int FPSCounter = 0;
static int testIndex = 0;
static Test * test = new BallsTest;
if (test->nextState() == false) {
delete test;
++testIndex;
switch (testIndex) {
case 1:
test = new PolygonsTest;
break;
case 2:
test = new SpritesTest;
break;
default:
testIndex = 0;
test = new BallsTest;
break;
}
}
if (esp_timer_get_time() - stime > 1000000) {
// calculate FPS
FPS = FPSCounter;
stime = esp_timer_get_time();
FPSCounter = 0;
}
++FPSCounter;
test->update();
// display test state and FPS
canvas.setPenColor(Color::Blue);
canvas.setBrushColor(Color::Yellow);
canvas.drawTextFmt(80, 5, " %d %s at %d FPS ", test->testState(), test->name(), FPS);
if (DOUBLEBUFFERING)
canvas.swapBuffers();
}
A class with a set of drawing methods.
Definition: canvas.h:70
Represents the VGA bitmapped controller.
Definition: vgacontroller.h:89
GlyphOptions & FillBackground(bool value)
Helper method to set or reset fillBackground.
This file is the all in one include file. Application can just include this file to use FabGL library...
#define VGA_320x200_75Hz
Definition: fabglconf.h:183