Skip to content

Conversation

Fancy2209
Copy link

@Fancy2209 Fancy2209 commented Feb 4, 2025

Description

Adds a video mode for widescreen

Existing Issue(s)

Fixes #73

@Fancy2209
Copy link
Author

The cursor displays properly, but games seem to still have issues
image

@Fancy2209 Fancy2209 marked this pull request as ready for review February 5, 2025 10:23
@Fancy2209
Copy link
Author

Fancy2209 commented Feb 5, 2025

I believe this is now ready for review
Only tested VVVVVV as most SDL2 Apps use OpenGX and that also needs changes (guOrtho width has to be different from viewport width)
Can defineteley use some cleanup but I want to make sure I am not doing something wrong

Stuff was setting the viewport and scissor to 854
Renderer now only adjusts projection if it's trying to set the viewport to 640*480 (this feels like not the intended way but I haven't found a better one)
@Fancy2209
Copy link
Author

Fancy2209 commented Feb 5, 2025

Correction: NOW it's ready for review
imagem
I feel like the logic to adjust the orthoWidth on the SDL Renderer is wrong but multiple render targets are a pain since only what's rendered to the screen needs adjusting

@Fancy2209 Fancy2209 changed the title WIP: Widescreen Video Mode [OGC] WIP: Wii Widescreen Feb 5, 2025
@Fancy2209 Fancy2209 requested a review from mardy February 5, 2025 23:43
@Fancy2209
Copy link
Author

Fancy2209 commented Feb 6, 2025

Btw there's something wrong with the code for centering the window, on widescreen VVVVVVV is setting the window x pos to 207, seems related to SDL_WINDOWPOS_CENTERED_DISPLAY (the x was smaller when I sent the picture above but it changed and I haven't found out why )

@mardy
Copy link
Collaborator

mardy commented Feb 7, 2025

SDL_WII_RESPECT_ASPECT_RATIO_CONFIG was just to allow apps to go into widescreen by default on wii but I can just make it what happens if SDL_OGC_ASPECT_RATIO isn't set

Makes sense!

@Fancy2209
Copy link
Author

Fancy2209 commented Feb 7, 2025

By the way just curious, why did you use the std lib directly for OGC_JoystickInit? I thougth that SDL was meant to use the SDL stdlib (as in getenv and strcmp instead of SDL_getenv and SDL_strcmp like the rest of the lib)

@Fancy2209 Fancy2209 changed the title [OGC] WIP: Wii Widescreen [OGC] Add support for Custom Aspect Ratios Feb 7, 2025
Because who doesn't want to make a Wii App that outputs at 21:9?
@Fancy2209
Copy link
Author

Fancy2209 commented Feb 7, 2025

:)
(Pictured is 21:9, wanted to make sure out of the bat something other than 16:9 worked)
imagem

Example usage

SDL_setenv("SDL_OGC_ASPECT_RATIO", "21:9", 1); // Normal setenv works, but no reason to include an extra header if you include SDL in your code directly already

mind you the format is w:h and w > h needs to be true or it will not work since the math doesn't work for when the height is what has to change
Also you can have 2 floats like 21.5:10.1 but I am praying no app does that since no screen does that so it'd just never look right

@Fancy2209 Fancy2209 requested a review from mardy February 7, 2025 22:19
@Fancy2209
Copy link
Author

By the way, something that is really bothering me is that when I set the window to widescreen the mouse starts having pixels jitter, like depending where it is some pixels get cut off in one of the sides

@mardy
Copy link
Collaborator

mardy commented Feb 8, 2025

By the way just curious, why did you use the std lib directly for OGC_JoystickInit? I thougth that SDL was meant to use the SDL stdlib (as in getenv and strcmp instead of SDL_getenv and SDL_strcmp like the rest of the lib)

