#include <SDL2/SDL.h> #include "MCANV.h" int main() { if (SDL_Init(SDL_INIT_EVERYTHING)!=0) return -1; SDL_Window *wnd=SDL_CreateWindow( "KANKA TITLE MY", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 960, SDL_WINDOW_SHOWN); if (!wnd) return -1; SDL_Renderer *rdr=SDL_CreateRenderer( wnd, -1, SDL_RENDERER_ACCELERATED| SDL_RENDERER_PRESENTVSYNC); if (!rdr) return -1; MCANVINFO mci={ .width=800, .height=600, .std_font=std_font, }; MCANV *canv=MCANV_Alloc(&mci;); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY,"1"); SDL_Texture *canv_txr=SDL_CreateTexture( rdr, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING, canv->info.width, canv->info.height); if (!canv_txr) return -1; unsigned long freq=SDL_GetPerformanceFrequency(); unsigned long time0=0,time1=SDL_GetPerformanceCounter(); float dt=0.0f; SDL_Event evnt; bool done=false; while (!done) { time1=SDL_GetPerformanceCounter(); dt=(float)(time1-time0)/(float)freq; time0=time1; while (SDL_PollEvent(&evnt;)) { if (evnt.type==SDL_QUIT) done=true; } canv->color=STD_PALETTE_BLACK; MCANV_Fill(canv); canv->color=STD_PALETTE_YELLOW; MCANV_PrintFmt(canv, canv->info.width-14*STD_FONT_WIDTH, canv->info.height-2*STD_FONT_HEIGHT, "dt: %.4fnfps: %.3f", dt,1.0f/dt); SDL_UpdateTexture(canv_txr,NULL,canv->buff,canv->pitch); SDL_RenderCopy(rdr,canv_txr,NULL,NULL); SDL_RenderPresent(rdr); } MCANV_Free(canv); SDL_DestroyTexture(canv_txr); SDL_DestroyRenderer(rdr); SDL_DestroyWindow(wnd); SDL_Quit(); return 0; }