models_billboard.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*******************************************************************************************
  2. *
  3. * raylib [models] example - Drawing billboards
  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 - drawing billboards");
  19. // Define the camera to look into our 3d world
  20. Camera camera = {{ 5.0, 4.0, 5.0 }, { 0.0, 2.0, 0.0 }, { 0.0, 1.0, 0.0 }};
  21. Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
  22. Vector3 billPosition = { 0.0, 2.0, 0.0 }; // Position where draw billboard
  23. SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
  24. SetCameraPosition(camera.position); // Set internal camera position to match our camera position
  25. SetCameraTarget(camera.target); // Set internal camera target to match our camera target
  26. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  27. //--------------------------------------------------------------------------------------
  28. // Main game loop
  29. while (!WindowShouldClose()) // Detect window close button or ESC key
  30. {
  31. // Update
  32. //----------------------------------------------------------------------------------
  33. UpdateCamera(&camera); // Update internal camera and our camera
  34. //----------------------------------------------------------------------------------
  35. // Draw
  36. //----------------------------------------------------------------------------------
  37. BeginDrawing();
  38. ClearBackground(RAYWHITE);
  39. Begin3dMode(camera);
  40. DrawBillboard(camera, bill, billPosition, 2.0f, WHITE);
  41. DrawGrid(10.0, 1.0); // Draw a grid
  42. End3dMode();
  43. DrawFPS(10, 10);
  44. EndDrawing();
  45. //----------------------------------------------------------------------------------
  46. }
  47. // De-Initialization
  48. //--------------------------------------------------------------------------------------
  49. UnloadTexture(bill); // Unload texture
  50. CloseWindow(); // Close window and OpenGL context
  51. //--------------------------------------------------------------------------------------
  52. return 0;
  53. }