程式語言 - Simple DirectMedia Layer (SDL) - v2.0 - C/C++ - Get Ticks



參考資訊:
https://wiki.libsdl.org/FrontPage

main.c

#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
#include <SDL2_gfxPrimitives.h>
 
int main(int argc, char **argv)
{
    const int w = 320;
    const int h = 240;
    const int bpp = 16;
    SDL_Window *window = NULL;
    SDL_Renderer *renderer = NULL;

    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
    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);

    Uint32 start = SDL_GetTicks();
    SDL_Delay(1000);
    Uint32 end = SDL_GetTicks();

    char buf[255] = {0};
    sprintf(buf, "strat:%d, end:%d", start, end);

    SDL_RenderClear(renderer);
    stringRGBA(renderer, 100, 100, buf, 0xff, 0xff, 0xff, 0xff);
    SDL_RenderPresent(renderer);

    SDL_Delay(3000);

    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}

編譯、執行

$ gcc main.c -o main -lSDL2 -lSDL2_gfx -I/usr/include/SDL2
$ ./main