caiiiycuk / js-dos

The best API for running dos programs in browser

Home Page:https://js-dos.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add option to change aspect ratio

landonpoch opened this issue · comments

I've been able to configure dosbox locally to run in the 4:3 aspect ratio by turning on output=opengl and screenresolution={desired res}. However, when creating a bundle with the same conf the screen will become garbled and the aspect ratio seems like it tries to work but doesn't quite get it right (screenshot below). I've also tried output=overlay. This one actually gets the aspect ratio correct but again the screen is still garbled. Are there any plans to support the opengl output type so scaling can work correctly? Output type of overlay would also be great but I know that it doesn't have the same hardware acceleration so it might not run great like that.

Mmm, you should not change the type of output from surface. The frame is rgb data that sends from worker to client and then rendered with WebGL. So, webgl is already there. Also I don't understand the problem with aspect ratio it is already fine, you can check that everything is correct:

https://dos.zone/doom-dec-1993/

If you want to add shaders or something special then you need to work with emulators/ui package like described there: https://js-dos.com/v7/build/docs/threejs or change the emulators-ui, code is there

https://github.com/js-dos/emulators-ui/blob/main/src/graphics/webgl.ts

Sorry, I've been quite busy and wasn't able to respond quick enough. I can open another issue if you prefer. The real issue is the aspect ratio for me. I don't really care if the output type is opengl, ddraw, surface, overlay or whatever. What I'd like to be able to do is play doom on a widescreen monitor without the image being stretched. I can achieve this is dosbox. I cannot achieve it in jsdos, even if I use the same configuration (or different variants). Also, the demo link you provided above is stretched if you try it on a widescreen monitor. Here are some screenshots to show you what I mean by aspect ratio being incorrect.

DOSBOX (Aspect ratio is correct, looks like 5:4 8:5):

JSDOS (Aspect ratio is strected, looks like 16:9):

It's fairly easy to see the bottom one is stretched. I have tried all kinds of configuration in my .jsdos/dosbox.conf file to resolve this and nothing seems to be able to correct the stretched image. For individuals who do not have the option to have their gpu scale the screen for them, the game will be stretched if they are on a widescreen monitor.

Sorry, I think you are wrong. The game original resolution 320x200 it's a 16:10 aspect, the top image is stretched and the bottom is correct. js-dos didn't change the game aspect at all, what you see is original game aspect, because of this you can see black space on left and right side. The js-dos can only zoom image to fit the div, but aspect is never changed.

Found this:

Vanilla Doom ran only in a tweaked VGA "Mode 13h" 320x200 video mode. On properly configured CRT monitors, which were the only widely available and inexpensive consumer display device for computers at the time, this video mode took up the entire screen, which had a 4:3 physical aspect ratio. This meant that the 320x200 display, with an 8:5 (commonly called "16:10") logical ratio, was stretched vertically — each pixel was 20% taller than it was wide.

So probably you want to do original behavior, when original game aspect 16:10 was scaled to crt monitor 4:3?

Anyway I think it's a good idea to add option to override aspect ratio, also it's easy to do.

Sorry, I updated my post above to change 5:4 to 8:5. 8:5 is the same as the commonly known 16:10 obviously just reduced down. That said, it is not running in a 8:5 / 16:10 aspect ratio for me as it is stretched. If I measure the bottom image with a tape measure the ratio is not 8:5 but is instead 16:9. Trying to correct that and setting the aspect=true in the config file results in javascript errors when the game is running (and the garbled screen referenced initially when the post was opened). I've attached a screenshot of the js error below.

I agree this probably has to do with pixel size itself on widescreen monitors. Aspect ratio correcting for widescreen monitors (different pixel sizes) would be an awesome feature to support if you are open to it. Most people are probably running widescreen monitors these days and it would feel much more true to the original game to approximate the aspect ratio on widescreens.

Also, compliments on the nice work you've done here! It's really cool to be able to run these old programs in a browser!

I took your screenshot, cut off the black bars and downscale it to 320, the height is 200. so it's 320x200 as expected (16:10), please check it.
изображение

And the frist one (from dosbox) is a 320x240 (4:3):
изображение

Yeah, that sounds fair to me and it looks right. So I guess this is really just about being able to run it on a widescreen where pixel height might be different than it used to be on older monitors and still have the perceived aspect ratio to the user run at 8:5 like the original game would have looked on an old CRT monitor. (Physical vs. Logical aspect ratio as referenced above)
If that means having it run in 4:3 so that it appears like 8:5 then I guess that does the trick. Basically something similar to what dosbox already supports.

I'm not quite sure which is which from the post above...
Logical aspect ratio = the exact number of pixels WxH reduced down to least common denominator?
Physical aspect ratio = take a tape measure of WxH then reduce it down in parts to the least common denominator?

At any rate I think the game was designed to look like 16:10 like you were saying (assuming perfectly square pixels) so logical & physical would be the same aspect ratio. Ideally running it on a widescreen the goal would be to get the actual physical aspect ratio (assuming my definitions above aren't in the wrong order) to be 16:10 even if widescreen pixels aren't square and you have to somehow compensate.

I belive for js-dos there is no difference between logical/physical aspect ratio. It just get original rgb buffer from game and then render it as is (without changing the aspect). To achive what you want, I plan to add option in dos ctor, that overrides actual aspect ratio with user provided ratio. Then you can set any ratio what ever you want.

Probably this affects also other games, but I am not sure if it correct to set 4:3 as default ratio also for other games...

Ah, what you said makes a lot of sense. I think I misunderstood the quote initially about vanilla doom. But now it makes more sense to me. Basically it was being stretched to 4:3 even though it should have looked wider like the 16:10 that I'm seeing on my monitor. So my monitor is accurately rendering it but even still it doesn't look right because it isn't being stretched vertically like on the old CRT monitors. This makes sense.

So yes, I would assume that being able to stretch it so that it looks like 4:3 would really help a lot of these old games to look closer to what they did back in the day when they were running on CRTs since those pixels were 20% taller back then. 4:3 would adjust correctly if the old pixels were indeed 20% taller.

Would it make sense to use the aspect=true flag under the render section in dosbox.conf to allow the user to specify the 4:3 aspect ratio? This would behave similar to dosbox if that were the case. Here's the thread that gave me the config I used to stretch to 4:3 on dosbox if that helps: https://www.gog.com/forum/star_wars_dark_forces_series/dosbox_option_for_43_ratio

Nope, I afraid this is not supported

Fixed in v7.5.0, now you can set the wanted aspect ratio in ctor like this:

        Dos(document.getElementById("jsdos"), {
            aspect: 4/3,

Awesome! I will give this a try as soon as possible.

Worked like a charm! Thank you! However, I tried doing this using npx create-dosbox and it didn't seem to pull in the latest. I could have just had something cached though. At any rate, I was able to build js-dos and then copy it over into my create-dosbox project and everything worked as expected. Might be good to add something to the docs so that others know about this. The experience is much more authentic being able to run in 4:3 and I'm sure others will be happy to use this once they see it in the docs. You're the man!

Yeah, create-dosbox needs to be updated. I am working on brand new version, will write this in the docs. Thanks for this nice catch!