main.cpp 2.5 KB

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