MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / displayWindow

Function displayWindow

apps/tools/Tools/SDLPreview.cpp:52–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52static void displayWindow(const std::string& title, int imgW, int imgH, const uint8_t* pixels,
53 SDL_PixelFormat pixelFormat, int bytesPerPixel, int minWinSize, ResizeCallback onResize)
54{
55 if (!SDL_Init(SDL_INIT_VIDEO))
56 {
57 std::cerr << "Error: SDL_Init failed: " << SDL_GetError() << std::endl;
58 throw CLI::RuntimeError(1);
59 }
60
61 int winW = imgW, winH = imgH;
62 int scale = 1;
63 while (winW * scale < minWinSize && winH * scale < minWinSize)
64 scale *= 2;
65 winW *= scale;
66 winH *= scale;
67
68 SDL_Window* window = SDL_CreateWindow(title.c_str(), winW, winH, SDL_WINDOW_RESIZABLE);
69 SDL_Renderer* renderer = SDL_CreateRenderer(window, nullptr);
70 SDL_Texture* tex = SDL_CreateTexture(renderer, pixelFormat, SDL_TEXTUREACCESS_STATIC, imgW, imgH);
71 SDL_UpdateTexture(tex, nullptr, pixels, imgW * bytesPerPixel);
72
73 std::vector<uint8_t> pixelsCopy(pixels, pixels + imgW * imgH * bytesPerPixel);
74 runEventLoop(window, renderer, tex, imgW, imgH, pixelFormat, bytesPerPixel, pixelsCopy, onResize);
75
76 SDL_DestroyTexture(tex);
77 SDL_DestroyRenderer(renderer);
78 SDL_DestroyWindow(window);
79 SDL_Quit();
80}
81
82void DisplayWindowRGBA(const std::string& title, int imgW, int imgH, const uint8_t* pixels)
83{

Callers 2

DisplayWindowRGBAFunction · 0.85
DisplayWindowRGBFunction · 0.85

Calls 1

runEventLoopFunction · 0.85

Tested by

no test coverage detected