2
0

main.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #include <ShellRenderInterfaceOpenGL.h>
  16. Rocket::Core::Context* context = NULL;
  17. ShellRenderInterfaceExtensions *shell_renderer;
  18. void GameLoop()
  19. {
  20. context->Update();
  21. shell_renderer->PrepareRenderBuffer();
  22. context->Render();
  23. shell_renderer->PresentRenderBuffer();
  24. }
  25. #if defined ROCKET_PLATFORM_WIN32
  26. #include <windows.h>
  27. 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))
  28. #else
  29. int main(int ROCKET_UNUSED_PARAMETER(argc), char** ROCKET_UNUSED_PARAMETER(argv))
  30. #endif
  31. {
  32. #ifdef ROCKET_PLATFORM_WIN32
  33. ROCKET_UNUSED(instance_handle);
  34. ROCKET_UNUSED(previous_instance_handle);
  35. ROCKET_UNUSED(command_line);
  36. ROCKET_UNUSED(command_show);
  37. #else
  38. ROCKET_UNUSED(argc);
  39. ROCKET_UNUSED(argv);
  40. #endif
  41. #ifdef ROCKET_PLATFORM_WIN32
  42. AllocConsole();
  43. #endif
  44. int window_width = 1024;
  45. int window_height = 768;
  46. ShellRenderInterfaceOpenGL opengl_renderer;
  47. shell_renderer = &opengl_renderer;
  48. // Generic OS initialisation, creates a window and attaches OpenGL.
  49. if (!Shell::Initialise() ||
  50. !Shell::OpenWindow("Template Tutorial", shell_renderer, window_width, window_height, true))
  51. {
  52. Shell::Shutdown();
  53. return -1;
  54. }
  55. // Rocket initialisation.
  56. Rocket::Core::SetRenderInterface(&opengl_renderer);
  57. opengl_renderer.SetViewport(window_width, window_height);
  58. ShellSystemInterface system_interface;
  59. Rocket::Core::SetSystemInterface(&system_interface);
  60. Rocket::Core::Initialise();
  61. // Create the main Rocket context and set it on the shell's input layer.
  62. context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(window_width, window_height));
  63. if (context == NULL)
  64. {
  65. Rocket::Core::Shutdown();
  66. Shell::Shutdown();
  67. return -1;
  68. }
  69. Rocket::Debugger::Initialise(context);
  70. Input::SetContext(context);
  71. shell_renderer->SetContext(context);
  72. Shell::LoadFonts("assets/");
  73. // Load and show the tutorial document.
  74. Rocket::Core::ElementDocument* document = context->LoadDocument("tutorial/template/data/tutorial.rml");
  75. if (document != NULL)
  76. {
  77. document->Show();
  78. document->RemoveReference();
  79. }
  80. Shell::EventLoop(GameLoop);
  81. // Shutdown Rocket.
  82. context->RemoveReference();
  83. Rocket::Core::Shutdown();
  84. Shell::CloseWindow();
  85. Shell::Shutdown();
  86. return 0;
  87. }