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.

69 rivejä
2.9 KiB

11 kuukautta sitten
5 vuotta sitten
5 vuotta sitten
9 vuotta sitten
3 vuotta sitten
  1. /*******************************************************************************************
  2. *
  3. * raylib [textures] example - Image loading and texture creation
  4. *
  5. * NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
  6. *
  7. * Example originally created with raylib 1.3, last time updated with raylib 1.3
  8. *
  9. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  10. * BSD-like license that allows static linking with closed source software
  11. *
  12. * Copyright (c) 2015-2024 Ramon Santamaria (@raysan5)
  13. *
  14. ********************************************************************************************/
  15. #include "raylib.h"
  16. //------------------------------------------------------------------------------------
  17. // Program main entry point
  18. //------------------------------------------------------------------------------------
  19. int main(void)
  20. {
  21. // Initialization
  22. //--------------------------------------------------------------------------------------
  23. const int screenWidth = 800;
  24. const int screenHeight = 450;
  25. InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading");
  26. // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
  27. Image image = LoadImage("resources/raylib_logo.png"); // Loaded in CPU memory (RAM)
  28. Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM)
  29. UnloadImage(image); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
  30. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  31. //---------------------------------------------------------------------------------------
  32. // Main game loop
  33. while (!WindowShouldClose()) // Detect window close button or ESC key
  34. {
  35. // Update
  36. //----------------------------------------------------------------------------------
  37. // TODO: Update your variables here
  38. //----------------------------------------------------------------------------------
  39. // Draw
  40. //----------------------------------------------------------------------------------
  41. BeginDrawing();
  42. ClearBackground(RAYWHITE);
  43. DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE);
  44. DrawText("this IS a texture loaded from an image!", 300, 370, 10, GRAY);
  45. EndDrawing();
  46. //----------------------------------------------------------------------------------
  47. }
  48. // De-Initialization
  49. //--------------------------------------------------------------------------------------
  50. UnloadTexture(texture); // Texture unloading
  51. CloseWindow(); // Close window and OpenGL context
  52. //--------------------------------------------------------------------------------------
  53. return 0;
  54. }