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.

74 line
2.7 KiB

  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(void)
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. const int screenWidth = 800;
  17. const 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 = { 0 };
  21. camera.position = (Vector3){ 5.0f, 4.0f, 5.0f };
  22. camera.target = (Vector3){ 0.0f, 2.0f, 0.0f };
  23. camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
  24. camera.fovy = 45.0f;
  25. camera.type = CAMERA_PERSPECTIVE;
  26. Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
  27. Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard
  28. SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
  29. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  30. //--------------------------------------------------------------------------------------
  31. // Main game loop
  32. while (!WindowShouldClose()) // Detect window close button or ESC key
  33. {
  34. // Update
  35. //----------------------------------------------------------------------------------
  36. UpdateCamera(&camera); // Update camera
  37. //----------------------------------------------------------------------------------
  38. // Draw
  39. //----------------------------------------------------------------------------------
  40. BeginDrawing();
  41. ClearBackground(RAYWHITE);
  42. BeginMode3D(camera);
  43. DrawGrid(10, 1.0f); // Draw a grid
  44. DrawBillboard(camera, bill, billPosition, 2.0f, WHITE);
  45. EndMode3D();
  46. DrawFPS(10, 10);
  47. EndDrawing();
  48. //----------------------------------------------------------------------------------
  49. }
  50. // De-Initialization
  51. //--------------------------------------------------------------------------------------
  52. UnloadTexture(bill); // Unload texture
  53. CloseWindow(); // Close window and OpenGL context
  54. //--------------------------------------------------------------------------------------
  55. return 0;
  56. }