//clang++ geometry_test.cpp -lSDL2 -lSDL2_ttf -O2 #include #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("/usr/share/fonts/noto/NotoSans-Regular.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 wantQuit=0; SDL_Event event; int fps=0, time=0; while (!wantQuit) { fps++; while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { wantQuit = 1; } } if (event.common.timestamp - time >= 1000) { if (event.common.timestamp - time >= 2000) { time = event.common.timestamp; time = event.common.timestamp; } else { printf("FPS: %d\n", fps); fps=1; time += 1000; } } SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); SDL_RenderClear(renderer); if (0) { 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_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); } SDL_RenderGeometry(renderer, texture, vertices, 90*24*6, 0, 0); } SDL_RenderPresent(renderer); } SDL_DestroyTexture(texture); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); TTF_Quit(); SDL_Quit(); }