raylib-nuklear-texture.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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(void)
  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. // Load the nk_image
  23. struct nk_image img = LoadNuklearImage("resources/test-image.png");
  24. while (!WindowShouldClose())
  25. {
  26. // Input
  27. UpdateNuklear(ctx);
  28. // The window called "Image example" is opend
  29. if(nk_begin(ctx, "Image example", nk_rect(300, 100, img.w, img.h + 50), NK_WINDOW_MINIMIZABLE|NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE))
  30. {
  31. // Setup the layout
  32. nk_layout_row_static(ctx, img.h, img.w, 1);
  33. // Draw the image
  34. nk_image(ctx, img);
  35. }
  36. nk_end(ctx);
  37. // Draw the GUI
  38. BeginDrawing();
  39. ClearBackground(RAYWHITE);
  40. DrawNuklear(ctx);
  41. EndDrawing();
  42. }
  43. // Unload the Nuklear image
  44. UnloadNuklearImage(img);
  45. CloseWindow();
  46. return 0;
  47. }