main.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. ShellRenderInterfaceOpenGL opengl_renderer;
  41. shell_renderer = &opengl_renderer;
  42. // Generic OS initialisation, creates a window and attaches OpenGL.
  43. if (!Shell::Initialise("../Samples/tutorial/template/") ||
  44. !Shell::OpenWindow("Template Tutorial", shell_renderer, 1024, 768, true))
  45. {
  46. Shell::Shutdown();
  47. return -1;
  48. }
  49. // Rocket initialisation.
  50. Rocket::Core::SetRenderInterface(&opengl_renderer);
  51. opengl_renderer.SetViewport(1024, 768);
  52. ShellSystemInterface system_interface;
  53. Rocket::Core::SetSystemInterface(&system_interface);
  54. Rocket::Core::Initialise();
  55. // Create the main Rocket context and set it on the shell's input layer.
  56. context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(1024, 768));
  57. if (context == NULL)
  58. {
  59. Rocket::Core::Shutdown();
  60. Shell::Shutdown();
  61. return -1;
  62. }
  63. Rocket::Debugger::Initialise(context);
  64. Input::SetContext(context);
  65. shell_renderer->SetContext(context);
  66. Shell::LoadFonts("../../assets/");
  67. // Load and show the tutorial document.
  68. Rocket::Core::ElementDocument* document = context->LoadDocument("data/tutorial.rml");
  69. if (document != NULL)
  70. {
  71. document->Show();
  72. document->RemoveReference();
  73. }
  74. Shell::EventLoop(GameLoop);
  75. // Shutdown Rocket.
  76. context->RemoveReference();
  77. Rocket::Core::Shutdown();
  78. Shell::CloseWindow();
  79. Shell::Shutdown();
  80. return 0;
  81. }