TextureViewerMain.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/AnKi.h>
  6. using namespace anki;
  7. class TextureViewerUiNode : public SceneNode
  8. {
  9. public:
  10. TextureViewerUiNode(SceneGraph* scene, CString name)
  11. : SceneNode(scene, name)
  12. {
  13. SpatialComponent* spatialc = newComponent<SpatialComponent>();
  14. spatialc->setAlwaysVisible(true);
  15. UiComponent* uic = newComponent<UiComponent>();
  16. uic->init([](CanvasPtr& canvas, const void* ud) { static_cast<const TextureViewerUiNode*>(ud)->draw(canvas); },
  17. this);
  18. ANKI_CHECK_AND_IGNORE(getSceneGraph().getUiManager().newInstance(m_font, "EngineAssets/UbuntuMonoRegular.ttf",
  19. Array<U32, 1>{32}));
  20. }
  21. private:
  22. FontPtr m_font;
  23. void draw(CanvasPtr& canvas) const
  24. {
  25. ImGui::Begin("Console", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoTitleBar);
  26. canvas->pushFont(m_font, 32);
  27. ImGui::SetWindowPos(Vec2(0.0f, 0.0f));
  28. ImGui::SetWindowSize(Vec2(F32(canvas->getWidth()), F32(canvas->getHeight())));
  29. ImGui::PushStyleColor(ImGuiCol_Text, Vec4(0.0f, 0.0f, 0.0f, 1.0f));
  30. ImGui::TextWrapped("Test");
  31. ImGui::PopStyleColor();
  32. canvas->popFont();
  33. ImGui::End();
  34. }
  35. };
  36. class MyApp : public App
  37. {
  38. public:
  39. Error init(int argc, char** argv, CString appName)
  40. {
  41. HeapAllocator<U32> alloc(allocAligned, nullptr);
  42. StringAuto mainDataPath(alloc, ANKI_SOURCE_DIRECTORY);
  43. ConfigSet config = DefaultConfigSet::get();
  44. config.set("window_fullscreen", false);
  45. config.set("rsrc_dataPaths", mainDataPath);
  46. config.set("gr_validation", 0);
  47. ANKI_CHECK(config.setFromCommandLineArguments(argc - 1, argv + 1));
  48. ANKI_CHECK(App::init(config, allocAligned, nullptr));
  49. SceneGraph& scene = getSceneGraph();
  50. TextureViewerUiNode* node;
  51. ANKI_CHECK(scene.newSceneNode("TextureViewer", node));
  52. return Error::NONE;
  53. }
  54. Error userMainLoop(Bool& quit, Second elapsedTime) override
  55. {
  56. Input& input = getInput();
  57. if(input.getKey(KeyCode::ESCAPE))
  58. {
  59. quit = true;
  60. }
  61. return Error::NONE;
  62. }
  63. };
  64. int main(int argc, char* argv[])
  65. {
  66. Error err = Error::NONE;
  67. MyApp* app = new MyApp;
  68. err = app->init(argc, argv, "Texture Viewer");
  69. if(!err)
  70. {
  71. err = app->mainLoop();
  72. }
  73. delete app;
  74. if(err)
  75. {
  76. ANKI_LOGE("Error reported. Bye!!");
  77. }
  78. else
  79. {
  80. ANKI_LOGI("Bye!!");
  81. }
  82. return 0;
  83. }