Skip to content

Commit 45c8072

Browse files
committed
update SDL2 Demo
+ Locking FPS
1 parent 1616408 commit 45c8072

File tree

9 files changed

+406
-306
lines changed

9 files changed

+406
-306
lines changed

PasImGui_SDL2_OpenGL3_Demo/ImGui_SDL2_OpenGL3_Demo.dpr

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
Program ImGui_SDL2_OpenGL3_Demo;
1616
{$IFDEF FPC}
17-
{$mode objfpc}{$H+}{$J-}
17+
{$mode Delphi}{$H+}{$J-}
1818
{$Optimization FASTMATH}
1919
{$ENDIF}
2020
{$IfDef LINUX}
@@ -38,7 +38,7 @@ Uses
3838
cmem,
3939
{$ENDIF}
4040
Math,
41-
SysUtils,
41+
SysUtils, ctypes,
4242
sdl2,
4343
glad_gl,
4444
PasImGui,
@@ -48,6 +48,8 @@ Uses
4848
PasImGui.Renderer.OpenGL3,
4949
TestWindow, CustomNodeGraph;
5050

51+
{ TODO: Test with LIBGL_ALWAYS_SOFTWARE - Time : 9/23/2024 4:34:43 PM }
52+
5153
Var
5254
counter: Integer;
5355
ShowPascalDemoWindow: Boolean = False;
@@ -82,7 +84,7 @@ Var
8284
var
8385
i: Integer;
8486
begin
85-
if not ImGui.Begin_('ImPlot Pascal Demo') then
87+
if not ImGui.Begin_('ImPlot Pascal Demo', nil, ImGuiWindowFlags_NoDocking) then
8688
begin
8789
ImGui.End_();
8890
exit;
@@ -308,7 +310,11 @@ Var
308310
end;
309311
Result := 1;
310312
end;
311-
313+
var
314+
FrameRate : Single = 60.0; // Default to 60 FPS
315+
elapsedMS : Single;
316+
SleepTime : Integer;
317+
Starting_tick: Cuint64;
312318
Begin
313319
{ TODO: This is here for testing - Remove this later :V }
314320
//DeleteFile('MyApp.ini');
@@ -341,7 +347,7 @@ Begin
341347
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
342348
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
343349
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
344-
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
350+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
345351
{$EndIf}
346352

347353
// From 2.0.18: Enable native IME.
@@ -418,7 +424,7 @@ Begin
418424
// Load Fonts
419425
//IO^.Fonts^.AddFontDefault();
420426
IO^.Fonts^.AddFontFromFileTTF('fonts/DroidSans.ttf', 25.0);
421-
IO^.Fonts^.AddFontFromFileTTF('fonts/JetBrainsMonoNerdFontPropo-Italic.ttf ', 28.0);
427+
//IO^.Fonts^.AddFontFromFileTTF('fonts/JetBrainsMonoNerdFontPropo-Italic.ttf ', 28.0);
422428

423429
// Background Color
424430
clearColor.x := 0.45;
@@ -433,6 +439,7 @@ Begin
433439
SDL_SetEventFilter(@window_redraw_on_resize, nil);
434440
While Not quit Do
435441
Begin
442+
starting_tick := SDL_GetPerformanceCounter();
436443
//handle input
437444
While SDL_PollEvent(@e) <> 0 Do
438445
Begin
@@ -443,8 +450,17 @@ Begin
443450
(e.window.windowID = SDL_GetWindowID(window)) Then
444451
quit := True;
445452
End;
446-
447453
DrawGUI();
454+
455+
// Locaked Frame Rate
456+
if FrameRate > 0 then
457+
begin
458+
elapsedMS := Single(SDL_GetPerformanceCounter() - starting_tick) / Single(SDL_GetPerformanceFrequency()) * 1000.0;
459+
SleepTime := Floor((1000.0 / FrameRate) - elapsedMS);
460+
if SleepTime <= 0 then
461+
SleepTime := 0;
462+
SDL_Delay(SleepTime);
463+
end;
448464
End;
449465
testwin.Free;
450466

