main.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. Rocket::Core::Context* context = NULL;
  32. ShellRenderInterfaceExtensions *shell_renderer;
  33. void GameLoop()
  34. {
  35. context->Update();
  36. shell_renderer->PrepareRenderBuffer();
  37. context->Render();
  38. shell_renderer->PresentRenderBuffer();
  39. }
  40. #if defined ROCKET_PLATFORM_WIN32
  41. #include <windows.h>
  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. #else
  44. int main(int ROCKET_UNUSED_PARAMETER(argc), char** ROCKET_UNUSED_PARAMETER(argv))
  45. #endif
  46. {
  47. #ifdef ROCKET_PLATFORM_WIN32
  48. ROCKET_UNUSED(instance_handle);
  49. ROCKET_UNUSED(previous_instance_handle);
  50. ROCKET_UNUSED(command_line);
  51. ROCKET_UNUSED(command_show);
  52. #else
  53. ROCKET_UNUSED(argc);
  54. ROCKET_UNUSED(argv);
  55. #endif
  56. #ifdef ROCKET_PLATFORM_LINUX
  57. #define APP_PATH "../Samples/basic/loaddocument/"
  58. #else
  59. #define APP_PATH "../../Samples/basic/loaddocument/"
  60. #endif
  61. #ifdef ROCKET_PLATFORM_WIN32
  62. DoAllocConsole();
  63. #endif
  64. int window_width = 1024;
  65. int window_height = 768;
  66. ShellRenderInterfaceOpenGL opengl_renderer;
  67. shell_renderer = &opengl_renderer;
  68. // Generic OS initialisation, creates a window and attaches OpenGL.
  69. if (!Shell::Initialise(APP_PATH) ||
  70. !Shell::OpenWindow("Load Document Sample", shell_renderer, window_width, window_height, true))
  71. {
  72. Shell::Shutdown();
  73. return -1;
  74. }
  75. // Rocket initialisation.
  76. Rocket::Core::SetRenderInterface(&opengl_renderer);
  77. shell_renderer->SetViewport(window_width, window_height);
  78. ShellSystemInterface system_interface;
  79. Rocket::Core::SetSystemInterface(&system_interface);
  80. Rocket::Core::Initialise();
  81. // Create the main Rocket context and set it on the shell's input layer.
  82. context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(window_width, window_height));
  83. if (context == NULL)
  84. {
  85. Rocket::Core::Shutdown();
  86. Shell::Shutdown();
  87. return -1;
  88. }
  89. Rocket::Debugger::Initialise(context);
  90. Input::SetContext(context);
  91. shell_renderer->SetContext(context);
  92. Shell::LoadFonts("../../assets/");
  93. // Load and show the demo document.
  94. Rocket::Core::ElementDocument* document = context->LoadDocument("../../assets/demo.rml");
  95. if (document != NULL)
  96. {
  97. document->Show();
  98. document->RemoveReference();
  99. }
  100. Shell::EventLoop(GameLoop);
  101. // Shutdown Rocket.
  102. context->RemoveReference();
  103. Rocket::Core::Shutdown();
  104. Shell::CloseWindow();
  105. Shell::Shutdown();
  106. return 0;
  107. }