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.

72 lines
3.2 KiB

  1. -------------------------------------------------------------------------------------------
  2. --
  3. -- raylib [models] example - Heightmap loading and drawing
  4. --
  5. -- This example has been created using raylib 1.6 (www.raylib.com)
  6. -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. --
  8. -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
  9. --
  10. -------------------------------------------------------------------------------------------
  11. -- Initialization
  12. -------------------------------------------------------------------------------------------
  13. local screenWidth = 800
  14. local screenHeight = 450
  15. InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing")
  16. -- Define our custom camera to look into our 3d world
  17. local camera = Camera(Vector3(18.0, 16.0, 18.0), Vector3(0.0, 0.0, 0.0), Vector3(0.0, 1.0, 0.0), 45.0)
  18. local image = LoadImage("resources/heightmap.png") -- Load heightmap image (RAM)
  19. local texture = LoadTextureFromImage(image) -- Convert image to texture (VRAM)
  20. local map = LoadHeightmap(image, Vector3(16, 8, 16)) -- Load heightmap model with defined size
  21. map.material.texDiffuse = texture -- Set map diffuse texture
  22. local mapPosition = Vector3(-8.0, 0.0, -8.0) -- Set model position (depends on model scaling!)
  23. UnloadImage(image) -- Unload heightmap image from RAM, already uploaded to VRAM
  24. SetCameraMode(CameraMode.ORBITAL) -- Set an orbital camera mode
  25. SetCameraPosition(camera.position) -- Set internal camera position to match our custom camera position
  26. SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
  27. ----------------------------------------------------------------------------------------
  28. -- Main game loop
  29. while not WindowShouldClose() do -- Detect window close button or ESC key
  30. -- Update
  31. ---------------------------------------------------------------------------------------
  32. camera = UpdateCamera(camera) -- Update internal camera and our camera
  33. ---------------------------------------------------------------------------------------
  34. -- Draw
  35. ---------------------------------------------------------------------------------------
  36. BeginDrawing()
  37. ClearBackground(RAYWHITE)
  38. Begin3dMode(camera)
  39. -- NOTE: Model is scaled to 1/4 of its original size (128x128 units)
  40. DrawModel(map, mapPosition, 1.0, RED)
  41. DrawGrid(20, 1.0)
  42. End3dMode()
  43. DrawTexture(texture, screenWidth - texture.width - 20, 20, WHITE)
  44. DrawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, GREEN)
  45. DrawFPS(10, 10)
  46. EndDrawing()
  47. ---------------------------------------------------------------------------------------
  48. end
  49. -- De-Initialization
  50. -------------------------------------------------------------------------------------------
  51. UnloadTexture(texture) -- Unload texture
  52. UnloadModel(map) -- Unload model
  53. CloseWindow() -- Close window and OpenGL context
  54. -------------------------------------------------------------------------------------------