-
1Install Cygwin with the tools.
This is a guide to install Cygwin and its required tools. https://mindchasers.com/dev/openocd-darsena-windows.
-
2Get the LibSDL2
Be sure to obtain the Development Libraries, and select the one with MinGW:
-
3Extract LibSDL2 on the main system drive, and install SDL2 files on the Cygwin folder
1.) Copy the library files from the x86_64-w64-mingw32/lib to C:/cygwin64/lib:
2.) Copy the entire SDL2 folder from /x86_64-w64-mingw2/include into c:/cygwin64/lib/gcc/x86_64-pc-cygwin/10/include:
Make sure the SDL2 folder is inside that include directory. Do not copy all its contents into the include folder - just put the folder inside.
3.) Finally, copy the x86_64-w64-ming32/bin/*.* to the C:/cygwin64/bin:
-
4Now go and git clone the U8G2!
As mentioned - git clone the U8G2. :)
-
5From the U8G2/sys/sdl/, create a new folder. Just call it whatever you want!
-
6Go to that new folder you created, and then make a Makefile on that provided:
CFLAGS = -g -Wall -I../../../csrc/. SRC = $(shell ls ../../../csrc/*.c) $(shell ls ../common/*.c ) main.c OBJ = $(SRC:.c=.o) LIBSDL = -lSDL2main -lSDL2 helloworld: $(OBJ) $(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) -o u8g2_sdl.exe $(LIBSDL) clean: -rm $(OBJ) u8g2_sdl
-
7And from the U8G2/sys/sdl/common, modify the both *.C files so that the GCC can detect these SDL libraries properly.
Modify the both C files:
- u8x8_d_sdl_128x64.c
- u8x8_sdl_key.c
The include should be "SDL2/SDL.h" instead of "SDL.h"
#ifndef NO_SDL #include "SDL2/SDL.h" #endif /* return ascii key value or -1 */ int u8g_sdl_get_key(void)
-
8Create the main.c from this template:
#include "u8g2.h" #include <stdio.h> u8g2_t u8g2; int main(void) { int k; u8g2_SetupBuffer_SDL_128x64_4(&u8g2, &u8g2_cb_r0); u8x8_InitDisplay(u8g2_GetU8x8(&u8g2)); u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0); u8g2_ClearBuffer(&u8g2); for(;;) { u8g2_FirstPage(&u8g2); do { u8g2_SetFont(&u8g2, u8g2_font_6x12_tf); u8g2_DrawStr(&u8g2, 5, 17, "hello world 123"); u8g2_DrawStr(&u8g2, 5, 27, "abcabcabc"); u8g2_SetFont(&u8g2, u8g2_font_open_iconic_embedded_1x_t); u8g2_DrawGlyph(&u8g2, 2, 56, 0x0041); } while( u8g2_NextPage(&u8g2) ); do { k = u8g_sdl_get_key(); } while( k < 0 ); if ( k == 'q' ) break; } return 0; }
-
9Save the main.c, then hit "make" in the Cygwin panel:
It should look something like this when it compiles all right:
-
10Run the executable file!
You will see this:
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
Are you sure? yes | no
Thanks! Very useful. In my case there were a few differences - Under windows 10 64 bit using SDL2-devel-2.0.22-mingw, I had to install the .a's and the DLL's from the i686-w64-mingw32/ subdir..
Also I was getting undefined reference to `u8x8_GetMenuEvent' until I went into u8x8_debounce.c and changed #ifdef __unix__xxxxxx_THIS_IS_DISABLED to #ifndef __unix__
Are you sure? yes | no