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