Ratio

ZGE Source Code discussion. Ask questions, present your changes, propose patches etc.

Moderator: Moderators

User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Ratio

Post by Kjell »

:)

Next up is Camera / Viewport Aspect Ratio.

K
Attachments
torus.jpg
torus.jpg (46.94 KiB) Viewed 30497 times
User avatar
VilleK
Site Admin
Posts: 2320
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

So I guess you calculate the render area in application and then pass parameters down to the platform-function. Can you post some code-snippets showing how you've tried to solve it? The screen shot looks nice!

Yes it would be cool if the zge-runtime only included the components needed for the current game in ZDesigner. That would make it easier to have more components and not bother about every components kb-size. I have an idea how that can be achieved but I haven't had the time to see if it is realistic yet. That topic needs a separate investigation-thread in the future.
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Ville,

The calculations where actually done in Renderer.pas, but I probably need to move them to ZApplication.pas in order to get everything to frmEditor.pas as well ( this is where I'm having most difficulties ). Anyway, here's the Init snippet.

Code: Select all

procedure InitRenderer(Width,Height : integer; Ratio : single);
var
  ViewportX : integer;
  ViewportY : integer;
  ViewportWidth : integer;
  ViewportHeight : integer;
begin
  if(Width/Height > Ratio)then
  begin
    ViewportWidth := Trunc(Height*Ratio);
    ViewportHeight := Height;
    ViewportX := Trunc((Width-Height*Ratio)/2);
    ViewportY := 0;
  end
  else
  begin
    ViewportWidth := Width;
    ViewportHeight := Trunc(Width/Ratio);
    ViewportX := 0;
    ViewportY := Trunc((Height-Width/Ratio)/2);
  end;

  glViewport(ViewportX, ViewportY, ViewportWidth, ViewportHeight);
end;
As far as modular development concerned, I only get as far as thinking you'd need a component register, and a "mother" component object you can extend individual component classes from ( moved from their catagory.pas to individual files ). Then you'd either need to parse through a project to see what methods are used, or let the user consciously enable / disable individual components before making them available for use in the Editor.

Anyway, future indeed :P

K
User avatar
VilleK
Site Admin
Posts: 2320
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

That looks pretty manageable! I've only used glViewport with the full screen area before.

1. What is the name and type of the property that the user will set?

2. What is the default value of this property, and what will the user do if he wants the current behavior (use full resolution as render area).
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Ville,

From ZApplication.pas

Code: Select all

  TZApplication = class(TZComponent)
  public
    Ratio,FOV,ClipNear,ClipFar : single;

  List.AddProperty({$IFNDEF MINIMAL}'Ratio',{$ENDIF}integer(@Ratio) - integer(Self), zptFloat);
    List.GetLast.DefaultValue.FloatValue := 4/3;
But perhaps ViewportRatio or CameraRatio would be better then just Ratio. And I could insert a if Ratio == 0 then just use the full window / screen resolution.

K
User avatar
VilleK
Site Admin
Posts: 2320
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

Kjell wrote:But perhaps ViewportRatio or CameraRatio would be better then just Ratio. And I could insert a if Ratio == 0 then just use the full window / screen resolution.K
"ViewportRatio" sounds good. Or is there another term for this? I want to be sure we use the correct terminology and minimize the risk of confusion with other "ratios".
And a zero value (which should be default for backwards compatibility) for the old behavior is good too!
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

8)

Done, attached are a couple of examples.

K
Attachments
Ratio.zip
(111.76 KiB) Downloaded 1055 times
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

hay that looks sweet! this will allow for some interesting arty type creations.., panorama looks great for the cinematic panovision effect that will work quite well on all these new fangle widescreen displays,. thanks for this!
iterationGAMES.com
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi jph,

The main reason for implementing this is that no matter what ScreenRatio you'll run a application in, that the active rendering region ( Viewport ) can always be the same ratio. Right now ( 1.9.0 ) the extremes lie at 4/3 and 1.6, which means that the person running in a ScreenRatio of 1.6 can see a significantly wider portion of your game compared to 4/3 .. and with that maybe even stuff that you never meant to have visible to begin with.

K
User avatar
VilleK
Site Admin
Posts: 2320
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

Suggestion:

Two new properties on application:

ViewportRatio dropdown (Use full window, Custom, 4:3, 16:9)

"Use full window" is the default and gives the current zge 1.9.0 behavior of rendering to the full window.

CustomViewportRatio numeric value, used when ViewportRatio is "Custom".

Will that be generic enough and still easy to use? I can make this change if you want to concentrate on your joystick feature Kjell :)
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Great suggestions Ville,

This will probably make it a little easier to understand what these properties do. And thanks for offering to make these changes. Now I can continue on implementing Joystick support indeed :wink:

K
User avatar
VilleK
Site Admin
Posts: 2320
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

Progress update: I've made the changes and it seems to work alright, but I need to clean up the code some more before releasing.
User avatar
VilleK
Site Admin
Posts: 2320
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

Updated this again now so that only the active viewport region is cleared with the clearcolor, using glScissor-function. This gives the letterbox effect with black area above and below the view region when using HD ratio on a non-HD display.
User avatar
Kjell
Posts: 1910
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hej Ville,

Ah, I actually liked the fact that you could use ClearColor to define the color of the "empty" space around your Viewport ..

K
User avatar
VilleK
Site Admin
Posts: 2320
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

You are right it could be useful to select the border color as well. I just found it hard to see that the viewport actually changed when the border was the same color. Perhaps a separate BorderColor property then, we'll see.
Post Reply