main.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include <RmlUi/Core.h>
  2. #include <RmlUi/Debugger.h>
  3. #include <Input.h>
  4. #include <Shell.h>
  5. #include "RenderInterfaceDirectX10.h"
  6. // Because we're a windows app
  7. #include <windows.h>
  8. // For _T unicode/mbcs macro
  9. #include <tchar.h>
  10. static Rml::Core::Context* context = nullptr;
  11. ShellRenderInterfaceExtensions *shell_renderer;
  12. void GameLoop()
  13. {
  14. context->Update();
  15. shell_renderer->PrepareRenderBuffer();
  16. context->Render();
  17. shell_renderer->PresentRenderBuffer();
  18. }
  19. 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))
  20. {
  21. RMLUI_UNUSED(instance_handle);
  22. RMLUI_UNUSED(previous_instance_handle);
  23. RMLUI_UNUSED(command_line);
  24. RMLUI_UNUSED(command_show);
  25. int window_width = 1024;
  26. int window_height = 768;
  27. RenderInterfaceDirectX10 directx_renderer;
  28. shell_renderer = &directx_renderer;
  29. // Generic OS initialisation, creates a window and does not attach OpenGL.
  30. if (!Shell::Initialise() ||
  31. !Shell::OpenWindow("DirectX 10 Sample", shell_renderer, window_width, window_height, true))
  32. {
  33. Shell::Shutdown();
  34. return -1;
  35. }
  36. // Install our DirectX render interface into RmlUi.
  37. Rml::Core::SetRenderInterface(&directx_renderer);
  38. ShellSystemInterface system_interface;
  39. Rml::Core::SetSystemInterface(&system_interface);
  40. Rml::Core::Initialise();
  41. // Create the main RmlUi context and set it on the shell's input layer.
  42. context = Rml::Core::CreateContext("main", Rml::Core::Vector2i(window_width, window_height));
  43. if (context == nullptr)
  44. {
  45. Rml::Core::Shutdown();
  46. Shell::Shutdown();
  47. return -1;
  48. }
  49. Rml::Debugger::Initialise(context);
  50. Input::SetContext(context);
  51. shell_renderer->SetContext(context);
  52. Shell::LoadFonts("assets/");
  53. // Load and show the tutorial document.
  54. Rml::Core::ElementDocument* document = context->LoadDocument("assets/demo.rml");
  55. if (document != nullptr)
  56. {
  57. document->Show();
  58. document->RemoveReference();
  59. }
  60. Shell::EventLoop(GameLoop);
  61. // Shutdown RmlUi.
  62. context->RemoveReference();
  63. Rml::Core::Shutdown();
  64. Shell::CloseWindow();
  65. Shell::Shutdown();
  66. return 0;
  67. }