main.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #include <RmlUi/Core.h>
  29. #include <RmlUi/Debugger.h>
  30. #include <Input.h>
  31. #include <Shell.h>
  32. #include <ShellRenderInterfaceOpenGL.h>
  33. Rml::Core::Context* context = NULL;
  34. ShellRenderInterfaceExtensions *shell_renderer;
  35. void GameLoop()
  36. {
  37. context->Update();
  38. shell_renderer->PrepareRenderBuffer();
  39. context->Render();
  40. shell_renderer->PresentRenderBuffer();
  41. }
  42. #if defined RMLUI_PLATFORM_WIN32
  43. #include <windows.h>
  44. int APIENTRY WinMain(HINSTANCE RMLUI_UNUSED_PARAMETER(instance_handle), HINSTANCE RMLUI_UNUSED_PARAMETER(previous_instance_handle), char* RMLUI_UNUSED_PARAMETER(command_line), int RMLUI_UNUSED_PARAMETER(command_show))
  45. #else
  46. int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
  47. #endif
  48. {
  49. #ifdef RMLUI_PLATFORM_WIN32
  50. RMLUI_UNUSED(instance_handle);
  51. RMLUI_UNUSED(previous_instance_handle);
  52. RMLUI_UNUSED(command_line);
  53. RMLUI_UNUSED(command_show);
  54. #else
  55. RMLUI_UNUSED(argc);
  56. RMLUI_UNUSED(argv);
  57. #endif
  58. #ifdef RMLUI_PLATFORM_WIN32
  59. AllocConsole();
  60. #endif
  61. int window_width = 1024;
  62. int window_height = 768;
  63. ShellRenderInterfaceOpenGL opengl_renderer;
  64. shell_renderer = &opengl_renderer;
  65. // Generic OS initialisation, creates a window and attaches OpenGL.
  66. if (!Shell::Initialise() ||
  67. !Shell::OpenWindow("Load Document Sample", shell_renderer, window_width, window_height, true))
  68. {
  69. Shell::Shutdown();
  70. return -1;
  71. }
  72. // RmlUi initialisation.
  73. Rml::Core::SetRenderInterface(&opengl_renderer);
  74. shell_renderer->SetViewport(window_width, window_height);
  75. ShellSystemInterface system_interface;
  76. Rml::Core::SetSystemInterface(&system_interface);
  77. Rml::Core::Initialise();
  78. // Create the main RmlUi context and set it on the shell's input layer.
  79. context = Rml::Core::CreateContext("main", Rml::Core::Vector2i(window_width, window_height));
  80. if (context == NULL)
  81. {
  82. Rml::Core::Shutdown();
  83. Shell::Shutdown();
  84. return -1;
  85. }
  86. Rml::Debugger::Initialise(context);
  87. Input::SetContext(context);
  88. shell_renderer->SetContext(context);
  89. Shell::LoadFonts("assets/");
  90. // Load and show the demo document.
  91. if (Rml::Core::ElementDocument * document = context->LoadDocument("assets/demo.rml"))
  92. document->Show();
  93. Shell::EventLoop(GameLoop);
  94. // Shutdown RmlUi.
  95. context->RemoveReference();
  96. Rml::Core::Shutdown();
  97. Shell::CloseWindow();
  98. Shell::Shutdown();
  99. return 0;
  100. }