您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

74 行
2.8 KiB

11 年前
11 年前
11 年前
11 年前
11 年前
11 年前
11 年前
11 年前
11 年前
11 年前
11 年前
11 年前
11 年前
  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()
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. int screenWidth = 800;
  17. 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 = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
  21. Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
  22. Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
  23. dwarf.material.texDiffuse = texture; // Set dwarf model diffuse texture
  24. Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
  25. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  26. //--------------------------------------------------------------------------------------
  27. // Main game loop
  28. while (!WindowShouldClose()) // Detect window close button or ESC key
  29. {
  30. // Update
  31. //----------------------------------------------------------------------------------
  32. //...
  33. //----------------------------------------------------------------------------------
  34. // Draw
  35. //----------------------------------------------------------------------------------
  36. BeginDrawing();
  37. ClearBackground(RAYWHITE);
  38. Begin3dMode(camera);
  39. DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
  40. DrawGrid(10, 1.0f); // Draw a grid
  41. DrawGizmo(position); // Draw gizmo
  42. End3dMode();
  43. DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY);
  44. DrawFPS(10, 10);
  45. EndDrawing();
  46. //----------------------------------------------------------------------------------
  47. }
  48. // De-Initialization
  49. //--------------------------------------------------------------------------------------
  50. UnloadTexture(texture); // Unload texture
  51. UnloadModel(dwarf); // Unload model
  52. CloseWindow(); // Close window and OpenGL context
  53. //--------------------------------------------------------------------------------------
  54. return 0;
  55. }