main.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 "RenderInterfaceDirectX.h"
  32. #include <windows.h>
  33. static Rocket::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. 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))
  43. {
  44. ROCKET_UNUSED(instance_handle);
  45. ROCKET_UNUSED(previous_instance_handle);
  46. ROCKET_UNUSED(command_line);
  47. ROCKET_UNUSED(command_show);
  48. int window_width = 1024;
  49. int window_height = 768;
  50. RenderInterfaceDirectX directx_renderer;
  51. shell_renderer = &directx_renderer;
  52. // Generic OS initialisation, creates a window
  53. if (!Shell::Initialise("../Samples/basic/directx/") ||
  54. !Shell::OpenWindow("DirectX Sample", shell_renderer, window_width, window_height, true))
  55. {
  56. Shell::Shutdown();
  57. return -1;
  58. }
  59. // Install our DirectX render interface into Rocket.
  60. Rocket::Core::SetRenderInterface(&directx_renderer);
  61. ShellSystemInterface system_interface;
  62. Rocket::Core::SetSystemInterface(&system_interface);
  63. Rocket::Core::Initialise();
  64. // Create the main Rocket context and set it on the shell's input layer.
  65. context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(window_width, window_height));
  66. if (context == NULL)
  67. {
  68. Rocket::Core::Shutdown();
  69. Shell::Shutdown();
  70. return -1;
  71. }
  72. Rocket::Debugger::Initialise(context);
  73. Input::SetContext(context);
  74. shell_renderer->SetContext(context);
  75. Shell::LoadFonts("../../assets/");
  76. // Load and show the tutorial document.
  77. Rocket::Core::ElementDocument* document = context->LoadDocument("../../assets/demo.rml");
  78. if (document != NULL)
  79. {
  80. document->Show();
  81. document->RemoveReference();
  82. }
  83. Shell::EventLoop(GameLoop);
  84. // Shutdown Rocket.
  85. context->RemoveReference();
  86. Rocket::Core::Shutdown();
  87. Shell::CloseWindow();
  88. Shell::Shutdown();
  89. return 0;
  90. }