Facebook
From ddenizozgur, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 159
  1. #include <SDL2/SDL.h>
  2.  
  3. #include "MCANV.h"
  4.  
  5. int main()
  6. {
  7.     if (SDL_Init(SDL_INIT_EVERYTHING)!=0)
  8.         return -1;
  9.  
  10.     SDL_Window *wnd=SDL_CreateWindow(
  11.         "KANKA TITLE MY",
  12.         SDL_WINDOWPOS_UNDEFINED,
  13.         SDL_WINDOWPOS_UNDEFINED,
  14.         1280,
  15.         960,
  16.         SDL_WINDOW_SHOWN);
  17.     if (!wnd)
  18.         return -1;
  19.  
  20.     SDL_Renderer *rdr=SDL_CreateRenderer(
  21.         wnd,
  22.         -1,
  23.         SDL_RENDERER_ACCELERATED|
  24.         SDL_RENDERER_PRESENTVSYNC);
  25.     if (!rdr)
  26.         return -1;
  27.  
  28.     MCANVINFO mci={
  29.         .width=800,
  30.         .height=600,
  31.         .std_font=std_font,
  32.     };
  33.     MCANV *canv=MCANV_Alloc(&mci;);
  34.  
  35.     SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY,"1");
  36.     SDL_Texture *canv_txr=SDL_CreateTexture(
  37.         rdr,
  38.         SDL_PIXELFORMAT_ABGR8888,
  39.         SDL_TEXTUREACCESS_STREAMING,
  40.         canv->info.width,
  41.         canv->info.height);
  42.     if (!canv_txr)
  43.         return -1;
  44.  
  45.  
  46.     unsigned long freq=SDL_GetPerformanceFrequency();
  47.     unsigned long time0=0,time1=SDL_GetPerformanceCounter();
  48.     float dt=0.0f;
  49.  
  50.     SDL_Event evnt;
  51.     bool done=false;
  52.     while (!done) {
  53.         time1=SDL_GetPerformanceCounter();
  54.         dt=(float)(time1-time0)/(float)freq;
  55.         time0=time1;
  56.         while (SDL_PollEvent(&evnt;)) {
  57.             if (evnt.type==SDL_QUIT)
  58.                 done=true;
  59.         }
  60.  
  61.         canv->color=STD_PALETTE_BLACK;
  62.         MCANV_Fill(canv);
  63.  
  64.  
  65.         canv->color=STD_PALETTE_YELLOW;
  66.         MCANV_PrintFmt(canv,
  67.             canv->info.width-14*STD_FONT_WIDTH,
  68.             canv->info.height-2*STD_FONT_HEIGHT,
  69.             "dt:  %.4fnfps: %.3f",
  70.             dt,1.0f/dt);
  71.  
  72.         SDL_UpdateTexture(canv_txr,NULL,canv->buff,canv->pitch);
  73.         SDL_RenderCopy(rdr,canv_txr,NULL,NULL);
  74.         SDL_RenderPresent(rdr);
  75.     }
  76.    
  77.     MCANV_Free(canv);
  78.  
  79.     SDL_DestroyTexture(canv_txr);
  80.     SDL_DestroyRenderer(rdr);
  81.     SDL_DestroyWindow(wnd);
  82.     SDL_Quit();
  83.     return 0;
  84. }