main.cpp 3.5 KB

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