{"id":2055,"date":"2021-09-23T19:07:58","date_gmt":"2021-09-23T10:07:58","guid":{"rendered":"https:\/\/sirius10.net\/blog\/wordpress\/?p=2055"},"modified":"2021-10-12T09:11:07","modified_gmt":"2021-10-12T00:11:07","slug":"post-2055","status":"publish","type":"post","link":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/2021\/09\/23\/2055\/","title":{"rendered":"GPiCASE \u306b\u30a2\u30ca\u30ed\u30b0\u6642\u8a08\u3092\u8868\u793a\u3059\u308b"},"content":{"rendered":"\n<p>\u3000\u3000\u30d5\u30ec\u30fc\u30e0\u30d0\u30c3\u30d5\u30a1\u3092\u4f7f\u3048\u3070\u3001GPiCASE \u306e RetroPie \u3067\u753b\u9762\u306b\u8868\u793a\u3055\u305b\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u3068\u308f\u304b\u308a\u307e\u3057\u305f\u3002SDL \u3067\u958b\u767a\u3059\u308c\u3070\u3001GPiCASE \u306e\u30d5\u30ec\u30fc\u30e0\u30d0\u30c3\u30d5\u30a1\u306b\u51fa\u3057\u3066\u304f\u308c\u308b\u3053\u3068\u3082\u308f\u304b\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3000\u305d\u3053\u3067\u3001\u8a66\u3057\u306b GPiCASE \u306b\u8868\u793a\u3059\u308b\u6642\u8a08\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002\u30c7\u30b8\u30bf\u30eb\u6642\u8a08\u3067\u306f\u306a\u304f\u3001\u30a2\u30ca\u30ed\u30b0\u6642\u8a08\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000320 x 240 \u306e\u30b5\u30a4\u30ba\u3067\u6642\u8a08\u306e\u6587\u5b57\u76e4\u3092\u30d3\u30c3\u30c8\u30de\u30c3\u30d7\u3067\u4f5c\u308a\u3001\u305d\u308c\u3092\u8868\u793a\u3059\u308b\u3060\u3051\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002\u30c6\u30b9\u30c8\u306f\u666e\u901a\u306eRaspberry Pi \u306e\u30c7\u30b9\u30af\u30c8\u30c3\u30d7\u3067\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted file\">#include &lt;SDL\/SDL.h&gt;\n\nint main(int argc, char* argv[]){\n\tSDL_Surface* image;\n\tSDL_Rect rect, scr_rect;\n\n\tSDL_Init(SDL_INIT_EVERYTHING);\n\n\tSDL_SetVideoMode(320, 240, 32, SDL_HWSURFACE);\n\n\t\/* \u753b\u50cf\u8aad\u307f\u8fbc\u307f *\/\n\timage = SDL_LoadBMP(\"clock.bmp\");\n\n\t\/* \u753b\u50cf\u306e\u77e9\u5f62\u60c5\u5831\u8a2d\u5b9a *\/\n\trect.x = 0;\n\trect.y = 0;\n\trect.w = image-&gt;w;\n\trect.h = image-&gt;h;\n\n\t\/* \u753b\u50cf\u914d\u7f6e\u4f4d\u7f6e\u60c5\u5831\u306e\u8a2d\u5b9a *\/\n\tscr_rect.x = 0;\n\tscr_rect.y = 0;\n\n\t\/* \u30b5\u30fc\u30d5\u30a7\u30b9\u306e\u8907\u5199 *\/\n\tSDL_BlitSurface(image, &amp;rect, SDL_GetVideoSurface(), &amp;scr_rect);\n\n\t\/* \u30b5\u30fc\u30d5\u30a7\u30b9\u30d5\u30ea\u30c3\u30d7 *\/\n\tSDL_Flip(SDL_GetVideoSurface());\n\n\tSDL_Delay(3000);\n\n\tSDL_FreeSurface(image);\n\n\tSDL_Quit();\n\n\treturn 0;\n}<\/pre>\n\n\n\n<p>\u30003 \u79d2\u3060\u3051\u6642\u8a08\u306e\u6587\u5b57\u76e4\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002GPiCASE \u306e Raspberry Pi Zero \u3078\u30b3\u30d4\u30fc\u3057\u3066\u5b9f\u884c\u3059\u308b\u3068\u3001GPiCASE \u306b\u6587\u5b57\u76e4\u304c\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002\u5927\u4e08\u592b\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u3055\u3066\u3001\u73fe\u5728\u6642\u523b\u3092\u53d6\u5f97\u3057\u3066\u3001\u6642\u8a08\u306e\u91dd\u3092\u8868\u793a\u3057\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002\u73fe\u5728\u6642\u523b\u306e\u53d6\u5f97\u306f\u666e\u901a\u306e C \u3067\u53d6\u5f97\u3067\u304d\u307e\u3059\u304c\u3001\u79d2\u91dd\u306e\u63cf\u753b\u3092\u3069\u3046\u3057\u307e\u3057\u3087\u3046\u304b\u3002<\/p>\n\n\n\n<p>\u3000\u65b9\u6cd5\u3068\u3057\u3066\u306f\u3001\u3044\u304f\u3064\u304b\u8003\u3048\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><span style=\"font-size: 17px\" class=\"font-size\">\u5168\u3066\u306e\u72b6\u614b\u306e\u79d2\u91dd\u3001\u5206\u91dd\u3001\u6642\u91dd\u306e\u753b\u50cf\u3092\u6e96\u5099\u3057\u3066\u91cd\u306d\u5408\u308f\u305b\u308b\u3002<\/span><\/li><li><span style=\"font-size: 17px\" class=\"font-size\">\u91dd\u306e\u753b\u50cf\u3092\u6e96\u5099\u3057\u3066\u56de\u8ee2\u3055\u305b\u308b\u3002<\/span><\/li><li><span style=\"font-size: 17px\" class=\"font-size\">\u30e9\u30a4\u30f3\u3067\u63cf\u753b\u3059\u308b\u3002<\/span><\/li><\/ul>\n\n\n\n<p>\u3000\u3069\u308c\u304c\u7c21\u5358\u3067\u3057\u3087\u3046\u3002\u91dd\u306e\u753b\u50cf\u3092\u56de\u8ee2\u3055\u305b\u3066\u8868\u793a\u3059\u308b\u306e\u304c\u3044\u3044\u3068\u601d\u3044\u307e\u3057\u305f\u304c\u3001SDL + OPENGL \u3067\u4f5c\u308b\u304b\u3001SDL2 \u3042\u305f\u308a\u3092\u4f7f\u3046\u304b\u306b\u306a\u308b\u3067\u3057\u3087\u3046\u3002SDL \u3060\u3051\u3067\u306f\u7121\u7406\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u91dd\u306e\u63cf\u753b\u306f\u5f8c\u306b\u3057\u3066\u3001SDL2 \u306b\u5909\u66f4\u3057\u3066\u30bf\u30a4\u30de\u30fc\u3092\u4f7f\u3044\u3001\u30c7\u30b8\u30bf\u30eb\u3067\u6642\u523b\u3092\u8868\u793a\u3057\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted file\">#include &lt;stdio.h&gt;\n#include &lt;time.h&gt;\n#include &lt;SDL.h&gt;\n#include &lt;SDL_ttf.h&gt;\n\nstatic SDL_Surface* image = NULL;\nstatic SDL_Window *window = NULL;\nstatic TTF_Font *font = NULL;\nstatic SDL_Color gray = {0x60, 0x60, 0x60};\n\nchar *get_time(int *h, int *m, int *s) {\n    time_t timer;\n    struct tm *local;\n    static char result[20];\n    int ts;\n\n    timer = time(NULL);\n    local = localtime(&amp;timer);\n\n    *h = local-&gt;tm_hour;\n    *m = local-&gt;tm_min;\n    *s = local-&gt;tm_sec;\n\n    sprintf(result, \"%02d:%02d:%02d\", *h, *m, *s);\n\n    return result;\n}\n\nvoid *redraw(void *param) {\n    SDL_Rect rect;\n    SDL_Surface *text;\n    int h, m, s;\n\n    \/* \u6587\u5b57\u76e4\u306e\u8868\u793a *\/\n    SDL_BlitSurface(image, NULL, SDL_GetWindowSurface(window), NULL);\n\n    \/* \u6642\u523b\u306e\u8868\u793a *\/\n    text = TTF_RenderUTF8_Blended(font, get_time(&amp;h, &amp;m, &amp;s), gray);\n    rect.x = 87;\n    rect.y = 200;\n    rect.w = text-&gt;w;\n    rect.h = text-&gt;h;\n    SDL_BlitSurface(text, NULL, SDL_GetWindowSurface(window), &amp;rect);\n    SDL_FreeSurface(text);\n    rect.x = rect.y = 0;\n    rect.w = image-&gt;w, rect.h = image-&gt;w;\n    SDL_UpdateWindowSurfaceRects(window, &amp;rect, 1);\n}\n\nUint32 callbackfunc(Uint32 interval, void *param)\n{\n    SDL_Event event;\n    SDL_UserEvent userevent;\n\n    \/* \u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u3067SDL_USEREVENT\u30a4\u30d9\u30f3\u30c8\u3092\u30ad\u30e5\u30fc\u306b\u5165\u308c\u308b\u3002\n    \u3053\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u306f\u4e00\u5b9a\u306e\u5468\u671f\u3067\u518d\u3073\u547c\u3070\u308c\u308b *\/\n\n    userevent.type = SDL_USEREVENT;\n    userevent.code = 0;\n    userevent.data1 = &amp;redraw;\n    userevent.data2 = param;\n\n    event.type = SDL_USEREVENT;\n    event.user = userevent;\n\n    SDL_PushEvent(&amp;event);\n    return(interval);\n}\n\nint main(int argc, char* argv[]){\n    SDL_Event event;\n    SDL_TimerID my_timer_id;\n\n    \/* \u521d\u671f\u5316 *\/\n    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) &lt; 0) {\n        fprintf(stderr, \"SDL_Init(): %s\\n\", SDL_GetError());\n        exit(1);\n    }\n    if (SDL_Init(SDL_INIT_JOYSTICK) &gt;= 0 ) {\n        if( SDL_JoystickOpen(0) != NULL )\n            SDL_ShowCursor(SDL_DISABLE);\n    }\n    TTF_Init();\n\n    \/* \u30d5\u30a9\u30f3\u30c8\u53d6\u5f97 *\/\n    font = TTF_OpenFont(\"\/usr\/share\/fonts\/truetype\/fonts-japanese-gothic.ttf\", 24);\n    if( font == NULL ) {\n        printf(\"Can not open font\\n\");\n        exit(1);\n    }\n    \/* \u753b\u50cf\u8aad\u307f\u8fbc\u307f *\/\n    image = SDL_LoadBMP(\"clock.bmp\");\n    if( image == NULL ) {\n        printf(\"Can not load image\\n\");\n        exit(1);\n    }\n\n    \/* \u30bf\u30a4\u30de\u30fc\u3092\u4f5c\u308b *\/\n    my_timer_id = SDL_AddTimer(1000, callbackfunc, NULL);\n\n    \/* \u30a6\u30a3\u30f3\u30c9\u30a6\u4f5c\u6210 *\/\n    window = SDL_CreateWindow(\"SDL clock\", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 320, 240, SDL_WINDOW_OPENGL);\n    if( window == NULL ) {\n        printf(\"Can not create window\\n\");\n        exit(1);\n    }\n\n    \/* \u30a4\u30d9\u30f3\u30c8\u30eb\u30fc\u30d7 *\/\n    while(1) {\n        if( SDL_PollEvent(&amp;event) ) {\n            switch (event.type) {\n            case SDL_WINDOWEVENT:\n                switch (event.window.event) {\n                case SDL_WINDOWEVENT_EXPOSED:\n                    SDL_UpdateWindowSurface(window);\n                    break;\n                }\n                break;\n\n            case SDL_USEREVENT: {\n                void (*p) (void*) = event.user.data1;\n                p(event.user.data2);\n                break;\n            }\n\n            case SDL_JOYBUTTONDOWN:\n                if( event.jbutton.button != 7 ) break;\n            case SDL_QUIT:\n                SDL_Quit();\n                exit(0);\n                break;\n            }\n        } else\n            SDL_Delay(500);\n    }\n    \/* \u3053\u3053\u306b\u306f\u3053\u306a\u3044 *\/\n    SDL_Quit();\n\n    return 0;\n}\n<\/pre>\n\n\n\n<p>\u3000\u30c7\u30b8\u30bf\u30eb\u3067\u306e\u6642\u8a08\u8868\u793a\u306f\u3067\u304d\u307e\u3057\u305f\u3002GPiCASE \u3067\u306f\u3001\u30b9\u30bf\u30fc\u30c8\u30dc\u30bf\u30f3\u3067\u7d42\u4e86\u3057\u307e\u3059\u3002\u5f8c\u306f\u30a2\u30ca\u30ed\u30b0\u6642\u8a08\u306e\u91dd\u306e\u63cf\u753b\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3000SDL2 \u306e\u56de\u8ee2\u306f\u3001renderer \u3092\u4f7f\u3046\u3088\u3046\u3067\u3059\u3002renderer \u306f\u521d\u3081\u3066\u4f7f\u3044\u307e\u3057\u305f\u304c\u3001\u753b\u50cf\u306e\u8868\u793a\u3082 renderer \u3092\u4f7f\u3063\u3066\u8868\u793a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u91dd\u306f\u3001\u77e9\u5f62\u306b\u3057\u307e\u3057\u305f\u3002\u6587\u5b57\u76e4\u306e\u753b\u50cf\u306e\u5de6\u4e0a\u306e\u30d4\u30af\u30bb\u30eb\u3092\u4f7f\u3063\u3066\u3001\u77e9\u5f62\u306b\u30b3\u30d4\u30fc\u3057\u3066\u56de\u8ee2\u3059\u308b\u3001SDL_RenderCopyEx \u3092\u4f7f\u3046\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3000\u307e\u305f\u3001\u305f\u3060\u5358\u7d14\u306b\u6642\u8a08\u3092\u8868\u793a\u3059\u308b\u3060\u3051\u3067\u306f\u3064\u307e\u3089\u306a\u3044\u306e\u3067\u3001\u30bf\u30a4\u30de\u30fc\u6a5f\u80fd\u3082\u8ffd\u52a0\u3057\u307e\u3057\u305f\u3002\u30bd\u30fc\u30b9\u306f\u6574\u7406\u3057\u3066\u3044\u307e\u305b\u3093\u3002\u3042\u3068\u3067\u3001\u5225\u30da\u30fc\u30b8\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>(2021.09.24 \u8ffd\u8a18)<\/p>\n\n\n\n<p><a href=\"https:\/\/sirius10.net\/RaspberryPi\/SDLClock.html\">SDL \u3067\u30a2\u30ca\u30ed\u30b0\u6642\u8a08\u3092\u4f5c\u308a\u3001GPiCASE \u3067\u52d5\u304b\u3059<\/a> \u304b\u3089\u30bd\u30fc\u30b9\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u3000\u30d5\u30ec\u30fc\u30e0\u30d0\u30c3\u30d5\u30a1\u3092\u4f7f\u3048\u3070\u3001GPiCASE \u306e RetroPie \u3067\u753b\u9762\u306b\u8868\u793a\u3055\u305b\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u3068\u308f\u304b\u308a\u307e\u3057\u305f\u3002SDL \u3067\u958b\u767a\u3059\u308c\u3070\u3001GPiCASE \u306e\u30d5\u30ec\u30fc\u30e0\u30d0\u30c3\u30d5\u30a1\u306b\u51fa\u3057\u3066\u304f\u308c\u308b\u3053\u3068\u3082\u308f\u304b\u308a\u307e\u3057\u305f\u3002 \u3000\u305d\u3053\u3067\u3001\u8a66\u3057 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-2055","post","type-post","status-publish","format-standard","hentry","category-gpicase"],"_links":{"self":[{"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/2055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=2055"}],"version-history":[{"count":6,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/2055\/revisions"}],"predecessor-version":[{"id":2243,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/2055\/revisions\/2243"}],"wp:attachment":[{"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=2055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=2055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sirius10.net\/blog\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=2055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}