PasImGui_SDL2_OpenGL3_Demo/ImGui_SDL2_OpenGL3_Demo.lpi

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<UseVersionInfo Value="True"/>
2626
<MajorVersionNr Value="1"/>
2727
</VersionInfo>
28-
<BuildModes Count="6">
28+
<BuildModes Count="7">
2929
<Item1 Name="Default" Default="True"/>
3030
<Item2 Name="Debug_windows_32">
3131
<CompilerOptions>
@@ -152,15 +152,15 @@
152152
</SearchPaths>
153153
<CodeGeneration>
154154
<SmartLinkUnit Value="True"/>
155-
<TargetProcessor Value="COREAVX2"/>
155+
<TargetCPU Value="x86_64"/>
156+
<TargetOS Value="win64"/>
156157
<Optimizations>
157158
<OptimizationLevel Value="3"/>
158159
</Optimizations>
159160
</CodeGeneration>
160161
<Linking>
161162
<Debugging>
162-
<GenerateDebugInfo Value="False"/>
163-
<RunWithoutDebug Value="True"/>
163+
<DebugInfoType Value="dsDwarf3"/>
164164
</Debugging>
165165
<LinkSmart Value="True"/>
166166
<Options>
@@ -201,11 +201,38 @@
201201
</Linking>
202202
</CompilerOptions>
203203
</Item6>
204-
<SharedMatrixOptions Count="4">
205-
<Item1 ID="825586496411" Value="-Xm"/>
206-
<Item2 ID="187403506791" Modes="Release_windows_64,Release_linux_64,Release_windows_32" Value="-CfAVX -CpCOREAVX -OpCOREAVX"/>
207-
<Item3 ID="940053534749" Value="-FWtwpo4-1.wpo -OWall"/>
208-
<Item4 ID="883228556756" Modes="Release_windows_64,Debug_windows_64,Release_windows_32,Release_linux_64,Debug_windows_32" Value="-dSDL2"/>
204+
<Item7 Name="Debug_linux_64">
205+
<CompilerOptions>
206+
<Version Value="11"/>
207+
<PathDelim Value="\"/>
208+
<Target>
209+
<Filename Value=".\Linux64\ImGui_SDL2_OpenGL3_Demo"/>
210+
</Target>
211+
<SearchPaths>
212+
<IncludeFiles Value="$(ProjOutDir);..\src"/>
213+
<Libraries Value="..\libs\static\linux64"/>
214+
<OtherUnitFiles Value="..\src;..\impl;..\OpenGL3;..\SDL2-for-Pascal\units;..\examples"/>
215+
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
216+
</SearchPaths>
217+
<CodeGeneration>
218+
<TargetCPU Value="x86_64"/>
219+
<TargetOS Value="linux"/>
220+
<Optimizations>
221+
<OptimizationLevel Value="0"/>
222+
</Optimizations>
223+
</CodeGeneration>
224+
<Linking>
225+
<Debugging>
226+
<RunWithoutDebug Value="True"/>
227+
<DebugInfoType Value="dsDwarf3"/>
228+
<UseExternalDbgSyms Value="True"/>
229+
</Debugging>
230+
</Linking>
231+
</CompilerOptions>
232+
</Item7>
233+
<SharedMatrixOptions Count="2">
234+
<Item1 ID="731975208417" Modes="Debug_windows_64,Release_windows_64,Release_windows_32,Debug_windows_32,Debug_linux_64,Release_linux_64" Value="-CfAVX2 -CpCOREAVX2 -OpCOREAVX2 -OoFASTMATH"/>
235+
<Item2 ID="883228556756" Modes="Release_windows_64,Debug_windows_64,Release_windows_32,Release_linux_64,Debug_windows_32,Debug_linux_64" Value="-dSDL2"/>
209236
</SharedMatrixOptions>
210237
</BuildModes>
211238
<PublishOptions>

0 commit comments

Comments
 (0)