Widescreen support

Blitz3D Forums/Blitz3D Programming/Widescreen support

John Pickford(Posted 2007) [#1]
I'm just in the process of adding widescreen support to Naked War and it looks pretty good. I've got all the 2D stuff using the full screen width etc.

The problem I've noticed is that 3D viewports are scaled according to the width of the viewport so when you make it wider you don't get a wider view. The image is effectively zoomed and cropped at the top and bottom.

Is there a simple way I can make it the other way around so a wider viewport is actually a wider view?

I'm looking for a formula where I can bung in the zoom value & the aspect ratio and get a new zoom value. Is this possible? My head hurts!


simonh(Posted 2007) [#2]
Using ScaleEntity with the camera should do the trick.


John Pickford(Posted 2007) [#3]
How? Is that going to squash the view or something?

I need to effectively zoom out till the top and bottom of the image are the same as they were in non-widescreen whilst horizontally I can see more rathern than seeing the same.


Birdie(Posted 2007) [#4]
You could try FNzoom in camerazoom. It seems to work ok

Global scn_w = 1024
Global scn_h = 256

Graphics3D scn_w,scn_h,0,2

SetBuffer BackBuffer()

Local wid# = 128
Local hgt# = scn_h

Local cam = CreateCamera()
CameraViewport cam,FNxPos(wid),0,wid,hgt

PositionEntity CreateLight(), 0, 3, 0
PositionEntity CreateCube(),0,0,0
PositionEntity CreateSphere(), -3, 0, 0
PositionEntity CreateSphere(),  3, 0, 0

PositionEntity cam,0,0,-10
ClsColor 255,0,0
While Not KeyDown(1)
	Cls
	If KeyDown(205) wid=wid+1
	If KeyDown(203) wid=wid-1
	CameraViewport cam,FNxPos(wid),0,wid,hgt
	CameraZoom cam, FNzoom( wid, hgt )
	RenderWorld
	Text 0,0, "Arrows left/right to alter view width"
	Flip
Wend


Function FNxPos( wid )
	Return (scn_w-wid)/2
End Function

Function FNzoom#( view_wid#, view_hgt# )
	Return 2.0*( view_hgt/ view_wid )
End Function



puki(Posted 2007) [#5]
A reply from "Birdie"!

That's virtually an honour.


sswift(Posted 2007) [#6]
John:

For widescreen, what you want is to have the same vertical FOV, but a wider horizontal FOV.

If you take a look at this thread, you'll find a function which lets you set the horizontal FOV:

http://www.blitzbasic.com/Community/posts.php?topic=20921#215264

The default FOV is 90. Standard displays are 4:3. Widescreen displays are either 16:9 or 16:10.

4:3 = 1.33:1
16:9 = 1.77:1
16:10 = 1.6:1

(Yes, those numbers are correct. 16:10 is not as "wide" as 16:9)

If we then normalize the widths:

1.33/1.33 = 1
1.77/1.33 = 1.33
1.6/1.33 = 1.2

So, we need an FOV which is 1.33x as wide for a 16:9 screen, and one which is 1.2x as wide for a 16:10 screen. That means FOV's of approximately 120 and 108.

Please note, these numbers are not exact. 4/3 is actually 1.33333~ repeating. Do the math in the code to get the most accurate results.

Anyway, that's how you can get the results you want. Now you just have to figure out how to determine if the screen is widescreen or not. I guess you'll need to either find some DX functions you can access to do that, or you'll need to come up with a table of resolutions and what aspect ratios go along with them. And if I remember from the other thread, you also will need to correct the FOV for weird resolutions with non square pixels.

For that, you may find this of help:
http://en.wikipedia.org/wiki/Computer_display_standard


John Pickford(Posted 2007) [#7]
Got it working using Birdies example.

Cheers for the help everyone.

sswift: I'm being cheap and assuming pixels are square. I'll have to get some people to test it on different monitors and modes but I suspect it'll be okay. It's not critical that it's super accurate, I just want a widescreen view to show more rather than less.

One part of my game has animated viewports that change shape. It looks cool with the new code - showing a wider view as the viewport gets wider etc.


Chroma(Posted 2007) [#8]
Would be cool if someone wrote a function to auto-detect and set the horizontal FOV based on the desktop resolution.


Buggy(Posted 2007) [#9]
Yeah, I've only seen that with gadgets, which Blitz3D doesn't have (why not?!).


John Pickford(Posted 2007) [#10]
The function above will do that if you give it graphicswidth(), graphicsheight() as parameters.