main.cpp 3.8 KB

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