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

79 行
3.0 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [models] example - Drawing billboards
  4. *
  5. * Example originally created with raylib 1.3, last time updated with raylib 3.5
  6. *
  7. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  8. * BSD-like license that allows static linking with closed source software
  9. *
  10. * Copyright (c) 2015-2022 Ramon Santamaria (@raysan5)
  11. *
  12. ********************************************************************************************/
  13. #include "raylib.h"
  14. //------------------------------------------------------------------------------------
  15. // Program main entry point
  16. //------------------------------------------------------------------------------------
  17. int main(void)
  18. {
  19. // Initialization
  20. //--------------------------------------------------------------------------------------
  21. const int screenWidth = 800;
  22. const int screenHeight = 450;
  23. InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards");
  24. // Define the camera to look into our 3d world
  25. Camera camera = { 0 };
  26. camera.position = (Vector3){ 5.0f, 4.0f, 5.0f };
  27. camera.target = (Vector3){ 0.0f, 2.0f, 0.0f };
  28. camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
  29. camera.fovy = 45.0f;
  30. camera.projection = CAMERA_PERSPECTIVE;
  31. Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
  32. Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard
  33. SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
  34. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  35. //--------------------------------------------------------------------------------------
  36. // Main game loop
  37. while (!WindowShouldClose()) // Detect window close button or ESC key
  38. {
  39. // Update
  40. //----------------------------------------------------------------------------------
  41. UpdateCamera(&camera);
  42. //----------------------------------------------------------------------------------
  43. // Draw
  44. //----------------------------------------------------------------------------------
  45. BeginDrawing();
  46. ClearBackground(RAYWHITE);
  47. BeginMode3D(camera);
  48. DrawGrid(10, 1.0f); // Draw a grid
  49. DrawBillboard(camera, bill, billPosition, 2.0f, WHITE);
  50. EndMode3D();
  51. DrawFPS(10, 10);
  52. EndDrawing();
  53. //----------------------------------------------------------------------------------
  54. }
  55. // De-Initialization
  56. //--------------------------------------------------------------------------------------
  57. UnloadTexture(bill); // Unload texture
  58. CloseWindow(); // Close window and OpenGL context
  59. //--------------------------------------------------------------------------------------
  60. return 0;
  61. }