main.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include <Rocket/Core.h>
  2. #include <Rocket/Debugger.h>
  3. #include <Input.h>
  4. #include <Shell.h>
  5. #include "RenderInterfaceDirectX10.h"
  6. // Because we're a windows app
  7. #include <windows.h>
  8. // For _T unicode/mbcs macro
  9. #include <tchar.h>
  10. static Rocket::Core::Context* context = NULL;
  11. ShellRenderInterfaceExtensions *shell_renderer;
  12. void GameLoop()
  13. {
  14. context->Update();
  15. shell_renderer->PrepareRenderBuffer();
  16. context->Render();
  17. shell_renderer->PresentRenderBuffer();
  18. }
  19. 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))
  20. {
  21. ROCKET_UNUSED(instance_handle);
  22. ROCKET_UNUSED(previous_instance_handle);
  23. ROCKET_UNUSED(command_line);
  24. ROCKET_UNUSED(command_show);
  25. int window_width = 1024;
  26. int window_height = 768;
  27. RenderInterfaceDirectX10 directx_renderer;
  28. shell_renderer = &directx_renderer;
  29. // Generic OS initialisation, creates a window and does not attach OpenGL.
  30. if (!Shell::Initialise("../Samples/basic/directx/") ||
  31. !Shell::OpenWindow("DirectX 10 Sample", shell_renderer, window_width, window_height, true))
  32. {
  33. Shell::Shutdown();
  34. return -1;
  35. }
  36. // Install our DirectX render interface into Rocket.
  37. Rocket::Core::SetRenderInterface(&directx_renderer);
  38. ShellSystemInterface system_interface;
  39. Rocket::Core::SetSystemInterface(&system_interface);
  40. Rocket::Core::Initialise();
  41. // Create the main Rocket context and set it on the shell's input layer.
  42. context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(window_width, window_height));
  43. if (context == NULL)
  44. {
  45. Rocket::Core::Shutdown();
  46. Shell::Shutdown();
  47. return -1;
  48. }
  49. Rocket::Debugger::Initialise(context);
  50. Input::SetContext(context);
  51. shell_renderer->SetContext(context);
  52. Shell::LoadFonts("../../assets/");
  53. // Load and show the tutorial document.
  54. Rocket::Core::ElementDocument* document = context->LoadDocument("../../assets/demo.rml");
  55. if (document != NULL)
  56. {
  57. document->Show();
  58. document->RemoveReference();
  59. }
  60. Shell::EventLoop(GameLoop);
  61. // Shutdown Rocket.
  62. context->RemoveReference();
  63. Rocket::Core::Shutdown();
  64. Shell::CloseWindow();
  65. Shell::Shutdown();
  66. return 0;
  67. }