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.

79 lines
3.2 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. /*******************************************************************************************
  2. *
  3. * raylib [models] example - Load and draw a 3d model (OBJ)
  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) 2014 Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. int main(void)
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. const int screenWidth = 800;
  17. const int screenHeight = 450;
  18. InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading");
  19. // Define the camera to look into our 3d world
  20. Camera camera = { 0 };
  21. camera.position = (Vector3){ 8.0f, 8.0f, 8.0f }; // Camera position
  22. camera.target = (Vector3){ 0.0f, 2.5f, 0.0f }; // Camera looking at point
  23. camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
  24. camera.fovy = 45.0f; // Camera field-of-view Y
  25. camera.type = CAMERA_PERSPECTIVE; // Camera mode type
  26. Model model = LoadModel("resources/models/castle.obj"); // Load OBJ model
  27. Texture2D texture = LoadTexture("resources/models/castle_diffuse.png"); // Load model texture
  28. model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
  29. Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
  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. //...
  38. //----------------------------------------------------------------------------------
  39. // Draw
  40. //----------------------------------------------------------------------------------
  41. BeginDrawing();
  42. ClearBackground(RAYWHITE);
  43. BeginMode3D(camera);
  44. DrawModel(model, position, 0.2f, WHITE); // Draw 3d model with texture
  45. DrawGrid(10, 1.0f); // Draw a grid
  46. DrawGizmo(position); // Draw gizmo
  47. EndMode3D();
  48. DrawText("(c) Castle 3D model by Alberto Cano", screenWidth - 200, screenHeight - 20, 10, GRAY);
  49. DrawFPS(10, 10);
  50. EndDrawing();
  51. //----------------------------------------------------------------------------------
  52. }
  53. // De-Initialization
  54. //--------------------------------------------------------------------------------------
  55. UnloadTexture(texture); // Unload texture
  56. UnloadModel(model); // Unload model
  57. CloseWindow(); // Close window and OpenGL context
  58. //--------------------------------------------------------------------------------------
  59. return 0;
  60. }