simple.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*******************************************************************************************
  2. *
  3. * raylib-extras [ImGui] example - Simple Integration
  4. *
  5. * This is a simple ImGui Integration
  6. * It is done using C++ but with C style code
  7. * It can be done in C as well if you use the C ImGui wrapper
  8. * https://github.com/cimgui/cimgui
  9. *
  10. * Copyright (c) 2021 Jeffery Myers
  11. *
  12. ********************************************************************************************/
  13. #include "raylib.h"
  14. #include "raymath.h"
  15. #include "imgui.h"
  16. #include "rlImGui.h"
  17. // DPI scaling functions
  18. float ScaleToDPIF(float value)
  19. {
  20. return GetWindowScaleDPI().x * value;
  21. }
  22. int ScaleToDPII(int value)
  23. {
  24. return int(GetWindowScaleDPI().x * value);
  25. }
  26. int main(int argc, char* argv[])
  27. {
  28. // Initialization
  29. //--------------------------------------------------------------------------------------
  30. int screenWidth = 1280;
  31. int screenHeight = 800;
  32. SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE);
  33. InitWindow(screenWidth, screenHeight, "raylib-Extras [ImGui] example - simple ImGui Demo");
  34. SetTargetFPS(144);
  35. rlImGuiSetup(true);
  36. Texture image = LoadTexture("resources/parrots.png");
  37. // Main game loop
  38. while (!WindowShouldClose()) // Detect window close button or ESC key
  39. {
  40. BeginDrawing();
  41. ClearBackground(DARKGRAY);
  42. // start ImGui Conent
  43. rlImGuiBegin();
  44. // show ImGui Content
  45. bool open = true;
  46. ImGui::ShowDemoWindow(&open);
  47. open = true;
  48. if (ImGui::Begin("Test Window", &open))
  49. {
  50. ImGui::TextUnformatted(ICON_FA_JEDI);
  51. rlImGuiImage(&image);
  52. }
  53. ImGui::End();
  54. // end ImGui Content
  55. rlImGuiEnd();
  56. EndDrawing();
  57. //----------------------------------------------------------------------------------
  58. }
  59. // De-Initialization
  60. //--------------------------------------------------------------------------------------
  61. rlImGuiShutdown();
  62. UnloadTexture(image);
  63. CloseWindow(); // Close window and OpenGL context
  64. //--------------------------------------------------------------------------------------
  65. return 0;
  66. }