Skip to content

Instantly share code, notes, and snippets.

@Habbie
Created April 30, 2023 20:58
Show Gist options
  • Save Habbie/e14583f99d6f5c9e057d08623faeb1f4 to your computer and use it in GitHub Desktop.
Save Habbie/e14583f99d6f5c9e057d08623faeb1f4 to your computer and use it in GitHub Desktop.
#!/bin/bash
id=$(docker create $1)
mkdir -p build
docker cp $id:$2 build/
docker rm -v $id
FROM debian:11-slim
RUN apt-get update && apt-get -y install debootstrap
RUN /usr/sbin/debootstrap --no-check-gpg --arch armel --foreign jessie /tmp/deb8arm http://archive.debian.org/debian/
RUN chroot /tmp/deb8arm /debootstrap/debootstrap --second-stage
RUN echo 'deb http://archive.debian.org/debian jessie-backports main' >> /tmp/deb8arm/etc/apt/sources.list
RUN chroot /tmp/deb8arm apt-get update
RUN chroot /tmp/deb8arm apt-get -y --force-yes install build-essential libdirectfb-dev
# may need pkg-config here?
RUN chroot /tmp/deb8arm apt-get -y --force-yes install -t jessie-backports cmake pkg-config
RUN wget https://github.com/libsdl-org/SDL/releases/download/release-2.26.4/SDL2-2.26.4.tar.gz
RUN tar xf SDL2-2.26.4.tar.gz
# next up: remove version check for libdirectfb. Then, see if compiling an actual 1.2.8 helps
RUN mv SDL2-2.26.4 /tmp/deb8arm/root
# maybe we can set other things to OFF to reduce library size
RUN chroot /tmp/deb8arm sh -c 'cd /root/SDL2-2.26.4 && mkdir build && cd build && cmake -DSDL_DIRECTFB=ON .. && make install'
COPY sdl-example.c /tmp/deb8arm/root/
RUN chroot /tmp/deb8arm sh -c 'cd /root && CFLAGS=`sdl2-config --cflags` LDFLAGS=`sdl2-config --libs` make sdl-example'
# now try LVGL
#RUN chroot /tmp/deb8arm sh -c 'apt-get -y --force-yes install git'
#RUN chroot /tmp/deb8arm sh -c 'git clone --depth 5 https://github.com/lvgl/lvgl'
#RUN chroot /tmp/deb8arm sh -c 'git clone --depth 5 https://github.com/lvgl/lv_drivers'
#RUN chroot /tmp/deb8arm sh -c 'git clone --depth 5 https://github.com/lvgl/lv_examples'
#
#RUN chroot /tmp/deb8arm sh -c 'mkdir lvgl-helloworld'
#RUN chroot /tmp/deb8arm sh -c 'mv lvgl lv_drivers lv_examples lvgl-helloworld/'
#RUN chroot /tmp/deb8arm sh -c 'cd lvgl-helloworld && cp lvgl/lv_conf_template.h lv_conf.h'
#RUN chroot /tmp/deb8arm sh -c 'cd lvgl-helloworld && cp lv_drivers/lv_drv_conf_template.h lv_drv_conf.h'
##RUN chroot /tmp/deb8arm sh -c 'cat lvgl-helloworld/lv_conf.h'
##RUN chroot /tmp/deb8arm sh -c 'cat lvgl-helloworld/lv_drv_conf.h'
#RUN chroot /tmp/deb8arm sh -c 'sed -i "s/#if 0/#if 1/" lvgl-helloworld/*.h'
#RUN chroot /tmp/deb8arm sh -c 'sed -i "s/LV_COLOR_DEPTH 16/LV_COLOR_DEPTH 32/" lvgl-helloworld/lv_conf.h'
#RUN chroot /tmp/deb8arm sh -c 'sed -i "s/# define USE_FBDEV 0/#define USE_FBDEV 1/" lvgl-helloworld/lv_drv_conf.h'
#RUN chroot /tmp/deb8arm sh -c 'pwd'
#
#COPY lvgl-helloworld/main.c /tmp/deb8arm/lvgl-helloworld/
#
#RUN chroot /tmp/deb8arm sh -c 'cd /lvgl-helloworld && make CPPFLAGS=-I. main'
# now try the LVGL fb example
RUN chroot /tmp/deb8arm sh -c 'apt-get -y --force-yes install git'
RUN chroot /tmp/deb8arm sh -c 'git clone https://github.com/Habbie/lv_port_linux_frame_buffer.git # 3'
RUN chroot /tmp/deb8arm sh -c 'cd lv_port_linux_frame_buffer/ && git submodule update --init --recursive'
RUN chroot /tmp/deb8arm sh -c 'cd lv_port_linux_frame_buffer && make -j12'
RUN chroot /tmp/deb8arm sh -c 'cd lv_port_linux_frame_buffer && find . -name demo'
#include <SDL2/SDL.h>
//#include <SDL2/SDL_image.h>
#include <SDL2/SDL_timer.h>
int main(int argc, char *argv[])
{
// returns zero on success else non-zero
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
printf("error initializing SDL: %s\n", SDL_GetError());
exit(1);
}
printf("x");
SDL_Window* win = SDL_CreateWindow("GAME", // creates a window
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
1000, 1000, 0);
printf("win=%x\n", win);
if(win == NULL) {
printf("error initializing SDL: %s\n", SDL_GetError());
exit(1);
}
printf("y");
// triggers the program that controls
// your graphics hardware and sets flags
Uint32 render_flags = 0; // SDL_RENDERER_ACCELERATED;
printf("z");
// creates a renderer to render our images
SDL_Renderer* rend = SDL_CreateRenderer(win, -1, render_flags);
printf("q");
// creates a surface to load an image into the main memory
// SDL_Surface* surface;
// please provide a path for your image
// surface = IMG_Load("path");
// loads image to our graphics hardware memory.
// SDL_Texture* tex = SDL_CreateTextureFromSurface(rend, surface);
// clears main-memory
//SDL_FreeSurface(surface);
printf("r");
// let us control our image position
// so that we can move it with our keyboard.
SDL_Rect dest;
// connects our texture with dest to control position
//SDL_QueryTexture(tex, NULL, NULL, &dest.w, &dest.h);
// adjust height and width of our image box.
dest.w /= 6;
dest.h /= 6;
// sets initial x-position of object
dest.x = (1000 - dest.w) / 2;
// sets initial y-position of object
dest.y = (1000 - dest.h) / 2;
// controls animation loop
int close = 0;
// speed of box
int speed = 300;
printf("a");
// animation loop
while (!close) {
printf("b");
SDL_Event event;
// Events management
while (SDL_PollEvent(&event)) {
printf("c");
switch (event.type) {
case SDL_QUIT:
// handling of close button
close = 1;
break;
case SDL_KEYDOWN:
// keyboard API for key pressed
switch (event.key.keysym.scancode) {
case SDL_SCANCODE_W:
case SDL_SCANCODE_UP:
dest.y -= speed / 30;
break;
case SDL_SCANCODE_A:
case SDL_SCANCODE_LEFT:
dest.x -= speed / 30;
break;
case SDL_SCANCODE_S:
case SDL_SCANCODE_DOWN:
dest.y += speed / 30;
break;
case SDL_SCANCODE_D:
case SDL_SCANCODE_RIGHT:
dest.x += speed / 30;
break;
default:
break;
}
}
}
// right boundary
if (dest.x + dest.w > 1000)
dest.x = 1000 - dest.w;
// left boundary
if (dest.x < 0)
dest.x = 0;
// bottom boundary
if (dest.y + dest.h > 1000)
dest.y = 1000 - dest.h;
// upper boundary
if (dest.y < 0)
dest.y = 0;
// clears the screen
printf("e");
SDL_RenderClear(rend);
printf("f");
//SDL_RenderCopy(rend, tex, NULL, &dest);
// triggers the double buffers
// for multiple rendering
SDL_RenderPresent(rend);
printf("g");
// calculates to 60 fps
SDL_Delay(1000 / 60);
}
printf("h");
// destroy texture
//SDL_DestroyTexture(tex);
// destroy renderer
SDL_DestroyRenderer(rend);
// destroy window
SDL_DestroyWindow(win);
// close SDL
SDL_Quit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment