main.cpp 2.2 KB

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