You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.7 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [textures] example - Texture loading with mipmaps, mipmaps generation
  4. *
  5. * NOTE: On OpenGL 1.1, mipmaps are calculated 'manually', original image must be power-of-two
  6. * On OpenGL 3.3 and ES2, mipmaps are generated automatically
  7. *
  8. * This example has been created using raylib 1.1 (www.raylib.com)
  9. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  10. *
  11. * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
  12. *
  13. ********************************************************************************************/
  14. #include "raylib.h"
  15. int main()
  16. {
  17. // Initialization
  18. //--------------------------------------------------------------------------------------
  19. int screenWidth = 800;
  20. int screenHeight = 450;
  21. InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture mipmaps generation");
  22. // NOTE: To generate mipmaps for an image, image must be loaded first and converted to texture
  23. // with mipmaps option set to true on CreateTexture()
  24. Image image = LoadImage("resources/raylib_logo.png"); // Load image to CPU memory (RAM)
  25. Texture2D texture = LoadTextureFromImage(image, true); // Create texture and generate mipmaps
  26. UnloadImage(image); // Once texture has been created, we can unload image data from RAM
  27. //--------------------------------------------------------------------------------------
  28. // Main game loop
  29. while (!WindowShouldClose()) // Detect window close button or ESC key
  30. {
  31. // Update
  32. //----------------------------------------------------------------------------------
  33. // TODO: Update your variables here
  34. //----------------------------------------------------------------------------------
  35. // Draw
  36. //----------------------------------------------------------------------------------
  37. BeginDrawing();
  38. ClearBackground(RAYWHITE);
  39. DrawTexture(texture, screenWidth/2 - texture.width/2,
  40. screenHeight/2 - texture.height/2 - 30, WHITE);
  41. DrawText("this IS a texture with mipmaps! really!", 210, 360, 20, GRAY);
  42. EndDrawing();
  43. //----------------------------------------------------------------------------------
  44. }
  45. // De-Initialization
  46. //--------------------------------------------------------------------------------------
  47. UnloadTexture(texture); // Texture unloading
  48. CloseWindow(); // Close window and OpenGL context
  49. //--------------------------------------------------------------------------------------
  50. return 0;
  51. }