FPS_50x50CubeGround.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "raylib.h"
  2. #include <stdlib.h>
  3. int main(void)
  4. {
  5. // Initialization
  6. //--------------------------------------------------------------------------------------
  7. const int screenWidth = 800;
  8. const int screenHeight = 450;
  9. InitWindow(screenWidth, screenHeight, "raylib example.");
  10. // We generate a checked image for texturing
  11. Image checked = GenImageChecked(2, 2, 1, 1, RED, GREEN);
  12. Texture2D texture = LoadTextureFromImage(checked);
  13. UnloadImage(checked);
  14. Model model = { 0 };
  15. model = LoadModelFromMesh(GenMeshCube(1.0f, 1.0f, 1.0f));
  16. // Set checked texture as default diffuse component for all models material
  17. model.materials[0].maps[MAP_DIFFUSE].texture = texture;
  18. // Define the camera to look into our 3d world
  19. Camera camera = { { 5.0f, 5.0f, 5.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
  20. SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set camera mode
  21. //SetCameraMode(camera, CAMERA_ORBITAL); // Set a orbital camera mode
  22. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  23. //--------------------------------------------------------------------------------------
  24. // Main game loop
  25. while (!WindowShouldClose()) // Detect window close button or ESC key
  26. {
  27. // Update
  28. //----------------------------------------------------------------------------------
  29. UpdateCamera(&camera); // Update internal camera and our camera
  30. //----------------------------------------------------------------------------------
  31. // Draw
  32. //----------------------------------------------------------------------------------
  33. BeginDrawing();
  34. ClearBackground(RAYWHITE);
  35. BeginMode3D(camera);
  36. for(int x=0;x<50;x++){
  37. for(int z=0;z<50;z++){
  38. Vector3 position;
  39. position.x = x;
  40. position.y = 0;
  41. position.z = z;
  42. DrawModel(model, position, 1.0f, WHITE);
  43. }
  44. }
  45. EndMode3D();
  46. DrawFPS(0,0);
  47. EndDrawing();
  48. //----------------------------------------------------------------------------------
  49. }
  50. // De-Initialization
  51. UnloadTexture(texture); // Unload texture
  52. // Unload models data (GPU VRAM)
  53. UnloadModel(model);
  54. //--------------------------------------------------------------------------------------
  55. CloseWindow(); // Close window and OpenGL context
  56. //--------------------------------------------------------------------------------------
  57. return 0;
  58. }