2
0

test_image_loading.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*******************************************************************************************
  2. *
  3. * raylib test - Testing LoadImage() and CreateTexture()
  4. *
  5. * This example has been created using raylib 1.0 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2013 Ramon Santamaria (Ray San - [email protected])
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. int main()
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. int screenWidth = 800;
  17. int screenHeight = 450;
  18. InitWindow(screenWidth, screenHeight, "raylib test - Image loading");
  19. // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
  20. Image img = LoadImage("resources/raylib_logo.png");
  21. Texture2D texture = CreateTexture(img);
  22. UnloadImage(img);
  23. //---------------------------------------------------------------------------------------
  24. // Main game loop
  25. while (!WindowShouldClose()) // Detect window close button or ESC key
  26. {
  27. // Update
  28. //----------------------------------------------------------------------------------
  29. // TODO: Update your variables here
  30. //----------------------------------------------------------------------------------
  31. // Draw
  32. //----------------------------------------------------------------------------------
  33. BeginDrawing();
  34. ClearBackground(RAYWHITE);
  35. DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE);
  36. DrawText("this IS a texture!", 360, 370, 10, GRAY);
  37. EndDrawing();
  38. //----------------------------------------------------------------------------------
  39. }
  40. // De-Initialization
  41. //--------------------------------------------------------------------------------------
  42. UnloadTexture(texture); // Texture unloading
  43. CloseWindow(); // Close window and OpenGL context
  44. //--------------------------------------------------------------------------------------
  45. return 0;
  46. }