main.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. #include <iostream>
  2. #include <getopt.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <SDL_mixer.h>
  6. #include <SDL.h>
  7. #include <FreeImage.h>
  8. #include <sys/stat.h>
  9. #include <GL/glew.h>
  10. #include <csignal>
  11. #include <GLFW/glfw3.h>
  12. #include <libgen.h>
  13. #include "WallpaperEngine/Core/CProject.h"
  14. #include "WallpaperEngine/Render/CWallpaper.h"
  15. #include "WallpaperEngine/Render/CContext.h"
  16. #include "WallpaperEngine/Render/CVideo.h"
  17. #include "WallpaperEngine/Assets/CPackage.h"
  18. #include "WallpaperEngine/Assets/CDirectory.h"
  19. #include "WallpaperEngine/Assets/CVirtualContainer.h"
  20. #include "WallpaperEngine/Assets/CCombinedContainer.h"
  21. #include "WallpaperEngine/Assets/CPackageLoadException.h"
  22. float g_Time;
  23. bool g_KeepRunning = true;
  24. int g_AudioVolume = 15;
  25. using namespace WallpaperEngine::Core::Types;
  26. const char* assets_default_paths [] = {
  27. ".steam/steam/steamapps/common/wallpaper_engine/assets",
  28. ".local/share/Steam/steamapps/common/wallpaper_engine/assets",
  29. nullptr
  30. };
  31. const char* backgrounds_default_paths [] = {
  32. ".local/share/Steam/steamapps/workshop/content/431960",
  33. ".steam/steam/steamapps/workshop/content/431960",
  34. nullptr
  35. };
  36. void print_help (const char* route)
  37. {
  38. std::cout
  39. << "Usage: " << route << " [options] background_path/background_id" << std::endl
  40. << std::endl
  41. << "where background_path/background_id can be:" << std::endl
  42. << "\tthe ID of the background (for autodetection on your steam installation)" << std::endl
  43. << "\ta full path to the background's folder" << std::endl
  44. << std::endl
  45. << "options:" << std::endl
  46. << " --silent\t\tMutes all the sound the wallpaper might produce" << std::endl
  47. << " --volume <amount>\tSets the volume for all the sounds in the background" << std::endl
  48. << " --screen-root <screen name>\tDisplay as screen's background" << std::endl
  49. << " --fps <maximum-fps>\tLimits the FPS to the given number, useful to keep battery consumption low" << std::endl
  50. << " --assets-dir <path>\tFolder where the assets are stored" << std::endl
  51. << " --screenshot\t\tTakes a screenshot of the background" << std::endl
  52. << " --list-properties\tList all the available properties and their possible values" << std::endl;
  53. }
  54. std::string stringPathFixes(const std::string& s)
  55. {
  56. if (s.empty () == true)
  57. return s;
  58. std::string str (s);
  59. // remove single-quotes from the arguments
  60. if (str [0] == '\'' && str [str.size() - 1] == '\'')
  61. str
  62. .erase (str.size() - 1, 1)
  63. .erase (0, 1);
  64. return std::move (str);
  65. }
  66. void signalhandler(int sig)
  67. {
  68. g_KeepRunning = false;
  69. }
  70. int validatePath(const char* path, std::string& final)
  71. {
  72. char finalPath [PATH_MAX];
  73. char* pointer = realpath (path, finalPath);
  74. if (finalPath == nullptr)
  75. return errno;
  76. // ensure the path points to a folder
  77. struct stat pathinfo;
  78. if (stat (finalPath, &pathinfo) != 0)
  79. return errno;
  80. if (!S_ISDIR (pathinfo.st_mode))
  81. return ENOTDIR;
  82. final = finalPath;
  83. return 0;
  84. }
  85. std::string getHomePath ()
  86. {
  87. char* home = getenv ("HOME");
  88. if (home == nullptr)
  89. throw std::runtime_error ("$HOME doesn't exist");
  90. std::string homepath;
  91. int error = validatePath (home, homepath);
  92. if (error == ENOTDIR)
  93. throw std::runtime_error ("Invalid user home path");
  94. else if (error == ENAMETOOLONG)
  95. throw std::runtime_error ("Cannot get user's home folder, path is too long");
  96. else if (error != 0)
  97. throw std::runtime_error ("Cannot find the home folder for the user");
  98. return homepath;
  99. }
  100. void initGLFW ()
  101. {
  102. // first of all, initialize the window
  103. if (glfwInit () == GLFW_FALSE)
  104. throw std::runtime_error ("Failed to initialize GLFW");
  105. // initialize freeimage
  106. FreeImage_Initialise (TRUE);
  107. // set some window hints (opengl version to be used)
  108. glfwWindowHint (GLFW_SAMPLES, 4);
  109. glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 3);
  110. glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 3);
  111. glfwWindowHint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  112. if (DEBUG)
  113. glfwWindowHint (GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
  114. }
  115. void addPkg (CCombinedContainer* containers, const std::string& path, std::string pkgfile)
  116. {
  117. try
  118. {
  119. std::string scene_path = path + pkgfile;
  120. // add the package to the list
  121. containers->add (new WallpaperEngine::Assets::CPackage (scene_path));
  122. std::cout << "Detected " << pkgfile << " file at " << scene_path << ". Adding to list of searchable paths" << std::endl;
  123. }
  124. catch (CPackageLoadException& ex)
  125. {
  126. // ignore this error, the package file was not found
  127. std::cout << "No " << pkgfile << " file found at " << path << ". Defaulting to normal folder storage" << std::endl;
  128. }
  129. catch (std::runtime_error& ex)
  130. {
  131. // the package was found but there was an error loading it (wrong header or something)
  132. fprintf (stderr, "Failed to load scene.pkg file: %s\n", ex.what());
  133. throw std::runtime_error ("Cannot load package file");
  134. }
  135. }
  136. CVirtualContainer* buildVirtualContainer ()
  137. {
  138. CVirtualContainer* container = new WallpaperEngine::Assets::CVirtualContainer ();
  139. //
  140. // Had to get a little creative with the effects to achieve the same bloom effect without any custom code
  141. // these virtual files are loaded by an image in the scene that takes current _rt_FullFrameBuffer and
  142. // applies the bloom effect to render it out to the screen
  143. //
  144. // add the effect file for screen bloom
  145. container->add (
  146. "effects/wpenginelinux/bloomeffect.json",
  147. "{"
  148. "\t\"name\":\"camerabloom_wpengine_linux\","
  149. "\t\"group\":\"wpengine_linux_camera\","
  150. "\t\"dependencies\":[],"
  151. "\t\"passes\":"
  152. "\t["
  153. "\t\t{"
  154. "\t\t\t\"material\": \"materials/util/downsample_quarter_bloom.json\","
  155. "\t\t\t\"target\": \"_rt_4FrameBuffer\","
  156. "\t\t\t\"bind\":"
  157. "\t\t\t["
  158. "\t\t\t\t{"
  159. "\t\t\t\t\t\"name\": \"_rt_FullFrameBuffer\","
  160. "\t\t\t\t\t\"index\": 0"
  161. "\t\t\t\t}"
  162. "\t\t\t]"
  163. "\t\t},"
  164. "\t\t{"
  165. "\t\t\t\"material\": \"materials/util/downsample_eighth_blur_v.json\","
  166. "\t\t\t\"target\": \"_rt_8FrameBuffer\","
  167. "\t\t\t\"bind\":"
  168. "\t\t\t["
  169. "\t\t\t\t{"
  170. "\t\t\t\t\t\"name\": \"_rt_4FrameBuffer\","
  171. "\t\t\t\t\t\"index\": 0"
  172. "\t\t\t\t}"
  173. "\t\t\t]"
  174. "\t\t},"
  175. "\t\t{"
  176. "\t\t\t\"material\": \"materials/util/blur_h_bloom.json\","
  177. "\t\t\t\"target\": \"_rt_Bloom\","
  178. "\t\t\t\"bind\":"
  179. "\t\t\t["
  180. "\t\t\t\t{"
  181. "\t\t\t\t\t\"name\": \"_rt_8FrameBuffer\","
  182. "\t\t\t\t\t\"index\": 0"
  183. "\t\t\t\t}"
  184. "\t\t\t]"
  185. "\t\t},"
  186. "\t\t{"
  187. "\t\t\t\"material\": \"materials/util/combine.json\","
  188. "\t\t\t\"target\": \"_rt_FullFrameBuffer\","
  189. "\t\t\t\"bind\":"
  190. "\t\t\t["
  191. "\t\t\t\t{"
  192. "\t\t\t\t\t\"name\": \"_rt_imageLayerComposite_-1_a\","
  193. "\t\t\t\t\t\"index\": 0"
  194. "\t\t\t\t},"
  195. "\t\t\t\t{"
  196. "\t\t\t\t\t\"name\": \"_rt_Bloom\","
  197. "\t\t\t\t\t\"index\": 1"
  198. "\t\t\t\t}"
  199. "\t\t\t]"
  200. "\t\t}"
  201. "\t]"
  202. "}"
  203. );
  204. // add some model for the image element even if it's going to waste rendering cycles
  205. container->add (
  206. "models/wpenginelinux.json",
  207. "{"
  208. "\t\"material\":\"materials/wpenginelinux.json\""
  209. "}"
  210. );
  211. // models require materials, so add that too
  212. container->add (
  213. "materials/wpenginelinux.json",
  214. "{"
  215. "\t\"passes\":"
  216. "\t\t["
  217. "\t\t\t{"
  218. "\t\t\t\t\"blending\": \"normal\","
  219. "\t\t\t\t\"cullmode\": \"nocull\","
  220. "\t\t\t\t\"depthtest\": \"disabled\","
  221. "\t\t\t\t\"depthwrite\": \"disabled\","
  222. "\t\t\t\t\"shader\": \"genericimage2\","
  223. "\t\t\t\t\"textures\": [\"_rt_FullFrameBuffer\"]"
  224. "\t\t\t}"
  225. "\t\t]"
  226. "}"
  227. );
  228. return container;
  229. }
  230. void takeScreenshot (WallpaperEngine::Render::CWallpaper* wp, const std::string& filename, FREE_IMAGE_FORMAT format)
  231. {
  232. GLint width, height;
  233. // bind texture and get the size
  234. glBindFramebuffer (GL_FRAMEBUFFER, wp->getWallpaperFramebuffer ());
  235. glBindTexture (GL_TEXTURE_2D, wp->getWallpaperTexture ());
  236. glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
  237. glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
  238. // make room for storing the pixel data
  239. uint8_t* buffer = new uint8_t [width * height * sizeof (uint8_t) * 3];
  240. uint8_t* pixel = buffer;
  241. // read the image into the buffer
  242. glReadPixels (0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer);
  243. // build the output file with FreeImage
  244. FIBITMAP* bitmap = FreeImage_Allocate (width, height, 24);
  245. RGBQUAD color;
  246. // now get access to the pixels
  247. for (int y = height; y > 0; y --)
  248. {
  249. for (int x = 0; x < width; x ++)
  250. {
  251. color.rgbRed = *pixel ++;
  252. color.rgbGreen = *pixel ++;
  253. color.rgbBlue = *pixel ++;
  254. // set the pixel in the destination
  255. FreeImage_SetPixelColor (bitmap, x, y, &color);
  256. }
  257. }
  258. // finally save the file
  259. FreeImage_Save (format, bitmap, filename.c_str (), 0);
  260. // free all the used memory
  261. delete[] buffer;
  262. FreeImage_Unload (bitmap);
  263. // unbind the textures
  264. glBindTexture (GL_TEXTURE_2D, GL_NONE);
  265. }
  266. int main (int argc, char* argv[])
  267. {
  268. std::vector <std::string> screens;
  269. int maximumFPS = 30;
  270. bool shouldEnableAudio = true;
  271. bool shouldTakeScreenshot = false;
  272. bool shouldListPropertiesAndStop = false;
  273. FREE_IMAGE_FORMAT screenshotFormat = FIF_UNKNOWN;
  274. std::string path;
  275. std::string assetsDir;
  276. std::string screenshotPath;
  277. static struct option long_options [] = {
  278. {"screen-root", required_argument, 0, 'r'},
  279. {"pkg", required_argument, 0, 'p'},
  280. {"dir", required_argument, 0, 'd'},
  281. {"silent", no_argument, 0, 's'},
  282. {"volume", required_argument, 0, 'v'},
  283. {"help", no_argument, 0, 'h'},
  284. {"fps", required_argument, 0, 'f'},
  285. {"assets-dir", required_argument, 0, 'a'},
  286. {"screenshot", required_argument, 0, 'c'},
  287. {"list-properties", no_argument, 0, 'l'},
  288. {nullptr, 0, 0, 0}
  289. };
  290. while (true)
  291. {
  292. int c = getopt_long (argc, argv, "r:p:d:shf:a:", long_options, nullptr);
  293. if (c == -1)
  294. break;
  295. switch (c)
  296. {
  297. case 'l':
  298. shouldListPropertiesAndStop = true;
  299. break;
  300. case 'r':
  301. screens.emplace_back (optarg);
  302. break;
  303. case 'p':
  304. case 'd':
  305. std::cerr << "--dir/--pkg is deprecated and not used anymore" << std::endl;
  306. path = stringPathFixes (optarg);
  307. break;
  308. case 's':
  309. shouldEnableAudio = false;
  310. break;
  311. case 'h':
  312. print_help (argv [0]);
  313. break;
  314. case 'f':
  315. maximumFPS = atoi (optarg);
  316. break;
  317. case 'a':
  318. assetsDir = optarg;
  319. break;
  320. case 'v':
  321. g_AudioVolume = atoi (optarg);
  322. break;
  323. case 'c':
  324. shouldTakeScreenshot = true;
  325. screenshotPath = stringPathFixes (optarg);
  326. break;
  327. }
  328. }
  329. if (path.empty () == true)
  330. {
  331. if (optind < argc && strlen (argv [optind]) > 0)
  332. {
  333. path = argv [optind];
  334. }
  335. else
  336. {
  337. print_help (argv [0]);
  338. return 0;
  339. }
  340. }
  341. // validate screenshot file just to make sure
  342. if (shouldTakeScreenshot == true)
  343. {
  344. // ensure the file is one of the supported formats
  345. std::string extension = screenshotPath.substr (screenshotPath.find_last_of (".") + 1);
  346. if (extension == "bmp")
  347. screenshotFormat = FIF_BMP;
  348. else if (extension == "png")
  349. screenshotFormat = FIF_PNG;
  350. else if (extension == "jpg" || extension == "jpeg")
  351. screenshotFormat = FIF_JPEG;
  352. else
  353. throw std::runtime_error ("Unsupported screenshot format...");
  354. }
  355. std::string homepath = getHomePath ();
  356. auto containers = new WallpaperEngine::Assets::CCombinedContainer ();
  357. // check if the background might be an ID and try to find the right path in the steam installation folder
  358. if (path.find ('/') == std::string::npos)
  359. {
  360. for (const char** current = backgrounds_default_paths; *current != nullptr; current ++)
  361. {
  362. std::string tmppath = homepath + "/" + *current + "/" + path;
  363. int error = validatePath (tmppath.c_str (), tmppath);
  364. if (error != 0)
  365. continue;
  366. path = tmppath;
  367. }
  368. }
  369. int error = validatePath (path.c_str (), path);
  370. if (error == ENOTDIR)
  371. throw std::runtime_error ("The background path is not a folder");
  372. else if (error == ENAMETOOLONG)
  373. throw std::runtime_error ("Cannot get wallpaper's folder, path is too long");
  374. else if (error != 0)
  375. throw std::runtime_error ("Cannot find the specified folder");
  376. // add a trailing slash to the path so the right file can be found
  377. path += "/";
  378. // the background's path is required to load project.json regardless of the type of background we're using
  379. containers->add (new WallpaperEngine::Assets::CDirectory (path));
  380. // add the virtual container for mocked up files
  381. containers->add (buildVirtualContainer ());
  382. // try to add the common packages
  383. addPkg (containers, path, "scene.pkg");
  384. addPkg (containers, path, "gifscene.pkg");
  385. if (assetsDir.empty () == true)
  386. {
  387. for (const char** current = assets_default_paths; *current != nullptr; current ++)
  388. {
  389. std::string tmppath = homepath + "/" + *current;
  390. error = validatePath (tmppath.c_str (), tmppath);
  391. if (error != 0)
  392. continue;
  393. assetsDir = tmppath;
  394. std::cout << "Found wallpaper engine's assets at " << assetsDir << std::endl;
  395. break;
  396. }
  397. if (assetsDir.empty () == true)
  398. {
  399. unsigned long len = strlen (argv [0]) + 1;
  400. char* copy = new char[len];
  401. strncpy (copy, argv [0], len);
  402. // path still not found, try one last thing on the current binary's folder
  403. std::string exepath = dirname (copy);
  404. exepath += "/assets";
  405. error = validatePath (exepath.c_str (), exepath);
  406. if (error == 0)
  407. {
  408. assetsDir = exepath;
  409. std::cout << "Found assets folder alongside the binary: " << assetsDir << std::endl;
  410. }
  411. delete[] copy;
  412. }
  413. }
  414. else
  415. {
  416. error = validatePath (assetsDir.c_str (), assetsDir);
  417. if (error == ENOTDIR)
  418. throw std::runtime_error ("Invalid assets folder");
  419. else if (error == ENAMETOOLONG)
  420. throw std::runtime_error ("Cannot get assets folder, path is too long");
  421. else if (error != 0)
  422. throw std::runtime_error ("Cannot find the specified assets folder");
  423. std::cout << "Found wallpaper engine's assets at " << assetsDir << " based on --assets-dir parameter" << std::endl;
  424. }
  425. if (assetsDir.empty () == true)
  426. throw std::runtime_error ("Cannot determine a valid path for the wallpaper engine assets");
  427. // add containers to the list
  428. containers->add (new WallpaperEngine::Assets::CDirectory (assetsDir + "/"));
  429. // parse the project.json file
  430. auto project = WallpaperEngine::Core::CProject::fromFile ("project.json", containers);
  431. // go to the right folder so the videos will play
  432. if (project->getWallpaper ()->is <WallpaperEngine::Core::CVideo> () == true)
  433. chdir (path.c_str ());
  434. // show properties if required
  435. if (shouldListPropertiesAndStop)
  436. {
  437. for (auto cur : project->getProperties ())
  438. {
  439. std::cout << cur->dump () << std::endl;
  440. }
  441. return 0;
  442. }
  443. // attach signals so if a stop is requested the X11 resources are freed and the program shutsdown gracefully
  444. std::signal(SIGINT, signalhandler);
  445. std::signal(SIGTERM, signalhandler);
  446. // initialize glfw
  447. initGLFW ();
  448. // auto projection = project->getWallpaper ()->as <WallpaperEngine::Core::CScene> ()->getOrthogonalProjection ();
  449. // create the window!
  450. // TODO: DO WE NEED TO PASS MONITOR HERE OR ANYTHING?
  451. // TODO: FIGURE OUT HOW TO PUT THIS WINDOW IN THE BACKGROUND
  452. GLFWwindow* window = glfwCreateWindow (1920, 1080, "WallpaperEngine", NULL, NULL);
  453. if (window == nullptr)
  454. {
  455. fprintf (stderr, "Failed to open a GLFW window");
  456. glfwTerminate ();
  457. return 2;
  458. }
  459. glfwMakeContextCurrent (window);
  460. // TODO: FIGURE THESE OUT BASED ON THE SCREEN
  461. int windowWidth = 1920;
  462. int windowHeight = 1080;
  463. // get the real framebuffer size
  464. glfwGetFramebufferSize (window, &windowWidth, &windowHeight);
  465. GLenum glewInitResult = glewInit ();
  466. // initialize glew
  467. if (glewInitResult != GLEW_OK)
  468. {
  469. fprintf (stderr, "Failed to initialize GLEW: %s", glewGetErrorString (glewInitResult));
  470. glfwTerminate ();
  471. return 3;
  472. }
  473. if (shouldEnableAudio == true && SDL_Init (SDL_INIT_AUDIO) < 0)
  474. {
  475. std::cerr << "Cannot initialize SDL audio system, SDL_GetError: " << SDL_GetError() << std::endl;
  476. std::cerr << "Continuing without audio support" << std::endl;
  477. }
  478. // initialize custom context class
  479. WallpaperEngine::Render::CContext* context = new WallpaperEngine::Render::CContext (screens, window, containers);
  480. // initialize mouse support
  481. context->setMouse (new CMouseInput (window));
  482. // set the default viewport
  483. context->setDefaultViewport ({0, 0, windowWidth, windowHeight});
  484. // ensure the context knows what wallpaper to render
  485. context->setWallpaper (
  486. WallpaperEngine::Render::CWallpaper::fromWallpaper (project->getWallpaper (), context)
  487. );
  488. // update maximum FPS if it's a video
  489. if (context->getWallpaper ()->is <WallpaperEngine::Render::CVideo> () == true)
  490. maximumFPS = context->getWallpaper ()->as <WallpaperEngine::Render::CVideo> ()->getFPS ();
  491. // TODO: FIGURE OUT THE REQUIRED INPUT MODE, AS SOME WALLPAPERS USE THINGS LIKE MOUSE POSITION
  492. // glfwSetInputMode (window, GLFW_STICKY_KEYS, GL_TRUE);
  493. double startTime, endTime, minimumTime = 1.0 / maximumFPS;
  494. uint32_t frameCounter = 0;
  495. while (glfwWindowShouldClose (window) == 0 && g_KeepRunning == true)
  496. {
  497. // get the real framebuffer size
  498. glfwGetFramebufferSize (window, &windowWidth, &windowHeight);
  499. // set the default viewport
  500. context->setDefaultViewport ({0, 0, windowWidth, windowHeight});
  501. // calculate the current time value
  502. g_Time = (float) glfwGetTime ();
  503. // get the start time of the frame
  504. startTime = glfwGetTime ();
  505. // render the scene
  506. context->render ();
  507. // do buffer swapping
  508. glfwSwapBuffers (window);
  509. // poll for events (like closing the window)
  510. glfwPollEvents ();
  511. // get the end time of the frame
  512. endTime = glfwGetTime ();
  513. // ensure the frame time is correct to not overrun FPS
  514. if ((endTime - startTime) < minimumTime)
  515. usleep ((minimumTime - (endTime - startTime)) * CLOCKS_PER_SEC);
  516. frameCounter ++;
  517. if (frameCounter == 5 && shouldTakeScreenshot == true)
  518. {
  519. takeScreenshot (context->getWallpaper (), screenshotPath, screenshotFormat);
  520. // disable screenshot just in case the counter overflows
  521. shouldTakeScreenshot = false;
  522. }
  523. }
  524. // ensure this is updated as sometimes it might not come from a signal
  525. g_KeepRunning = false;
  526. std::cout << "Stop requested" << std::endl;
  527. // terminate gl
  528. glfwTerminate ();
  529. // terminate free image
  530. FreeImage_DeInitialise ();
  531. // terminate SDL
  532. SDL_QuitSubSystem(SDL_INIT_AUDIO);
  533. SDL_Quit ();
  534. // free context
  535. delete context;
  536. return 0;
  537. }