Camera aspect ratio
by J. Donavan Stanley · in Torque Game Engine · 03/21/2003 (6:39 am) · 17 replies
I've been toying with using a "wide screen" FOV with GORPE. Occording to my handy dandy OpenGL guide I'd do this by calling gluPerspective and glViewport. However I can't seem to locate anywhere within the engine where either of those two are called.
So has anyone mucked with non-standard FOVs for the main camera in Torque that can point me to the right area of the code to start digging? I've wandered around looking at various sections of code that reference the camera but I quickly get glassy eyed...
So has anyone mucked with non-standard FOVs for the main camera in Torque that can point me to the right area of the code to start digging? I've wandered around looking at various sections of code that reference the camera but I quickly get glassy eyed...
#3
03/25/2003 (8:41 am)
Melv, that changes the FOV, but it doesn't change the aspect ratio.
#4
Not all of the viewcone is shown, however. Due to the monitor not being cirular, a 4:3 rectangle from that cone is displayed. What you need to do to get a widescreen effect is change the dimensions of the rectangle.
The best way, like I said above is to use the stencil buffer to block out 2 strips - top and bottom, so that you get a widescreen effect.
However, if you're looking to stretch the image, you'd have to play with the frustrum a bit. There may not be a call to glFrustrum, so you'll have to find the appropriate place to put it.
03/25/2003 (8:51 am)
Mark, the FOV is not what you want to change. The FOV is an angle. If you draw a line from the eye out into space, then draw another line at a FOV/2 degree angle to that line, and then spin that around the first line really really fast, you'd get the viewcone.Not all of the viewcone is shown, however. Due to the monitor not being cirular, a 4:3 rectangle from that cone is displayed. What you need to do to get a widescreen effect is change the dimensions of the rectangle.
The best way, like I said above is to use the stencil buffer to block out 2 strips - top and bottom, so that you get a widescreen effect.
However, if you're looking to stretch the image, you'd have to play with the frustrum a bit. There may not be a call to glFrustrum, so you'll have to find the appropriate place to put it.
#5
How did my name get in there? ;)
For widescreen simulation, I would probably favor drawing a couple of black bars in ortho mode over using the stencil buffer, since the stencil test is going to burn performance for no good reason.
Draw the bars early in the frame and let the depth test sort it out for you.
Of course, this is going to look particularly stupid for those users who actually do have a widescreen monitor - you'll want to toss in a check for those.
03/25/2003 (9:03 am)
Quote:
Mark, the FOV is not what you want to change.
How did my name get in there? ;)
For widescreen simulation, I would probably favor drawing a couple of black bars in ortho mode over using the stencil buffer, since the stencil test is going to burn performance for no good reason.
Draw the bars early in the frame and let the depth test sort it out for you.
Of course, this is going to look particularly stupid for those users who actually do have a widescreen monitor - you'll want to toss in a check for those.
#6
The idea being to present the user with a cinema type look and use the blank areas left over by the "letterbox" effect for UI elements.
03/25/2003 (9:19 am)
What I'm shooting for is something like a 2.35:1 ratio. As for black bars, wouldn't a viewport elminate the need for drawing them?The idea being to present the user with a cinema type look and use the blank areas left over by the "letterbox" effect for UI elements.
#7
You're right, of course, you'd want to throw in calls to change the viewport when the 3D stuff is rendering.
IIRC (and I might be wrong) Torque is using glFrustrum instead of gluPerspective, so look for that in the source. I would, but I don't have a copy with me at work. :)
If you can't find an existing hook, you could do worse than SceneGraph::renderScene as a place to set this up.
EDIT: I spoke too soon, I actually had the proper place in my notes. You're looking for the sgComputeNewFrustum function in sgUtil.cc - Torque is manually setting up the projection matrix.
03/25/2003 (9:37 am)
Duh. What _was_ I thinking about?You're right, of course, you'd want to throw in calls to change the viewport when the 3D stuff is rendering.
IIRC (and I might be wrong) Torque is using glFrustrum instead of gluPerspective, so look for that in the source. I would, but I don't have a copy with me at work. :)
If you can't find an existing hook, you could do worse than SceneGraph::renderScene as a place to set this up.
EDIT: I spoke too soon, I actually had the proper place in my notes. You're looking for the sgComputeNewFrustum function in sgUtil.cc - Torque is manually setting up the projection matrix.
#8
03/25/2003 (9:57 am)
Thanks for the tip. Now to make sense of it all.
#9
Torque calls dglSetFrustum from within GuiTSCtrl::onRender. If you want to have a different aspect ratio that the actual ratio of the extents of the control, you'd have to modify the viewport/frustrum setup code in GuiTSCtrl::onRender.
03/25/2003 (11:04 am)
Well, in torque, the easiest thing to do would be to first, set up your GuiTSControl (or GameTSControl) so that it describes the visible portion of your letterbox - this will do all the viewport manipulation. have an aspect ration of 2.35 : 1 just make a GuiTSControl that is 2.35 times as wide as it is tall.Torque calls dglSetFrustum from within GuiTSCtrl::onRender. If you want to have a different aspect ratio that the actual ratio of the extents of the control, you'd have to modify the viewport/frustrum setup code in GuiTSCtrl::onRender.
#10
Widescreen is not simply changing the aspect ratio. Movie cameras take a wider FOV and to display that correctly you need a different FOV display device e.g. widescreen TV (16:9) or use an existing TV (4:3) and scale-down the image resulting in upper/lower black bands. You can take widescreen to mean what you desire but if it's dark upper/lower bands you want then it is technically fitting a wider fov into a fixed view which also entails changing the aspect.
For games, you can create the effect without changing the FOV and sure it looks okay but I was probably being too accurate and not the opposite.
Standard (4:3) is approx a fov of 30deg horiz / 22.7deg vert.
Widescreen (16:9) is approx a fov of 37.5deg horiz / 21.7deg vert.
Ultimately, the fov is the frustum and so Marks suggestion works.
- Melv.
03/25/2003 (12:00 pm)
GuysWidescreen is not simply changing the aspect ratio. Movie cameras take a wider FOV and to display that correctly you need a different FOV display device e.g. widescreen TV (16:9) or use an existing TV (4:3) and scale-down the image resulting in upper/lower black bands. You can take widescreen to mean what you desire but if it's dark upper/lower bands you want then it is technically fitting a wider fov into a fixed view which also entails changing the aspect.
For games, you can create the effect without changing the FOV and sure it looks okay but I was probably being too accurate and not the opposite.
Standard (4:3) is approx a fov of 30deg horiz / 22.7deg vert.
Widescreen (16:9) is approx a fov of 37.5deg horiz / 21.7deg vert.
Ultimately, the fov is the frustum and so Marks suggestion works.
- Melv.
#11
03/25/2003 (12:39 pm)
Hmm oddly enough something is forcing PlayGui back to being square.. I'm looking into what that might be now.
#12
Hopefully, this should help.
- Melv.
03/25/2003 (12:49 pm)
PlayGui is the main parent on the canvas as default (GameTSCtrl). Try placing a background control 'behind' it e.g. place the GameTSCtrl as a child to a background control (GuiChunkedBitmapCtrl) or (GuiControl) and simply resize it as a child.Hopefully, this should help.
- Melv.
#13
03/25/2003 (12:58 pm)
Thanks Melv, I was about to try something like that after finally tracking the problem down to the GuiCanvas::renderFrame. Apparently all bottom level controls must be the same size as the canvas for mouse events to pass through.
#14
So now I'm looking at 1) Adding a mechanism to tell the canvas "send all input events to this control" 2) Adding support for controls to forward all of their messages onward.
Time for me to head of to take my dog to the vet. I'll take this up again tomorrow.
03/25/2003 (1:37 pm)
The more I dig into the this the more complicated it seems to get. I appears as though game input gets transmitted to the GameTSControl by the canvas those input events are going to the chunkedbitmap now.So now I'm looking at 1) Adding a mechanism to tell the canvas "send all input events to this control" 2) Adding support for controls to forward all of their messages onward.
Time for me to head of to take my dog to the vet. I'll take this up again tomorrow.
#15
It doesn't look "right" to me though. It appears as though the FOV is the same in both the horiz. and the vert. and as Melv pointed out that's not the desired behavior. Of course right now I'm basing that on eyeball estimation only so...
Oh and Melv, the widescreen effect I'm shooting for is Anamorphic (2.35:1). "True" (16:9) widscreen looks distorted on non-widescreen display devices in my experiance.
At any rate, now that I've seen it I'm not sure if I want to continue down this path. I'll probably just use a viewport and maintain the normal FOV and aspect ratio. Even on a 22 inch monitor the letterbox you get from 2.35:1 makes the gameplay area of the screen too small.
03/26/2003 (6:30 am)
The input problem was as simple as making sure the background control called onWake for the GameTSControl when it woke up. It doesn't look "right" to me though. It appears as though the FOV is the same in both the horiz. and the vert. and as Melv pointed out that's not the desired behavior. Of course right now I'm basing that on eyeball estimation only so...
Oh and Melv, the widescreen effect I'm shooting for is Anamorphic (2.35:1). "True" (16:9) widscreen looks distorted on non-widescreen display devices in my experiance.
At any rate, now that I've seen it I'm not sure if I want to continue down this path. I'll probably just use a viewport and maintain the normal FOV and aspect ratio. Even on a 22 inch monitor the letterbox you get from 2.35:1 makes the gameplay area of the screen too small.
#17
with:
This only works for windowed mode.
09/26/2006 (11:06 am)
I got a fine 16:9 widescreen by editing mygame/main.cs onStart(), and replacing:initServer(); initClient();
with:
initServer(); $pref::Video::resolution="800 450 32"; initClient(); setFOV(90);
This only works for windowed mode.
Torque Owner Chris \"Hobbiticus\" Weiland
glClearColor
glViewport
glFrustrum
gluOrtho
One of those is bound to come up with a starting place.
You could also use the stencil buffer to make two black strips for a letterbox style widescreen, which might be more of what you're looking for. I don't know much about it, but I think you just give it screen coords of where your scene is going to be using a masking matrix/image and it'll only draw on the screen coords you tell it to.
That's how say... Flight Simulator does the cockpit - the scene is only rendered in the window, and everything else is just overlayed over the strip of scene.