core_3d_mode.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Initialize 3d mode
  4. *
  5. * This example has been created using raylib 1.0 (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 (@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 [core] example - 3d mode");
  19. // Define the camera to look into our 3d world
  20. Camera camera;
  21. camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position
  22. camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point
  23. camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
  24. Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
  25. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  26. //--------------------------------------------------------------------------------------
  27. // Main game loop
  28. while (!WindowShouldClose()) // Detect window close button or ESC key
  29. {
  30. // Update
  31. //----------------------------------------------------------------------------------
  32. // TODO: Update your variables here
  33. //----------------------------------------------------------------------------------
  34. // Draw
  35. //----------------------------------------------------------------------------------
  36. BeginDrawing();
  37. ClearBackground(RAYWHITE);
  38. Begin3dMode(camera);
  39. DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
  40. DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
  41. DrawGrid(10, 1.0f);
  42. End3dMode();
  43. DrawText("Welcome to the third dimension!", 10, 40, 20, DARKGRAY);
  44. DrawFPS(10, 10);
  45. EndDrawing();
  46. //----------------------------------------------------------------------------------
  47. }
  48. // De-Initialization
  49. //--------------------------------------------------------------------------------------
  50. CloseWindow(); // Close window and OpenGL context
  51. //--------------------------------------------------------------------------------------
  52. return 0;
  53. }