|
| 1 | +program r3d_fog; |
| 2 | + |
| 3 | +{$mode objfpc}{$H+} |
| 4 | + |
| 5 | +uses |
| 6 | +{$IFDEF LINUX} cthreads,{$ENDIF} |
| 7 | + Classes, SysUtils, CustApp, raylib, r3d; |
| 8 | + |
| 9 | +type |
| 10 | + { TRayApplication } |
| 11 | + TRayApplication = class(TCustomApplication) |
| 12 | + protected |
| 13 | + procedure DoRun; override; |
| 14 | + private |
| 15 | + sponza: TModel; |
| 16 | + camera: TCamera3D; |
| 17 | + procedure Init; |
| 18 | + procedure Update; |
| 19 | + procedure Draw; |
| 20 | + Procedure Close; |
| 21 | + public |
| 22 | + constructor Create(TheOwner: TComponent); override; |
| 23 | + destructor Destroy; override; |
| 24 | + end; |
| 25 | + |
| 26 | + const AppTitle = '[r3d] - fog example'; |
| 27 | + |
| 28 | +{ TRayApplication } |
| 29 | + |
| 30 | +constructor TRayApplication.Create(TheOwner: TComponent); |
| 31 | +begin |
| 32 | + inherited Create(TheOwner); |
| 33 | + |
| 34 | + InitWindow(800, 600, AppTitle); // for window settings, look at example - window flags |
| 35 | + Init; |
| 36 | + SetTargetFPS(60); // Set our game to run at 60 frames-per-second |
| 37 | +end; |
| 38 | + |
| 39 | +procedure TRayApplication.DoRun; |
| 40 | +begin |
| 41 | + |
| 42 | + while (not WindowShouldClose) do // Detect window close button or ESC key |
| 43 | + begin |
| 44 | + // Update your variables here |
| 45 | + Update; |
| 46 | + // Draw |
| 47 | + BeginDrawing(); |
| 48 | + Draw; |
| 49 | + EndDrawing(); |
| 50 | + end; |
| 51 | + |
| 52 | + // Stop program loop |
| 53 | + Terminate; |
| 54 | +end; |
| 55 | + |
| 56 | +procedure TRayApplication.Init; |
| 57 | +var i: integer; |
| 58 | + light: TR3D_Light; |
| 59 | +begin |
| 60 | + R3D_Init(GetScreenWidth(), GetScreenHeight(), 0); |
| 61 | + SetTargetFPS(60); |
| 62 | + |
| 63 | + sponza := LoadModel('resources/sponza.glb'); |
| 64 | + |
| 65 | + for i := 0 to sponza.materialCount -1 do |
| 66 | + begin |
| 67 | + sponza.materials[i].maps[MATERIAL_MAP_ALBEDO].color := WHITE; |
| 68 | + sponza.materials[i].maps[MATERIAL_MAP_OCCLUSION].value := 1.0; |
| 69 | + sponza.materials[i].maps[MATERIAL_MAP_ROUGHNESS].value := 1.0; |
| 70 | + sponza.materials[i].maps[MATERIAL_MAP_METALNESS].value := 1.0; |
| 71 | + end; |
| 72 | + |
| 73 | + R3D_SetFogMode(R3D_FOG_EXP); |
| 74 | + |
| 75 | + light := R3D_CreateLight(R3D_LIGHT_DIR); |
| 76 | + R3D_SetLightDirection(light, Vector3Create( 0, -1, 0 )); |
| 77 | + R3D_SetLightActive(light, true); |
| 78 | + |
| 79 | + camera.Create(Vector3Create(0,0,0), Vector3Create(0,0,-1), Vector3Create(0,1,0), 60); |
| 80 | + |
| 81 | + DisableCursor(); |
| 82 | + |
| 83 | +end; |
| 84 | + |
| 85 | +procedure TRayApplication.Update; |
| 86 | +begin |
| 87 | + UpdateCamera(@camera, CAMERA_FREE); |
| 88 | +end; |
| 89 | + |
| 90 | +procedure TRayApplication.Draw; |
| 91 | +begin |
| 92 | + R3D_Begin(camera); |
| 93 | + R3D_DrawModel(sponza, Vector3Create(0,0,0), 1.0); |
| 94 | + R3D_End(); |
| 95 | + |
| 96 | + DrawFPS(10, 10); |
| 97 | +end; |
| 98 | + |
| 99 | +procedure TRayApplication.Close; |
| 100 | +begin |
| 101 | + UnloadModel(sponza); |
| 102 | + R3D_Close(); |
| 103 | +end; |
| 104 | + |
| 105 | +destructor TRayApplication.Destroy; |
| 106 | +begin |
| 107 | + Close; |
| 108 | + CloseWindow(); // Close window and OpenGL context |
| 109 | + |
| 110 | + // Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR...) |
| 111 | + TraceLog(LOG_INFO, 'your first window is close and destroy'); |
| 112 | + |
| 113 | + inherited Destroy; |
| 114 | +end; |
| 115 | + |
| 116 | +var |
| 117 | + Application: TRayApplication; |
| 118 | +begin |
| 119 | + Application:=TRayApplication.Create(nil); |
| 120 | + Application.Title:=AppTitle; |
| 121 | + Application.Run; |
| 122 | + Application.Free; |
| 123 | +end. |
| 124 | + |
0 commit comments