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.

75 lines
2.8 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [models] example - Heightmap loading and drawing
  4. *
  5. * This example has been created using raylib 1.1 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
  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 [models] example - heightmap loading and drawing");
  19. // Define the camera to look into our 3d world
  20. Camera camera = {{ 10.0, 12.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
  21. Image img = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
  22. Texture2D texture = LoadTextureFromImage(img, false); // Convert image to texture (VRAM)
  23. Model map = LoadHeightmap(img, 4); // Load heightmap model
  24. SetModelTexture(&map, texture); // Bind texture to model
  25. Vector3 mapPosition = { -4, 0.0, -4 }; // Set model position
  26. UnloadImage(img); // Unload heightmap image from RAM, already uploaded to VRAM
  27. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  28. //--------------------------------------------------------------------------------------
  29. // Main game loop
  30. while (!WindowShouldClose()) // Detect window close button or ESC key
  31. {
  32. // Update
  33. //----------------------------------------------------------------------------------
  34. // ...
  35. //----------------------------------------------------------------------------------
  36. // Draw
  37. //----------------------------------------------------------------------------------
  38. BeginDrawing();
  39. ClearBackground(RAYWHITE);
  40. Begin3dMode(camera);
  41. DrawModel(map, mapPosition, 0.5f, MAROON);
  42. DrawGrid(10.0, 1.0);
  43. DrawGizmo(mapPosition);
  44. End3dMode();
  45. DrawFPS(10, 10);
  46. EndDrawing();
  47. //----------------------------------------------------------------------------------
  48. }
  49. // De-Initialization
  50. //--------------------------------------------------------------------------------------
  51. UnloadTexture(texture); // Unload texture
  52. UnloadModel(map); // Unload model
  53. CloseWindow(); // Close window and OpenGL context
  54. //--------------------------------------------------------------------------------------
  55. return 0;
  56. }