SDL is trying to be as portable as possible, so it redefines these functions to allow platforms to reimplement them, if needed. But for us it just introduces a slow-down, since while the stdlib functions can be optimized away from the compiler, the SDL equivalent can not (that's my guess, at least, since it does not know them). I would suggest avoiding them, unless you are writing code in the SDL common modules and you plan to submit it upstream.

Comment on lines 203 to 208
if (aspect_w > 4.0f && aspect_h > 3.0f)
OGC_load_texture(curdata->texels, curdata->w, curdata->h, GX_TF_RGBA8,
SDL_ScaleModeLinear);
else
OGC_load_texture(curdata->texels, curdata->w, curdata->h, GX_TF_RGBA8,
SDL_ScaleModeNearest);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what this does, and I'm not sure that the if is correct (what if the ratio is 3:2? -- by the way, for this type of checks it appears that using a single float for the aspect ratio instead of two ints would be better).

Note that the scaling is done either by the TV or by the VI interface, so I don't think we should be changing how the texture is being filtered.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cursor looks very jittery on other aspect ratios, so I changed it to Linear since it wouldn't be as noticeable, but it's still noticeable and I have no idea why it's cutting pixels from the image depending on where it is


guMtxIdentity(mv);
guMtxScaleApply(mv, mv, screen_w / 640.0f, screen_h / 480.0f, 1.0f);
guMtxScaleApply(mv, mv, screen_w / (480.0f * aspect_w / aspect_h), screen_h / 480.0f, 1.0f);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot do this on the modelview matrix, because then you are actually changing the cursor width, and then if the cursor then gets rotated it will appear wrong. I think that all this code should stay unchanged, and we should only operate on how the OGX_set_viewport function gets called.

It sounds a bit silly, since it was me who introduces this scaling, but looking at it now, it appears wrong: we already have the viewport to do the scaling; can you try to just remove this line?

And in the call to OGC_set_viewport() below, we should probably pass the EFB dimensions, not the screen dimensions adjusted for the aspect ratio (at least if you follow my suggestion about retrieving the aspect ratio from OGC_set_viewport).

Copy link
Author

@Fancy2209 Fancy2209 Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would I retrieve the aspect ratio from the viewport function tough? I stopped doing a different width for the matrix because it's more correct, an app will look right if it's widescreen
If an app doesn't try to use widescreen, doing work arounds so maybe it'll look right felt wrong

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i made the resize be sceen height dependant

@@ -157,6 +167,20 @@ static void setup_video_mode(_THIS, GXRModeObj *vmode)
{
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;

// TODO: Should I make this only happen if the aspect ratio isn't 4:3?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To simplify things I suggest forgetting about the VI changes for now (have them in a separate PR later), because handing of the CONF_GetAspectRatio() is a bit orthogonal to setting the best video mode. It will make testing and reviewing easier, if we tackle one issue at a time.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +68 to 72
GX_SetViewport(x, y, (w > 640) ? 640 : w, h, 0, 1);
GX_SetScissor(x, y, (w > 640) ? 640 : w, h);

// matrix, t, b, l, r, n, f
guOrtho(proj, 0, h, 0, w, 0, 1);
Copy link
Collaborator

@mardy mardy Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that GX_SetViewport and GX_SetScissor can be set to the EFB size (that is, we can consider w and h to be in pixels), and if we want to play with the aspect ratio we can play with the width parameter passed to guOrtho.

In other words, I would set leave the calls to GX_SetViewport and GX_SetScissor exactly as they were, then call OGC_get_aspect_ratio_dimensions right from within this function and call

const float ratio4_3 = 4.0f / 3.0f;
guOrtho(proj, 0, h, 0, w * ratio / ratio4_3, 0, 1); 

Of course, this needs to be checked. :-) The thing is, if you pass the same values to both functions (GX_SetViewport and guOrtho) you get a 1:1 mapping, which is not what we want for widescreen cases (or for any case where the ratio is not 4/3).

Copy link
Author

@Fancy2209 Fancy2209 Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave up aspect correcting apps that aren't using 16:9
Fixing this here would cause issues, as I've showed before it makes VVVVVVV less wide than it should.
The whole guOrtho thing being a new var really felt like a hack, and I think leaving it as is is the best approach, especially since some apps resize the viewport twice every frame and it will distort the image more than it should if we do it

@Fancy2209
Copy link
Author

Fancy2209 commented Feb 9, 2025

I just tested Wii screen on my TV
692*460 is what worked, I have a component cable but I guess not good enough since I can't disable over scan (on LG TVs it's enabling Just Scan)
I guess I'll have to add an env var to optionally adjust for overscan :/

@Fancy2209
Copy link
Author

So since I can't just correct all viewports, what changes do I need to do appart from aspect ratio caching?

@mardy
Copy link
Collaborator

mardy commented Feb 17, 2025

So since I can't just correct all viewports, what changes do I need to do appart from aspect ratio caching?

I've been quiet on the last few days because I've got several conflicting thoughts, and I'm not even sure what the original problem is (or maybe, there's more than one). I've wanted to test this myself, but I'm busy with some other stuff now, so I've to wait a few more days to get my hands on this. Meanwhile, if you have time, you might be able to answer this question: how does the TV detects aspect ratio? If the TV is set to auto-detect the aspect ratio, is it possible from the Wii to set the mode in such a way that the TV detects it with the aspect ratio we want (4:3 and 16:9 only, obviously)?

