simple.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
  57. DrawText("Prssed", 0, 0, 20, RED);
  58. if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
  59. DrawText("Down", 0, 20, 20, GREEN);
  60. if (IsWindowFocused())
  61. DrawText("Focused", 100, 20, 20, WHITE);
  62. EndDrawing();
  63. //----------------------------------------------------------------------------------
  64. }
  65. // De-Initialization
  66. //--------------------------------------------------------------------------------------
  67. rlImGuiShutdown();
  68. UnloadTexture(image);
  69. CloseWindow(); // Close window and OpenGL context
  70. //--------------------------------------------------------------------------------------
  71. return 0;
  72. }