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.

80 lines
3.0 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [models] example - Cubicmap loading and drawing
  4. *
  5. * This example has been created using raylib 1.2 (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 - cubesmap loading and drawing");
  19. // Define the camera to look into our 3d world
  20. Camera camera = {{ 7.0, 7.0, 7.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
  21. Image img = LoadImage("resources/cubicmap.png"); // Load cubesmap image (RAM)
  22. Texture2D texture = LoadTextureFromImage(img, false); // Convert image to texture (VRAM)
  23. Model map = LoadCubicmap(img); // Load cubicmap model
  24. SetModelTexture(&map, texture); // Bind texture to model
  25. Vector3 mapPosition = { -1, 0.0, -1 }; // Set model position
  26. UnloadImage(img); // Unload cubesmap 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. if (IsKeyDown(KEY_UP)) camera.position.y += 0.2f;
  35. else if (IsKeyDown(KEY_DOWN)) camera.position.y -= 0.2f;
  36. if (IsKeyDown(KEY_RIGHT)) camera.position.z += 0.2f;
  37. else if (IsKeyDown(KEY_LEFT)) camera.position.z -= 0.2f;
  38. //----------------------------------------------------------------------------------
  39. // Draw
  40. //----------------------------------------------------------------------------------
  41. BeginDrawing();
  42. ClearBackground(RAYWHITE);
  43. Begin3dMode(camera);
  44. DrawModel(map, mapPosition, 1.0f, MAROON);
  45. DrawGrid(10.0, 1.0);
  46. DrawGizmo(mapPosition);
  47. End3dMode();
  48. DrawFPS(10, 10);
  49. EndDrawing();
  50. //----------------------------------------------------------------------------------
  51. }
  52. // De-Initialization
  53. //--------------------------------------------------------------------------------------
  54. UnloadTexture(texture); // Unload texture
  55. UnloadModel(map); // Unload model
  56. CloseWindow(); // Close window and OpenGL context
  57. //--------------------------------------------------------------------------------------
  58. return 0;
  59. }