44
55uses
66{ $IFDEF LINUX} cthreads,{ $ENDIF}
7- Classes, SysUtils, CustApp, raylib, r3d;
7+ Classes, SysUtils, CustApp, raylib, r3d, rlGl, math ;
88
99type
1010 { TRayApplication }
1111 TRayApplication = class (TCustomApplication)
1212 protected
1313 procedure DoRun ; override;
14+ private
15+ sphere: TModel;
16+ camera: TCamera;
17+ materials: array [0 ..4 ] of TMaterial;
1418 public
1519 constructor Create(TheOwner: TComponent); override;
1620 destructor Destroy; override;
21+ procedure Init ;
22+ procedure Update ;
23+ procedure Draw ;
24+ procedure Close ;
1725 end ;
1826
19- const AppTitle = ' raylib - basic window ' ;
27+ const AppTitle = ' [r3d] - resize example ' ;
2028
2129{ TRayApplication }
2230
@@ -25,7 +33,7 @@ constructor TRayApplication.Create(TheOwner: TComponent);
2533 inherited Create(TheOwner);
2634
2735 InitWindow(800 , 600 , AppTitle); // for window settings, look at example - window flags
28-
36+ Init;
2937 SetTargetFPS(60 ); // Set our game to run at 60 frames-per-second
3038end ;
3139
@@ -35,11 +43,10 @@ procedure TRayApplication.DoRun;
3543 while (not WindowShouldClose) do // Detect window close button or ESC key
3644 begin
3745 // Update your variables here
38-
46+ Update;
3947 // Draw
4048 BeginDrawing();
41- ClearBackground(RAYWHITE);
42- DrawText(' Congrats! You created your first window!' , 190 , 200 , 20 , LIGHTGRAY);
49+ Draw;
4350 EndDrawing();
4451 end ;
4552
@@ -49,7 +56,7 @@ procedure TRayApplication.DoRun;
4956
5057destructor TRayApplication.Destroy;
5158begin
52- // De-Initialization
59+ close;
5360 CloseWindow(); // Close window and OpenGL context
5461
5562 // Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR...)
@@ -58,6 +65,88 @@ destructor TRayApplication.Destroy;
5865 inherited Destroy;
5966end ;
6067
68+ procedure TRayApplication.Init ;
69+ var i: integer;
70+ light: TR3D_Light;
71+ begin
72+ R3D_Init(GetScreenWidth(), GetScreenHeight(), R3D_FLAG_NONE);
73+ SetWindowState(FLAG_WINDOW_RESIZABLE);
74+ SetTargetFPS(60 );
75+
76+ sphere := LoadModelFromMesh(GenMeshSphere(0.5 , 64 , 64 ));
77+ UnloadMaterial(sphere.materials[0 ]);
78+
79+ for i := 0 to 4 do
80+ begin
81+ materials[i] := LoadMaterialDefault();
82+ materials[i].maps[MATERIAL_MAP_ALBEDO].color := ColorFromHSV(i / 5 * 330 , 1.0 , 1.0 );
83+ materials[i].maps[MATERIAL_MAP_OCCLUSION].value := 1 ;
84+ materials[i].maps[MATERIAL_MAP_ROUGHNESS].value := 1 ;
85+ materials[i].maps[MATERIAL_MAP_METALNESS].value := 0 ;
86+ end ;
87+
88+ camera.Create(Vector3Create(0 , 2 , 2 ), Vector3Create(0 , 0 , 0 ), Vector3Create(0 , 1 , 0 ), 60 , 0 );
89+
90+ light := R3D_CreateLight(R3D_LIGHT_DIR);
91+
92+ R3D_SetLightDirection(light, Vector3Create( 0 , 0 , -1 ));
93+ R3D_SetLightActive(light, true);
94+
95+ end ;
96+
97+ procedure TRayApplication.Update ;
98+ var keep, linear: boolean;
99+ begin
100+ UpdateCamera(@camera, CAMERA_ORBITAL);
101+
102+ if IsKeyPressed(KEY_R) then
103+ begin
104+ keep := R3D_HasState(R3D_FLAG_ASPECT_KEEP);
105+ if (keep) then R3D_ClearState(R3D_FLAG_ASPECT_KEEP)
106+ else R3D_SetState(R3D_FLAG_ASPECT_KEEP);
107+ end ;
108+
109+ if (IsKeyPressed(KEY_F)) then
110+ begin
111+ linear := R3D_HasState(R3D_FLAG_BLIT_LINEAR);
112+ if (linear) then R3D_ClearState(R3D_FLAG_BLIT_LINEAR)
113+ else R3D_SetState(R3D_FLAG_BLIT_LINEAR);
114+ end ;
115+ end ;
116+
117+ procedure TRayApplication.Draw ;
118+ var keep, linear: boolean; i: integer;
119+ begin
120+ keep := R3D_HasState(R3D_FLAG_ASPECT_KEEP);
121+ linear := R3D_HasState(R3D_FLAG_BLIT_LINEAR);
122+
123+ if (keep) then
124+ ClearBackground(BLACK);
125+
126+
127+ R3D_Begin(camera);
128+ rlPushMatrix();
129+ for i := 0 to 4 do
130+ begin
131+ sphere.materials[0 ] := materials[i];
132+ R3D_DrawModel(sphere, Vector3Create( i - 2 , 0 , 0 ), 1.0 );
133+ end ;
134+ rlPopMatrix();
135+ R3D_End();
136+
137+ if keep then DrawText(' (R)esize mode: KEEP' , 10 , 10 , 20 , BLACK) else
138+ DrawText(' (R)esize mode: EXPAND' , 10 , 10 , 20 , BLACK);
139+
140+ if linear then DrawText(' (F)ilter mode: LINEAR' , 10 , 40 , 20 , BLACK) else
141+ DrawText(' (F)ilter mode: NEAREST' , 10 , 40 , 20 , BLACK);
142+ end ;
143+
144+ procedure TRayApplication.Close ;
145+ begin
146+ UnloadModel(sphere);
147+ R3D_Close();
148+ end ;
149+
61150var
62151 Application: TRayApplication;
63152begin
0 commit comments