raylib-nuklear-texture.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* ===============================================================
  2. *
  3. * EXAMPLE
  4. *
  5. * ===============================================================*/
  6. /*
  7. This example shows how to use the image API from raylib nuklear.
  8. And then display it.
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <raylib.h>
  13. #define RAYLIB_NUKLEAR_IMPLEMENTATION
  14. #include "raylib-nuklear.h"
  15. int main()
  16. {
  17. InitWindow(1280, 720, "[raylib-nuklear] - Texture/Image");
  18. // Initialize the context
  19. struct nk_context* ctx = InitNuklear(20);
  20. // Scale up the Nuklear GUI
  21. SetNuklearScaling(ctx, 1.2f);
  22. SetNuklearPosition(ctx, (Vector2){300.0f, 100.0f});
  23. // Load the nk_image
  24. struct nk_image img = LoadNuklearImage("resources/test-image.png");
  25. while (!WindowShouldClose())
  26. {
  27. // Input
  28. UpdateNuklear(ctx);
  29. // The window called "Image example" is opend
  30. if(nk_begin(ctx, "Image example", nk_rect(0, 0, img.w, img.h + 50), NK_WINDOW_MINIMIZABLE|NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE))
  31. {
  32. // Setup the layout
  33. nk_layout_row_static(ctx, img.h, img.w, 1);
  34. // Draw the image
  35. nk_image(ctx, img);
  36. }
  37. nk_end(ctx);
  38. // Draw the GUI
  39. BeginDrawing();
  40. ClearBackground(RAYWHITE);
  41. DrawNuklear(ctx);
  42. EndDrawing();
  43. }
  44. // Unload the Nuklear image
  45. UnloadNuklearImage(img);
  46. CloseWindow();
  47. return 0;
  48. }