Issue #340, add bitmap/hello_world example

This example uses the Bitmap device to draw to an in-memory buffer
and writes the result to a TGA file. This can for example be used to
make screenshots of an application normally running on an Arduino.
This commit is contained in:
Matthijs Kooijman 2017-08-30 13:35:57 +02:00
parent c7ac9a7818
commit 094a13c255
2 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,12 @@
CFLAGS = -g -Wall -I../../../csrc/.
SRC = $(shell ls ../../../csrc/*.c) $(shell ls ../common/u8x8_d_bitmap.c ) main.c
OBJ = $(SRC:.c=.o)
hello_world: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) -o $@
clean:
-rm -f $(OBJ) hello_world *.tga

View File

@ -0,0 +1,40 @@
#include "u8g2.h"
#include <stdio.h>
/*
* This example uses the Bitmap device to draw to an in-memory buffer
* and writes the result to a TGA file. This can for example be used to
* make screenshots of an application normally running on an Arduino.
*/
u8g2_t u8g2;
int main(void)
{
u8g2_SetupBitmap(&u8g2, &u8g2_cb_r0, 128, 64);
u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
u8g2_SetFont(&u8g2, u8g2_font_helvB08_tr);
u8g2_ClearBuffer(&u8g2);
// Here, you can call other code to actually draw things, such as
// existing application code to generate a screenshot
u8g2_DrawStr(&u8g2, 10, 30, "Hello, world!");
u8g2_SendBuffer(&u8g2);
u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "small.tga");
// This changes size, but also resets other stuff like font
u8g2_SetupBitmap(&u8g2, &u8g2_cb_r0, 128, 128);
u8g2_SetFont(&u8g2, u8g2_font_helvB08_tr);
u8g2_ClearBuffer(&u8g2);
// Here, you can call other code to actually draw things, such as
// existing application code to generate a screenshot
u8g2_DrawStr(&u8g2, 10, 30, "Hello, world!");
u8g2_DrawStr(&u8g2, 10, 100, "Hello, larger world!");
u8g2_SendBuffer(&u8g2);
u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "large.tga");
return 0;
}