models_billboard.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*******************************************************************************************
  2. *
  3. * raylib [models] example - Drawing billboards (adapted for HTML5 platform)
  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. #if defined(PLATFORM_WEB)
  13. #include <emscripten/emscripten.h>
  14. #endif
  15. //----------------------------------------------------------------------------------
  16. // Global Variables Definition
  17. //----------------------------------------------------------------------------------
  18. int screenWidth = 800;
  19. int screenHeight = 450;
  20. // Define the camera to look into our 3d world
  21. Camera camera = {{ 5.0f, 4.0f, 5.0f }, { 0.0f, 2.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f };
  22. Texture2D bill; // Our texture billboard
  23. Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard
  24. //----------------------------------------------------------------------------------
  25. // Module Functions Declaration
  26. //----------------------------------------------------------------------------------
  27. void UpdateDrawFrame(void); // Update and Draw one frame
  28. //----------------------------------------------------------------------------------
  29. // Main Enry Point
  30. //----------------------------------------------------------------------------------
  31. int main()
  32. {
  33. // Initialization
  34. //--------------------------------------------------------------------------------------
  35. InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards");
  36. bill = LoadTexture("resources/billboard.png"); // Our texture billboard
  37. SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
  38. #if defined(PLATFORM_WEB)
  39. emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
  40. #else
  41. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  42. //--------------------------------------------------------------------------------------
  43. // Main game loop
  44. while (!WindowShouldClose()) // Detect window close button or ESC key
  45. {
  46. UpdateDrawFrame();
  47. }
  48. #endif
  49. // De-Initialization
  50. //--------------------------------------------------------------------------------------
  51. UnloadTexture(bill); // Unload texture
  52. CloseWindow(); // Close window and OpenGL context
  53. //--------------------------------------------------------------------------------------
  54. return 0;
  55. }
  56. //----------------------------------------------------------------------------------
  57. // Module Functions Definition
  58. //----------------------------------------------------------------------------------
  59. void UpdateDrawFrame(void)
  60. {
  61. // Update
  62. //----------------------------------------------------------------------------------
  63. UpdateCamera(&camera); // Update internal camera and our camera
  64. //----------------------------------------------------------------------------------
  65. // Draw
  66. //----------------------------------------------------------------------------------
  67. BeginDrawing();
  68. ClearBackground(RAYWHITE);
  69. Begin3dMode(camera);
  70. DrawBillboard(camera, bill, billPosition, 2.0f, WHITE);
  71. DrawGrid(10, 1.0f); // Draw a grid
  72. End3dMode();
  73. DrawFPS(10, 10);
  74. EndDrawing();
  75. //----------------------------------------------------------------------------------
  76. }