main.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2006 - 2008
  3. * Wandering Monster Studios Limited
  4. *
  5. * Any use of this program is governed by the terms of Wandering Monster
  6. * Studios Limited's Licence Agreement included with this program, a copy
  7. * of which can be obtained by contacting Wandering Monster Studios
  8. * Limited at [email protected].
  9. *
  10. */
  11. #include <Rocket/Core.h>
  12. #include <Rocket/Debugger.h>
  13. #include <Input.h>
  14. #include <Shell.h>
  15. Rocket::Core::Context* context = NULL;
  16. ShellRenderInterfaceExtensions *shell_renderer;
  17. void GameLoop()
  18. {
  19. context->Update();
  20. shell_renderer->PrepareRenderBuffer();
  21. context->Render();
  22. shell_renderer->PresentRenderBuffer();
  23. }
  24. #if defined ROCKET_PLATFORM_WIN32
  25. #include <windows.h>
  26. 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))
  27. #else
  28. int main(int ROCKET_UNUSED_PARAMETER(argc), char** ROCKET_UNUSED_PARAMETER(argv))
  29. #endif
  30. {
  31. #ifdef ROCKET_PLATFORM_WIN32
  32. ROCKET_UNUSED(instance_handle);
  33. ROCKET_UNUSED(previous_instance_handle);
  34. ROCKET_UNUSED(command_line);
  35. ROCKET_UNUSED(command_show);
  36. #else
  37. ROCKET_UNUSED(argc);
  38. ROCKET_UNUSED(argv);
  39. #endif
  40. #ifdef ROCKET_PLATFORM_LINUX
  41. #define APP_PATH "../Samples/tutorial/template/"
  42. #else
  43. #define APP_PATH "../../Samples/tutorial/template/"
  44. #endif
  45. #ifdef ROCKET_PLATFORM_WIN32
  46. DoAllocConsole();
  47. #endif
  48. int window_width = 1024;
  49. int window_height = 768;
  50. ShellRenderInterfaceOpenGL opengl_renderer;
  51. shell_renderer = &opengl_renderer;
  52. // Generic OS initialisation, creates a window and attaches OpenGL.
  53. if (!Shell::Initialise(APP_PATH) ||
  54. !Shell::OpenWindow("Template Tutorial", shell_renderer, window_width, window_height, true))
  55. {
  56. Shell::Shutdown();
  57. return -1;
  58. }
  59. // Rocket initialisation.
  60. Rocket::Core::SetRenderInterface(&opengl_renderer);
  61. opengl_renderer.SetViewport(window_width, window_height);
  62. ShellSystemInterface system_interface;
  63. Rocket::Core::SetSystemInterface(&system_interface);
  64. Rocket::Core::Initialise();
  65. // Create the main Rocket context and set it on the shell's input layer.
  66. context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(window_width, window_height));
  67. if (context == NULL)
  68. {
  69. Rocket::Core::Shutdown();
  70. Shell::Shutdown();
  71. return -1;
  72. }
  73. Rocket::Debugger::Initialise(context);
  74. Input::SetContext(context);
  75. shell_renderer->SetContext(context);
  76. Shell::LoadFonts("../../assets/");
  77. // Load and show the tutorial document.
  78. Rocket::Core::ElementDocument* document = context->LoadDocument("data/tutorial.rml");
  79. if (document != NULL)
  80. {
  81. document->Show();
  82. document->RemoveReference();
  83. }
  84. Shell::EventLoop(GameLoop);
  85. // Shutdown Rocket.
  86. context->RemoveReference();
  87. Rocket::Core::Shutdown();
  88. Shell::CloseWindow();
  89. Shell::Shutdown();
  90. return 0;
  91. }