As for the cursor being cut, well, that is because you are shrinking the image in order to compensate for the stretching operated by the TV set. I think that your change which sets the interpolation mode to linear should fix it, doesn't it?

@Fancy2209
Copy link
Author

Fancy2209 commented Feb 17, 2025

It's understandable to not have time
Let me answer your questions though
The issue was that if an app wanted to use widescreen, they couldn't, setting a window to 854 by 480 would just get cut off or get garbled. At one point I also tried to fix the issue that in 16:9 if an window wasn't a widescreen res it'd get streched, but I realized it wasn't worth it as it was a bit hacky and I wasn't happy with the results.
About the tv detection, it'll always be detected as 4:3, the Wii always outputs a 4:3 signal.

The cursor being set to linear made it be less noticeable but not 100% like it should, the homebrew channel cursor behaves much less weirdly

@Fancy2209
Copy link
Author

Any chance for a new review of this?

@DacoTaco
Copy link
Member

Any chance for a new review of this?

that should be depended @mardy i think. they are basically the sdl->ogc expert here i think :p

Comment on lines 299 to 307
vmode->viWidth = VI_MAX_WIDTH_NTSC; // VI_MAX_WIDTH is the same for all regions
// set Center point
if (VI_FORMAT_FROM_MODE(vmode->viTVMode) == VI_PAL) {
vmode->viXOrigin = (VI_MAX_WIDTH_PAL - vmode->viWidth) / 2;
vmode->viYOrigin = (VI_MAX_HEIGHT_PAL - vmode->viHeight) / 2;
} else {
vmode->viXOrigin = (VI_MAX_WIDTH_NTSC - vmode->viWidth) / 2;
vmode->viYOrigin = (VI_MAX_HEIGHT_NTSC - vmode->viHeight) / 2;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look correct: why are we setting the width to the max here? What if an application wants to have a 4:3 ratio and is therefore fine with viWidth and viHeight set to 640x480?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, actually, this is correct, but only if the Wii conf setting for the aspect ratio is set to 16:9. Do you agree, @Fancy2209 ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe? It's been so long I don't remeber why I did this change 😅

@mardy
Copy link
Collaborator

mardy commented Aug 27, 2025

Any chance for a new review of this?

Oh, actually now I would have some time to test this, so thanks for the ping :-) By the way do you have some tests apps for this, or did you only try with VVVVVV?

@Fancy2209
Copy link
Author

Fancy2209 commented Aug 27, 2025

Any chance for a new review of this?

Oh, actually now I would have some time to test this, so thanks for the ping :-) By the way do you have some tests apps for this, or did you only try with VVVVVV?

I used Neverball and had a Raylib Hello World sample working with it
Raylib and the sample build without changes using the SDL2 Backend as long as you disable raudio
Neverball worked but I had to add 854x480 as a option
mardy/neverball#1
though I think I based on the wrong branch as the one I modifed had mouse controls and not Accelerometer ones
VVVVVV I gave up on as correcting. It was getting Squished instead of beeing 4:3

@Fancy2209
Copy link
Author

Should I make a test app?

@mardy
Copy link
Collaborator

mardy commented Aug 28, 2025

Should I make a test app?

That would be helpful indeed!

@Fancy2209
Copy link
Author

Should I make a test app?

That would be helpful indeed!

How would I allow the aspect ratio to be changed if that has to happen before init though?

@mardy
Copy link
Collaborator

mardy commented Aug 29, 2025

Should I make a test app?

That would be helpful indeed!

How would I allow the aspect ratio to be changed if that has to happen before init though?

Just hardcode an aspect ratio, build the app, save it under a different name, change the aspect ratio in the code, build again :-) So we get two apps we can test.

@Fancy2209
Copy link
Author

Should I make a test app?

That would be helpful indeed!

How would I allow the aspect ratio to be changed if that has to happen before init though?

Just hardcode an aspect ratio, build the app, save it under a different name, change the aspect ratio in the code, build again :-) So we get two apps we can test.

ah I see
what ratios do you want?
4:3, 16:9 and 16:10?

@mardy
Copy link
Collaborator

mardy commented Aug 30, 2025

ah I see what ratios do you want? 4:3, 16:9 and 16:10?

I would only care about 4:3 and 16:9, personally.

@Fancy2209
Copy link
Author

ah I see what ratios do you want? 4:3, 16:9 and 16:10?

I would only care about 4:3 and 16:9, personally.

Fair
Something is broken, when I set the aspect ratio and test on dolphin something breaks if I set the env var, addr2line doesn't say where though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants