main.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #include "Inventory.h"
  17. Rml::Core::Context* context = NULL;
  18. ShellRenderInterfaceExtensions *shell_renderer;
  19. void GameLoop()
  20. {
  21. context->Update();
  22. shell_renderer->PrepareRenderBuffer();
  23. context->Render();
  24. shell_renderer->PresentRenderBuffer();
  25. }
  26. #if defined RMLUI_PLATFORM_WIN32
  27. #include <windows.h>
  28. 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))
  29. #else
  30. int main(int RMLUI_UNUSED_PARAMETER(argc), char** RMLUI_UNUSED_PARAMETER(argv))
  31. #endif
  32. {
  33. #ifdef RMLUI_PLATFORM_WIN32
  34. RMLUI_UNUSED(instance_handle);
  35. RMLUI_UNUSED(previous_instance_handle);
  36. RMLUI_UNUSED(command_line);
  37. RMLUI_UNUSED(command_show);
  38. #else
  39. RMLUI_UNUSED(argc);
  40. RMLUI_UNUSED(argv);
  41. #endif
  42. #ifdef RMLUI_PLATFORM_WIN32
  43. AllocConsole();
  44. #endif
  45. int window_width = 1024;
  46. int window_height = 768;
  47. auto opengl_renderer = std::make_shared<ShellRenderInterfaceOpenGL>();
  48. shell_renderer = opengl_renderer.get();
  49. // Generic OS initialisation, creates a window and attaches OpenGL.
  50. if (!Shell::Initialise() ||
  51. !Shell::OpenWindow("Drag Tutorial", shell_renderer, window_width, window_height, true))
  52. {
  53. Shell::Shutdown();
  54. return -1;
  55. }
  56. // RmlUi initialisation.
  57. Rml::Core::SetRenderInterface(opengl_renderer);
  58. opengl_renderer->SetViewport(window_width, window_height);
  59. Rml::Core::SetSystemInterface(std::make_shared<ShellSystemInterface>());
  60. Rml::Core::Initialise();
  61. // Create the main RmlUi context and set it on the shell's input layer.
  62. context = Rml::Core::CreateContext("main", Rml::Core::Vector2i(window_width, window_height));
  63. if (context == NULL)
  64. {
  65. Rml::Core::Shutdown();
  66. Shell::Shutdown();
  67. return -1;
  68. }
  69. Rml::Debugger::Initialise(context);
  70. Input::SetContext(context);
  71. shell_renderer->SetContext(context);
  72. Shell::LoadFonts("assets/");
  73. // Load and show the inventory document.
  74. Inventory* inventory_1 = new Inventory("Inventory 1", Rml::Core::Vector2f(50, 200), context);
  75. Inventory* inventory_2 = new Inventory("Inventory 2", Rml::Core::Vector2f(540, 240), context);
  76. // Add items into the inventory.
  77. inventory_1->AddItem("Mk III L.A.S.E.R.");
  78. inventory_1->AddItem("Gravity Descender");
  79. inventory_1->AddItem("Closed-Loop Ion Beam");
  80. inventory_1->AddItem("5kT Mega-Bomb");
  81. Shell::EventLoop(GameLoop);
  82. delete inventory_1;
  83. delete inventory_2;
  84. // Shutdown RmlUi.
  85. Rml::Core::Shutdown();
  86. Shell::CloseWindow();
  87. Shell::Shutdown();
  88. return 0;
  89. }