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.

54 lines
2.4 KiB

  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. -- This example has been created using raylib 1.6 (www.raylib.com)
  8. -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  9. --
  10. -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
  11. --
  12. -------------------------------------------------------------------------------------------
  13. -- Initialization
  14. -------------------------------------------------------------------------------------------
  15. local screenWidth = 800
  16. local screenHeight = 450
  17. InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading")
  18. -- NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
  19. local image = LoadImage("resources/raylib_logo.png") -- Loaded in CPU memory (RAM)
  20. local texture = LoadTextureFromImage(image) -- Image converted to texture, GPU memory (VRAM)
  21. UnloadImage(image) -- Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
  22. -------------------------------------------------------------------------------------------
  23. -- Main game loop
  24. while not WindowShouldClose() do -- Detect window close button or ESC key
  25. -- Update
  26. ---------------------------------------------------------------------------------------
  27. -- TODO: Update your variables here
  28. ---------------------------------------------------------------------------------------
  29. -- Draw
  30. ---------------------------------------------------------------------------------------
  31. BeginDrawing()
  32. ClearBackground(RAYWHITE)
  33. DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE)
  34. DrawText("this IS a texture loaded from an image!", 300, 370, 10, GRAY)
  35. EndDrawing()
  36. ---------------------------------------------------------------------------------------
  37. end
  38. -- De-Initialization
  39. -------------------------------------------------------------------------------------------
  40. UnloadTexture(texture) -- Texture unloading
  41. CloseWindow() -- Close window and OpenGL context
  42. -------------------------------------------------------------------------------------------