Z-Pocket Game Pro(ZPG Pro)

sdltest


main.c

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <string.h>
#include <linux/fb.h>
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>

int main(int argc, char* args[])
{
  SDL_Window *sdlWindow;
  SDL_Renderer *sdlRenderer;
  
  SDL_Init(SDL_INIT_VIDEO);
  SDL_CreateWindowAndRenderer(480, 320, SDL_WINDOW_SHOWN, &sdlWindow, &sdlRenderer);
  SDL_Surface *screen = SDL_CreateRGBSurface(SDL_SWSURFACE, 480, 320, 16, 0, 0, 0, 0);
  SDL_Texture *sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, 480, 320);

  int col=0xf800;
  int x, y, z=600;
  while(z--){
    uint16_t *s = screen->pixels;
    for(y=0; y<320; y++){
      for(x=0; x<480; x++){
        *s++ = col;
      }
    }
    SDL_UpdateTexture(sdlTexture, NULL, screen->pixels, screen->pitch);
    SDL_RenderClear(sdlRenderer);
    SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
    SDL_RenderPresent(sdlRenderer);

    switch(col){
    case 0xf800:
      col = 0x7e0;
      break;
    case 0x7e0:
      col = 0x1f;
      break;
    case 0x1f:
      col = 0xf800;
      break;
    }
    SDL_Delay(1000/60);
  }
  SDL_FreeSurface(screen);
  SDL_DestroyTexture(sdlTexture);
  SDL_DestroyRenderer(sdlRenderer);
  SDL_DestroyWindow(sdlWindow);
  SDL_Quit();
  return 0;
}

編譯

$ cd
$ wget https://github.com/steward-fu/zpg-pro/releases/download/v1.0/toolchain-x64.tar.gz
$ tar xvf toolchain-x64.tar.gz
$ sudo mv gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu /opt/zpg-sdk
$ export PATH=$PATH:/opt/zpg-sdk/bin

$ /opt/zpg-sdk/bin/aarch64-none-linux-gnu-gcc main.c -o sdltest -lSDL2 -I/opt/zpg-sdk/aarch64-none-linux-gnu/include/SDL2 -Wl,-rpath-link=/opt/zpg-sdk/aarch64-none-linux-gnu/lib -Wl,-rpath-link=/opt/zpg-sdk/aarch64-none-linux-gnu/lib/pulseaudio


返回上一頁