PDA

View Full Version : How to use SDL_ListModes in Pascal??



paul_nicholls
16-09-2011, 10:19 AM
Hey all,
I am trying to get all the available resolutions (w x h) using SDL_ListModes like it shows here:
http://www.libsdl.org/cgi/docwiki.cgi/SDL_ListModes

but I am not sure how to translate that to Pascal...it seems to be a double pointer or something?

My code is crashing :(

Here is the code I have whipped up to try and enumerate the display settings:


type
TGraphicsMode = record
Width : Word;
Height : Word;
AspectRatio : Single;
IsWidescreen : Boolean;
end;

TGraphicsModeArray = array of TGraphicsMode;

procedure EnumerateDisplaySettings(var aGraphicsModes: TGraphicsModeArray; var aDesktopIsWideScreen: Boolean);
const
cNormalAspectRatio = 1024/768;
var
Index : Integer;
ScreenWidth : Integer;
ScreenHeight : Integer;
Modes : PPSDL_Rect;
begin
Modes := SDL_ListModes(nil,SDL_HWSURFACE);

if not Assigned(Modes^) then
Modes := SDL_ListModes(nil,SDL_SWSURFACE);

SetLength(aGraphicsModes,0);

Index := 0;
while Assigned(Modes^) do
begin
SetLength(aGraphicsModes,Index + 1);
aGraphicsModes[Index].Width := Modes^.w;
aGraphicsModes[Index].Height := Modes^.h;
aGraphicsModes[Index].AspectRatio := Modes^.w / Modes^.h;
aGraphicsModes[Index].IsWidescreen := Abs(aGraphicsModes[Index].AspectRatio - cNormalAspectRatio) > 0.1;
Inc(Index);
Inc(Modes^);
end;
end;


cheers,
Paul

paul_nicholls
16-09-2011, 10:24 AM
Nevermind, after some more searching, I found this page:
http://jedi-sdl.pascalgamedevelopment.com/html_docs/sdllistmodes.html

It shows me how to use it in Pascal :)

cheers,
Paul

paul_nicholls
16-09-2011, 11:05 AM
ok, here is my code now - it isn't crashing anymore, but it always seems to reach this line and then exit as that condition is true:


// all modes are available
if ppmode = PPSDL_Rect( -1 ) then Exit;

I was hoping to get an actual list of available video resolutions, but this doesn't seem to happen :(


type
TGraphicsMode = record
Width : Word;
Height : Word;
AspectRatio : Single;
IsWidescreen : Boolean;
end;

TGraphicsModeArray = array of TGraphicsMode;

procedure EnumerateDisplaySettings(var aGraphicsModes: TGraphicsModeArray; var aDesktopIsWideScreen: Boolean);
const
cNormalAspectRatio = 1024/768;
var
Index : Integer;
ScreenWidth : Integer;
ScreenHeight : Integer;
VideoInfo : PSDL_VideoInfo;
ppmode : PPSDL_Rect;
begin
SetLength(aGraphicsModes,0);

VideoInfo := SDL_GetVideoInfo;
ppmode := SDL_ListModes(VideoInfo^.vfmt,SDL_OPENGL or SDL_HWSURFACE);

// no hardware modes found
if ppmode = PPSDL_Rect( 0 ) then
ppmode := SDL_ListModes(VideoInfo^.vfmt,SDL_OPENGL or SDL_SWSURFACE);

// no software modes found
if ppmode = PPSDL_Rect( 0 ) then Exit;

// all modes are available
if ppmode = PPSDL_Rect( -1 ) then Exit;

// return available modes
Index := 0;
while Assigned(ppmode^) do
begin
SetLength(aGraphicsModes,Index + 1);
aGraphicsModes[Index].Width := ppmode^^.w;
aGraphicsModes[Index].Height := ppmode^.h;
aGraphicsModes[Index].AspectRatio := ppmode^.w / ppmode^.h;
aGraphicsModes[Index].IsWidescreen := Abs(aGraphicsModes[Index].AspectRatio - cNormalAspectRatio) > 0.1;
Inc(Index);
Inc(ppmode^);
end;
end;

Any ideas?

If I can't do it this way using SDL, I do have a windows only way already, but then I would need a Linux/Mac OS X way too...

cheers,
Paul