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.

72 lines
2.8 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [models] example - Drawing billboards
  4. *
  5. * This example has been created using raylib 1.2 (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 (Ray San - raysan@raysanweb.com)
  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 = {{ 10.0, 8.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
  21. Texture2D lena = LoadTexture("resources/lena.png"); // Our texture for billboard
  22. Rectangle eyesRec = { 225, 240, 155, 50 }; // Part of the texture to draw
  23. Vector3 billPosition = { 0.0, 0.0, 0.0 }; // Position where draw billboard
  24. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  25. //--------------------------------------------------------------------------------------
  26. // Main game loop
  27. while (!WindowShouldClose()) // Detect window close button or ESC key
  28. {
  29. // Update
  30. //----------------------------------------------------------------------------------
  31. if (IsKeyDown(KEY_LEFT)) camera.position.x -= 0.2;
  32. if (IsKeyDown(KEY_RIGHT)) camera.position.x += 0.2;
  33. if (IsKeyDown(KEY_UP)) camera.position.y -= 0.2;
  34. if (IsKeyDown(KEY_DOWN)) camera.position.y += 0.2;
  35. //----------------------------------------------------------------------------------
  36. // Draw
  37. //----------------------------------------------------------------------------------
  38. BeginDrawing();
  39. ClearBackground(RAYWHITE);
  40. Begin3dMode(camera);
  41. //DrawBillboard(camera, lena, billPosition, 1.0, WHITE);
  42. DrawBillboardRec(camera, lena, eyesRec, billPosition, 4.0, WHITE);
  43. DrawGrid(10.0, 1.0); // Draw a grid
  44. End3dMode();
  45. DrawFPS(10, 10);
  46. EndDrawing();
  47. //----------------------------------------------------------------------------------
  48. }
  49. // De-Initialization
  50. //--------------------------------------------------------------------------------------
  51. UnloadTexture(lena); // Unload texture
  52. CloseWindow(); // Close window and OpenGL context
  53. //--------------------------------------------------------------------------------------
  54. return 0;
  55. }