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.

85 lines
3.5 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [models] example - Cubicmap loading and drawing
  4. *
  5. * This example has been created using raylib 1.3 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2015 Ramon Santamaria (@raysan5)
  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 = {{ 16.0f, 14.0f, 16.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
  21. Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
  22. Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)
  23. Model map = LoadCubicmap(image); // Load cubicmap model (generate model from image)
  24. // NOTE: By default each cube is mapped to one part of texture atlas
  25. Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
  26. map.material.texDiffuse = texture; // Set map diffuse texture
  27. Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position
  28. UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
  29. SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
  30. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  31. //--------------------------------------------------------------------------------------
  32. // Main game loop
  33. while (!WindowShouldClose()) // Detect window close button or ESC key
  34. {
  35. // Update
  36. //----------------------------------------------------------------------------------
  37. UpdateCamera(&camera); // Update camera
  38. //----------------------------------------------------------------------------------
  39. // Draw
  40. //----------------------------------------------------------------------------------
  41. BeginDrawing();
  42. ClearBackground(RAYWHITE);
  43. Begin3dMode(camera);
  44. DrawModel(map, mapPosition, 1.0f, WHITE);
  45. End3dMode();
  46. DrawTextureEx(cubicmap, (Vector2){ screenWidth - cubicmap.width*4 - 20, 20 }, 0.0f, 4.0f, WHITE);
  47. DrawRectangleLines(screenWidth - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN);
  48. DrawText("cubicmap image used to", 658, 90, 10, GRAY);
  49. DrawText("generate map 3d model", 658, 104, 10, GRAY);
  50. DrawFPS(10, 10);
  51. EndDrawing();
  52. //----------------------------------------------------------------------------------
  53. }
  54. // De-Initialization
  55. //--------------------------------------------------------------------------------------
  56. UnloadTexture(cubicmap); // Unload cubicmap texture
  57. UnloadTexture(texture); // Unload map texture
  58. UnloadModel(map); // Unload map model
  59. CloseWindow(); // Close window and OpenGL context
  60. //--------------------------------------------------------------------------------------
  61. return 0;
  62. }