example_implot.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Sample app built with Dear ImGui and ImPlot
  2. // This app uses implot and imgui, but does not output to any backend! It only serves as a proof that an app can be built, linked, and run.
  3. #include "imgui.h"
  4. #include "implot.h"
  5. #include "stdio.h"
  6. int main(int, char**)
  7. {
  8. printf("sample_implot: start\n");
  9. IMGUI_CHECKVERSION();
  10. ImGui::CreateContext();
  11. ImPlot::CreateContext();
  12. // Additional imgui initialization needed when no backend is present
  13. ImGui::GetIO().DisplaySize = ImVec2(400.f, 400.f);
  14. ImGui::GetIO().Fonts->Build();
  15. // Render 500 frames
  16. for(int counter = 0; counter < 500; ++counter)
  17. {
  18. ImGui::NewFrame();
  19. if (ImGui::Begin("Hello, world!"))
  20. {
  21. ImGui::Text("Hello again");
  22. if (ImPlot::BeginPlot("My Plot"))
  23. {
  24. static double values[] = {1., 3., 5.};
  25. ImPlot::PlotLine("Values", values, 3);
  26. ImPlot::EndPlot();
  27. }
  28. #ifdef IMPLOT_INSTANTIATE_ALL_NUMERIC_TYPES
  29. if (ImPlot::BeginPlot("My Plot (long double)"))
  30. {
  31. static long double values[] = {1., 3., 5.};
  32. ImPlot::PlotLine("Values", values, 3);
  33. ImPlot::EndPlot();
  34. }
  35. #endif
  36. ImGui::End();
  37. }
  38. ImGui::Render();
  39. }
  40. ImPlot::DestroyContext();
  41. ImGui::DestroyContext();
  42. printf("sample_implot: end\n");
  43. return 0;
  44. }