[FIXED] App.ScreenMode Use DesktopResolution only works on Windows

Found a bug? Post information about it here so we can fix it!

Moderator: Moderators

Post Reply
User avatar
Ats
Posts: 603
Joined: Fri Sep 28, 2012 10:05 am
Contact:

[FIXED] App.ScreenMode Use DesktopResolution only works on Windows

Post by Ats »

Here's the little ZGE project to test it:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="test_viewport" FullScreen="255" ScreenMode="0" MouseVisible="255" FileVersion="2" AndroidPackageName="com.txori.test_viewport" AndroidPortrait="1">
  <OnLoaded>
    <ZExternalLibrary ModuleName="opengl32">
      <BeforeInitExp>
<![CDATA[//

if(ANDROID)
{
  this.ModuleName = "libGLESv1_CM.so";
}
else if(LINUX)
{
  this.ModuleName = "libGL.so";
}
else
{
  this.ModuleName = "opengl32";
}]]>
      </BeforeInitExp>
      <Source>
<![CDATA[//
const int GL_VIEWPORT = 0x0BA2;
void glGetIntegerv(int pname, xptr params){}]]>
      </Source>
    </ZExternalLibrary>
    <ZExpression>
      <Expression>
<![CDATA[//
glGetIntegerv(0x0BA2, Viewport);
trace(intToStr(Viewport[0]));
trace(intToStr(Viewport[1]));
trace(intToStr(Viewport[2]));
trace(intToStr(Viewport[3]));]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
  <OnRender>
    <UseMaterial Material="DigitsMaterial"/>
    <RenderText Scale="0.5">
      <TextExpression>
<![CDATA[//
intToStr(Viewport[2])+" "+intToStr(Viewport[3]);]]>
      </TextExpression>
    </RenderText>
  </OnRender>
  <Content>
    <Array Name="Viewport" Type="1" SizeDim1="4"/>
    <Bitmap Name="DigitsBitmap" Width="128" Height="16">
      <Producers>
        <BitmapFromFile Comment="Imported from Digits.bmp" Transparency="1" DataWidth="128" DataHeight="16">
          <BitmapFile>
<![CDATA[789CED583BAE22410CECE372088EC009B800393931292921211921195B9AD2962CFFBA9176A5173C0768F0B8FD29DBDDEE19E3977E045D2E97D7EBF5F97CF08BE75E18628FC723322B92CCF97CC642F19FCFE7F57A9DFAC6259613F58093AE3D1E8F92AC42A3C06EB7AB1CC0ABDBED467CA8077F9DFCFBFDD6DBFBFD7E381CA67189A00D0BB10AEED1193C37F229FE00414A1CD985C49C7C088303CFF7FB7D632EE24F3DD24FD3F8750B6148B02BB42806ACC00708A975BE85931068DC56507860A62A85A97E0B38F537194CF11F5B0A7A30638D9D4EA769BA23FE510FEA1F3236D78CCBA11DC5AC89B405985C1714FE562058432BDDCDE2B7FAA9BC495F639A2900AA53BB2276AEFEC6F66139B9564ABD82A48B2B420A73568CD4B440156CAC0A4711D894523D699F4E5D22B160D6534078ADF295A3641AC86BA3A998E52335A97B293FCDA32596F1B405B89545E54DB03DFEE39B14C4FD070EC3BAADDB69A5C92B97C7141F976E115B20B6183D74ADC12DDA06C8339AB8F1B0180B4055327DC82B6A99028C1FF1953B37A32A4064992BF8439B4389E97078C6C3CE52D50288E2BD11DDE6B3051FA54EE4750A4315A39B7AFE9FF01F7F3B37EEC0DA4CF0366D4FA2A491323AC321C4E5D1553B4DE015966B32E9C7ADAA05C656DE9A3FE370924E2C2C8915FCFFF9FE43EAE7BAB1B536731401B1BB503A7FB208057235D28CED1CB4DB4233E78FA20558DEAC7FF442F4F9DBBDCE128BC7317B8417F11F5B1ED38E16018D4A9B76A1883FABBA37CD6AFFEA1E348A16A003023CFADC84D09FD1E39BF9135E71D35BC73F4DEEA20CA180C5883F38D3B818457FB348298216E38DB3562C33A6697A0B5BBF7F31539C0722FE88D76DE644C0CEB1E0B8A188321598DC8552FC572622B6C0F4738A230668FD8C5DEC38DCEADD3710D6D54A031270FBFDA1CA1AAF7529FEF441F77442E74620661068734E904C33A9EAD4B34C015B7DE88816F5F5C01649D4407225218EBB0F5A439AE5ACCCCAFD572608C5F4FB5B55FF636B251D764C68CCBEF613C9A433AAD519F1D768E1A8D2002BCAA3ADDB5449AA0D4E6A9EC4435A30829DF8F471FDD24FA03FFC4DB206]]>
          </BitmapFile>
        </BitmapFromFile>
      </Producers>
    </Bitmap>
    <Font Name="DigitsFont" Bitmap="DigitsBitmap" FirstChar="48" CharPixelWidth="12" CharPixelHeight="16"/>
    <Material Name="DigitsMaterial" Light="0" Blend="2" Font="DigitsFont"/>
  </Content>
</ZApplication>
If I set App.ScreenMode to "Use Desktop Resolution", it works on Windows.

But the result on Android is 0 0. Landscape and Portrait.

And on Linux, 800 600.
Other App.ScreenMode are working on Linux.
Last edited by Ats on Wed Apr 28, 2021 10:50 am, edited 1 time in total.
User avatar
Ats
Posts: 603
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: App.ScreenMode Use DesktopResolution only works on Windows

Post by Ats »

As Kjell told me, it's not a bug, but a missing feature :wink:

ZPlatform_SDL.inc

Code: Select all

  if Width=-1 then
  begin
    //Todo: support "current desktop resolution" on sdl
    Width := 800;
    Height := 600;
  end;
After a few readings regarding the detection of screen size on several different devices using SDL2, it appears the best one is:

SDL_DisplayMode display;
SDL_GetCurrentDisplayMode(0, &display);
Width = display.w;
Height = display.h;

https://wiki.libsdl.org/SDL_GetCurrentDisplayMode

But I think https://wiki.libsdl.org/SDL_DisplayMode needs to be added to sdlvideo.inc
I've tried some things without success, I'm curious to see how it is done :wink:
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: App.ScreenMode Use DesktopResolution only works on Windows

Post by VilleK »

Does this help? It compiles here but does not seem to return actual desktop resolution on Windows.

Code: Select all

var
  display : TSDL_DisplayMode;

Code: Select all

  if Width=-1 then
  begin
    SDL_GetDesktopDisplayMode(0,@display);
    Width := display.w;
    Height := display.h;
  end;
User avatar
Ats
Posts: 603
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: App.ScreenMode Use DesktopResolution only works on Windows

Post by Ats »

Oh, I didn't see it was already in sdlvideo.inc because I was searching for the whole exact word. So T and P nomenclature stands for get and set?

ZDesigner compiles without problems on Windows, but on Linux I get:
ZPlatform_SDL.inc(67,41) Error: Incompatible type for arg no. 2: Got "TSDL_DisplayMode", expected "PSDL_DisplayMode"
ZPlatform_SDL.inc(345,47) Error: Can't evaluate constant expression

I tried renaming the var to PSDL_DisplayMode. It compiles on Windows and Player_linux.bin, but then on Linux, ZGE apps gives:
An unhandled exception occurred at $0000000000416B0A:
EAccessViolation: Access violation
$0000000000416B0A

By the way, I put var display on line 25:

Code: Select all

var
  //Current mouse pos, written to in eventhandling
  SdlMousePos : TZPointi;
  Keys : array[0..511] of boolean;
  KeyMap : array[AnsiChar] of integer;
  gZApp: TZApplication;
  display : TSDL_DisplayMode;
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: App.ScreenMode Use DesktopResolution only works on Windows

Post by VilleK »

You can declare display as a local variable in that function. It should be of type "TSDL_DisplayMode" then it is important to prefix it with "@" in the call to SDL_GetDesktopDisplayMode (this takes the address of the variable, creating a pointer).

SDL_GetDesktopDisplayMode(0,@display);

Please double check that you've done this.
User avatar
Ats
Posts: 603
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: App.ScreenMode Use DesktopResolution only works on Windows

Post by Ats »

Sorry, I had a remnant of test I added in ZApplication.pas yesterday.
So now it's working perfectly on Linux, but not on Android.

I already tried to remove that entire block from ZApplication.pas:

Code: Select all

{$ifndef android}
 if((CustomScreenWidth > 0) and (CustomScreenHeight > 0)) then
 begin
   ScreenWidth := Self.CustomScreenWidth;
   ScreenHeight := Self.CustomScreenHeight;
 end
 else
 begin
   I := Ord(Self.ScreenMode);
   ScreenWidth := ScreenModes[ I ].W;
   ScreenHeight := ScreenModes[ I ].H;
 end;
{$endif}
I also tried replacing SDL_GetDesktopDisplayMode per SDL_GetCurrentDisplayMode
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: App.ScreenMode Use DesktopResolution only works on Windows

Post by VilleK »

Perhaps on Android it is too early to get Viewport size in OnLoaded? Try in OnUpdate or OnRender instead.

What are your end goals here, do you need a technique to find the current resolution?
User avatar
Ats
Posts: 603
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: App.ScreenMode Use DesktopResolution only works on Windows

Post by Ats »

You're right. Get Viewport size works on OnUpdate on Android :D
I need that to resize the background correctly, to optimize the deletion of objects out of the camera and to place virtual gamepad correctly on the screen. I'll initialize the screen size on the OnStart of the first state loaded. So it's working with that:

Code: Select all

  if Width=-1 then
  begin
    var display : TSDL_DisplayMode;
    SDL_GetDesktopDisplayMode(0,@display);
    Width := display.w;
    Height := display.h;
  end;
Post Reply