//clang++ geometry_test.cpp -o geometry_test `sdl2-config --cflags --libs` -lSDL2_ttf -std=c++17 #include #include int main(int argc, char* argv[]) { SDL_Init(SDL_INIT_VIDEO); auto window = SDL_CreateWindow("Geometry test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1920/2, 1080/2, SDL_WINDOW_SHOWN); TTF_Init(); TTF_Font* font = TTF_OpenFont("NotoSans-Light.ttf", 12*2); SDL_Color color = {255, 255, 255, 255}; auto surface = TTF_RenderText_Solid(font, "T", color); auto renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); auto texture = SDL_CreateTextureFromSurface(renderer, surface); SDL_FreeSurface(surface); TTF_CloseFont(font); int tw = 0; int th = 0; SDL_QueryTexture(texture, NULL, NULL, &tw, &th); bool useGeometry = false; if(argc > 1 && SDL_strncasecmp(argv[1], "geo", 3) == 0) { useGeometry = true; } printf("Render method: %s\n", useGeometry ? "SDL_RenderGeometry" : "SDL_RenderCopy"); SDL_Vertex vertices[90*24*6]; for(int r=0; r<24; r++) { for(int c=0; c<90; c++) { float x = c*(tw+3); float y = r*(th+5); const SDL_Vertex verts[6] = { { SDL_FPoint{ x, y }, SDL_Color{ 255, 0, 0, 255 }, SDL_FPoint{ 0, 0 }, }, { SDL_FPoint{ x+tw, y }, SDL_Color{ 0, 0, 255, 255 }, SDL_FPoint{ 1, 0 }, }, { SDL_FPoint{ x, y+th }, SDL_Color{ 0, 255, 0, 255 }, SDL_FPoint{ 0, 1 }, }, { SDL_FPoint{ x, y+th }, SDL_Color{ 0, 255, 0, 255 }, SDL_FPoint{ 0, 1 }, }, { SDL_FPoint{ x+tw, y }, SDL_Color{ 0, 0, 255, 255 }, SDL_FPoint{ 1, 0 }, }, { SDL_FPoint{ x+tw, y+th }, SDL_Color{ 0, 255, 0, 255 }, SDL_FPoint{ 1, 1 }, }, }; //*/ /* const SDL_Vertex verts[6] = { { SDL_FPoint{ x, y }, color, SDL_FPoint{ 0, 0 }, }, { SDL_FPoint{ x+tw, y }, color, SDL_FPoint{ 1, 0 }, }, { SDL_FPoint{ x, y+th }, color, SDL_FPoint{ 0, 1 }, }, { SDL_FPoint{ x, y+th }, color, SDL_FPoint{ 0, 1 }, }, { SDL_FPoint{ x+tw, y }, color, SDL_FPoint{ 1, 0 }, }, { SDL_FPoint{ x+tw, y+th }, color, SDL_FPoint{ 1, 1 }, }, }; //*/ memcpy(vertices+((r*90)+c)*6, verts, sizeof(SDL_Vertex)*6); } } bool wantQuit=0; SDL_Event event; uint64_t frameCount = 0; uint64_t startTime = SDL_GetPerformanceCounter(); while (!wantQuit) { while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { wantQuit = 1; } } SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); SDL_RenderClear(renderer); if (!useGeometry) { for(int r=0; r<24; r++) for(int c=0; c<90; c++) { SDL_Rect dstRect = { c*(tw+3), r*(th+5), tw, th }; SDL_RenderCopy(renderer, texture, 0, &dstRect); } } else { SDL_RenderGeometry(renderer, texture, vertices, 90*24*6, 0, 0); } SDL_RenderPresent(renderer); frameCount += 1; } uint64_t endTime = SDL_GetPerformanceCounter(); double timeTaken = ((double)((endTime - startTime) * 1000) / SDL_GetPerformanceFrequency()) / 1000.0; printf("%" SDL_PRIu64 " frames in %f seconds, %.02f average FPS\n", frameCount, timeTaken, (double)frameCount / timeTaken); SDL_DestroyTexture(texture); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); TTF_Quit(); SDL_Quit(); }