Steward
分享是一種喜悅、更是一種幸福
掌機 - Miyoo A30 - C/C++ - SDL v2.0 - Open Font
main.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <stdio.h> #include <stdlib.h> #include <SDL.h> #include <SDL_ttf.h> int main ( int argc, char **argv) { const int w = 320; const int h = 240; const int bpp = 16; SDL_Window * window = NULL ; SDL_Surface *screen = NULL ; SDL_Texture *texture = NULL ; SDL_Renderer *renderer = NULL ; SDL_Init ( SDL_INIT_VIDEO ); window = SDL_CreateWindow ( "main" , SDL_WINDOWPOS_UNDEFINED , SDL_WINDOWPOS_UNDEFINED , w, h, SDL_WINDOW_SHOWN ); renderer = SDL_CreateRenderer ( window , -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC ); screen = SDL_CreateRGBSurface (0, w, h, bpp, 0, 0, 0, 0); texture = SDL_CreateTexture (renderer, SDL_PIXELFORMAT_RGB565 , SDL_TEXTUREACCESS_STREAMING , w, h); TTF_Init (); TTF_Font *font = TTF_OpenFont ( "font.ttf" , 30); SDL_FillRect (screen, &screen->clip_rect, SDL_MapRGB (screen->format, 0x00, 0x00, 0x00)); int ww = 0, hh = 0; SDL_Color col = {0, 255, 0}; SDL_Rect rt = {0, 100, 0, 0}; const char *cc = "Miyoo Handheld" ; TTF_SizeUTF8 (font, cc, &ww, &hh); rt.x = (w - ww) / 2; SDL_Surface *msg = TTF_RenderUTF8_Solid (font, cc, col); SDL_BlitSurface (msg, NULL , screen, &rt); SDL_FreeSurface (msg); SDL_UpdateTexture (texture, NULL , screen->pixels, screen->pitch); SDL_RenderClear (renderer); SDL_RenderCopy (renderer, texture, NULL , NULL ); SDL_RenderPresent (renderer); SDL_Delay (30000); TTF_CloseFont (font); TTF_Quit (); SDL_FreeSurface (screen); SDL_DestroyTexture (texture); SDL_DestroyRenderer (renderer); SDL_DestroyWindow ( window ); SDL_Quit (); return 0; } |
編譯、執行
$ /opt/a30/bin/arm-linux-gcc \ -I/opt/a30/arm-a30-linux-gnueabihf/sysroot/usr/include/SDL2 \ -lSDL2 -lSDL2_gfx -lSDL2_image -lSDL2_ttf -lSDL2_mixer \ -lGLESv2 main.c -o main /mnt/SDCARD# export LD_LIBRARY_PATH=.:/config/lib:/customer/lib:/usr/miyoo/lib /mnt/SDCARD# ./main