main.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2006 - 2008
  3. * Wandering Monster Studios Limited
  4. *
  5. * Any use of this program is governed by the terms of Wandering Monster
  6. * Studios Limited's Licence Agreement included with this program, a copy
  7. * of which can be obtained by contacting Wandering Monster Studios
  8. * Limited at [email protected].
  9. *
  10. */
  11. #include <RmlUi/Core.h>
  12. #include <RmlUi/Debugger.h>
  13. #include <Input.h>
  14. #include <Shell.h>
  15. #include <ShellRenderInterfaceOpenGL.h>
  16. Rml::Context* context = nullptr;
  17. ShellRenderInterfaceExtensions *shell_renderer;
  18. void GameLoop()
  19. {
  20. context->Update();
  21. shell_renderer->PrepareRenderBuffer();
  22. context->Render();
  23. shell_renderer->PresentRenderBuffer();
  24. }
  25. #if defined RMLUI_PLATFORM_WIN32
  26. #include <windows.h>
  27. 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))
  28. #else
  29. int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
  30. #endif
  31. {
  32. #ifdef RMLUI_PLATFORM_WIN32
  33. RMLUI_UNUSED(instance_handle);
  34. RMLUI_UNUSED(previous_instance_handle);
  35. RMLUI_UNUSED(command_line);
  36. RMLUI_UNUSED(command_show);
  37. #else
  38. RMLUI_UNUSED(argc);
  39. RMLUI_UNUSED(argv);
  40. #endif
  41. #ifdef RMLUI_PLATFORM_WIN32
  42. AllocConsole();
  43. #endif
  44. int window_width = 1024;
  45. int window_height = 768;
  46. ShellRenderInterfaceOpenGL opengl_renderer;
  47. shell_renderer = &opengl_renderer;
  48. // Generic OS initialisation, creates a window and attaches OpenGL.
  49. if (!Shell::Initialise() ||
  50. !Shell::OpenWindow("Template Tutorial", shell_renderer, window_width, window_height, true))
  51. {
  52. Shell::Shutdown();
  53. return -1;
  54. }
  55. // RmlUi initialisation.
  56. Rml::SetRenderInterface(&opengl_renderer);
  57. opengl_renderer.SetViewport(window_width, window_height);
  58. ShellSystemInterface system_interface;
  59. Rml::SetSystemInterface(&system_interface);
  60. Rml::Initialise();
  61. // Create the main RmlUi context and set it on the shell's input layer.
  62. context = Rml::CreateContext("main", Rml::Vector2i(window_width, window_height));
  63. if (context == nullptr)
  64. {
  65. Rml::Shutdown();
  66. Shell::Shutdown();
  67. return -1;
  68. }
  69. Rml::Debugger::Initialise(context);
  70. Input::SetContext(context);
  71. Shell::SetContext(context);
  72. Shell::LoadFonts("assets/");
  73. // Load and show the tutorial document.
  74. if (Rml::ElementDocument * document = context->LoadDocument("tutorial/template/data/tutorial.rml"))
  75. document->Show();
  76. Shell::EventLoop(GameLoop);
  77. // Shutdown RmlUi.
  78. Rml::Shutdown();
  79. Shell::CloseWindow();
  80. Shell::Shutdown();
  81. return 0;
  82. }