test_heightmap.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*******************************************************************************************
  2. *
  3. * raylib test - Testing Heightmap Loading and Drawing
  4. *
  5. * This example has been created using raylib 1.0 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2013 Ramon Santamaria (Ray San - [email protected])
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. int main()
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. int screenWidth = 800;
  17. int screenHeight = 450;
  18. Vector3 position = { 0.0, 0.0, 0.0 };
  19. // Define the camera to look into our 3d world
  20. Camera camera = {{ 12.0, 10.0, 12.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
  21. InitWindow(screenWidth, screenHeight, "raylib test - Heightmap loading and drawing");
  22. Image img = LoadImage("heightmap.png");
  23. Model map = LoadHeightmap(img, 4);
  24. Texture2D tex = CreateTexture(img);
  25. UnloadImage(img);
  26. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  27. //--------------------------------------------------------------------------------------
  28. // Main game loop
  29. while (!WindowShouldClose()) // Detect window close button or ESC key
  30. {
  31. // Update
  32. //----------------------------------------------------------------------------------
  33. // ...
  34. //----------------------------------------------------------------------------------
  35. // Draw
  36. //----------------------------------------------------------------------------------
  37. BeginDrawing();
  38. ClearBackground(RAYWHITE);
  39. Begin3dMode(camera);
  40. //DrawModel(map, position, 0.5f, MAROON);
  41. DrawModelEx(map, tex, position, 0.5f, WHITE); // Draw 3d model with texture
  42. DrawGrid(10.0, 1.0); // Draw a grid
  43. DrawGizmo(position, false);
  44. End3dMode();
  45. DrawFPS(10, 10);
  46. EndDrawing();
  47. //----------------------------------------------------------------------------------
  48. }
  49. // De-Initialization
  50. //--------------------------------------------------------------------------------------
  51. UnloadTexture(tex); // Unload texture
  52. UnloadModel(map); // Unload model
  53. CloseWindow(); // Close window and OpenGL context
  54. //--------------------------------------------------------------------------------------
  55. return 0;
  56. }