Results 1 to 3 of 3

Thread: How to use SDL_ListModes in Pascal??

  1. #1

    How to use SDL_ListModes in Pascal??

    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:

    Code:
    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

  2. #2
    Nevermind, after some more searching, I found this page:
    http://jedi-sdl.pascalgamedevelopmen...listmodes.html

    It shows me how to use it in Pascal

    cheers,
    Paul

  3. #3
    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:

    Code:
      // 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

    Code:
    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Comodo SSL