Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ditch DirectX in favor of OpenGL; use SDL window; ditch Windows Registry #1983

Merged
merged 5 commits into from
Dec 12, 2024

Conversation

rr-
Copy link
Collaborator

@rr- rr- commented Dec 2, 2024

Checklist

  • I have read the coding conventions
  • I have added a changelog entry about what my pull request accomplishes, or it is an internal change

Description

As a reminder:

  • (NEW) F1/Shift-F1: toggle upscaling 1-2-3-4× ("scaler")
  • F2/Shift-F2: increase or decrease viewport size ("sizer")
  • F3: toggle bilinear filter
  • F4: toggle perspective filter
  • F7: toggle zbuffer
  • F12: toggle SWR/HWR renderer

Known issues:

  • There are black rectangles around the window on some configurations
  • The game sometimes crashes when using the new scaler option (F1 / Shift-F1)
  • Scaler/sizer woes with HWR/SWR
  • Console fails to get drawn on non-1x-scaling
  • Window isn't brought to front on launch
  • Text doesn't respect aspect ratio
  • Aspect ratio issues
  • ZBuffer near plane clipping (looking closely at door objects, passport animation)
  • Alpha problems for UI in HWR
  • Alpha problems for UI in SWR
  • Alpha edge problems in textures in HWR
  • Ingame backgrounds do not work at all (neither SWR nor HWR)
  • 3D pickups overlay clips with HWR + ZBuffer ON
  • The controls UI doesn't display
  • The ammo counter doesn't display
  • Health/air bars don't show in HWR + ZBuffer ON
  • Health/air bars appear ugly in HWR
  • The health bar doesn't display when highlighting a medi pack in the inventory
  • If you use F5/F6 or flip through the passport pages - the OPTION text blinks. It's subtle but noticeable.
  • Green pixels appear in explosion sprites in Dragon's Lair (level file textures seem OK, doesn't happen in OG)
  • Fade out in the title screen clips the inventory items in HWR / ZBuffer ON
  • The end of level stats background uses the main menu image instead, with these steps (/play 1, /endlevel)
  • The end of level stats background looks bugged (/play 1, open then close the inventory, /endlevel, skip cutscene)
  • The textures keep zooming in when toggling the renderer with the bilinear filter on
  • Quitting the game with Alt+F4 goes to the inventory very briefly(?)
  • The end of level stats background is now a black screen. In OG, the end of level stats uses the carpet background like the inventory.
  • The game crashes with these steps: /play 1, open the inventory or F5 or F6, /title
  • The game crashes with these steps: /play 1, open the inventory or F5 or F6, /demo, ending the demo crashes the game
  • If TR2X is behind another window e.g. notepad, while in the main menu, the game freezes and I get a black screen when the demo mode starts. Conversely, this issue happens when the demo ends while another window is in front of TR2X
  • In the inventory, when the medi pack is highlighted and you switch to another item, the health bar persists until the next item is highlighted. In OG, the health bar would disappear the moment you press left/right to switch.
  • Similar issue to above, if you have a medi pack highlighted when switching to rings above or below, the health bar is slow to disappear and quick to reappear. In OG, the health bar would appear/disappear at the same time as the green arrows in the middle ring.
  • The water/acid/mercury/lava animated textures is now static.
  • SWR crash related to bad default UVs
  • Using F1/Shift+F1 while in the stopwatch/end of level stats causes the UI to become persistent
  • Looking around in the Floater crashes the game when trying to draw too many rooms at once

@rr- rr- added the Enhancement Improvement of an existing feature label Dec 2, 2024
@rr- rr- self-assigned this Dec 2, 2024
Copy link

github-actions bot commented Dec 2, 2024

@rr- rr- added the TR2 label Dec 2, 2024
@walkawayy
Copy link
Collaborator

Honestly this plays really nicely! Credit images fade in / fade out seems to work fine.

Some issues I noticed (at least with HWR):

  • No inventory red waving background. Just a black screen.
  • 3D pickups in the overlay are sometimes behind geometry in the game world like the floor. They also don't clip their meshes properly.
  • The Bartoli dragon coming alive might need checked? @aredfan I'm not super familiar with it's OG behavior.

@lahm86
Copy link
Collaborator

lahm86 commented Dec 3, 2024

Looking great so far! Other than the issues mentioned, I've noticed the following.

  • Window isn't brought to front on launch

  • Health/air bars don't show in HWR

  • Full screen aspect ratio issue maybe? 2560x1440 suffers from "wide/squashed Lara" issue; maximized window-mode doesn't have this problem.
    image

  • Green pixels appear in explosion sprites in Dragon's Lair (level file textures seem OK, doesn't happen in OG)
    image

@aredfan
Copy link
Collaborator

aredfan commented Dec 3, 2024

I made a note of these few issues after a short time testing on HWR.

  • The controls UI doesn't display.
  • The ammo counter doesn't display.
  • The colour bitrate is lower in HWR compared to before, maybe it's using 24 instead of 32?

@walkawayy I didn't notice anything out of the ordinary with the dragon but I can check again soon.

@rr-
Copy link
Collaborator Author

rr- commented Dec 3, 2024

  • The colour bitrate is lower in HWR compared to before, maybe it's using 24 instead of 32?

Can I get direct comparison screenshots? Thanks. If anything it's using 8-bit palette rather than the 16-bit one, but I didn't notice differences so I'd appreciate a more direct example.

@aredfan
Copy link
Collaborator

aredfan commented Dec 3, 2024

  • The colour bitrate is lower in HWR compared to before, maybe it's using 24 instead of 32?

Can I get direct comparison screenshots? Thanks. If anything it's using 8-bit palette rather than the 16-bit one, but I didn't notice differences so I'd appreciate a more direct example.

Yes of course. See the colour bandings in the passport pages in HWR.

PR:
20241203_125135_The_Dragons_Lair
Dev snapshot:
20241203_125248_The_Dragons_Lair

The fire sprite has a mixture of orange and yellow in the dev snapshot, whereas it's mostly orange in the PR.
PR:
20241203_125149_The_Dragons_Lair
Dev snapshot:
20241203_125252_The_Dragons_Lair

@rr-
Copy link
Collaborator Author

rr- commented Dec 3, 2024

@aredfan what if you use windowed mode and disable 16-bit textures?

@aredfan
Copy link
Collaborator

aredfan commented Dec 3, 2024

The controls UI is fixed, thank you, but the transparent backgrounds are now more opaque. More screenshots to follow.

Left is latest dev snapshot, right is PR.

HWR:
1
2
SWR:
3

Edit: I noticed the alpha textures appears different along the edges, when bilinear filter is enabled.

Left is latest dev snapshot, right is PR.
1

@rr-
Copy link
Collaborator Author

rr- commented Dec 3, 2024

@lahm86 can you check the newest build (once it finishes building) for this?

Window isn't brought to front on launch

I can't test this part reliably on wine.

@lahm86
Copy link
Collaborator

lahm86 commented Dec 3, 2024

@lahm86 can you check the newest build (once it finishes building) for this?

Window isn't brought to front on launch

I can't test this part reliably on wine.

Fixed! Thank you.

@aredfan
Copy link
Collaborator

aredfan commented Dec 3, 2024

The UI alpha issue in HWR is fully resolved, thank you. 👍

There's UI alpha issues remaining in SWR. Whilst the customize controls section looks good. 👇

20241203_165435_Laras_Home

Whereas other aspects of the main menu are showing black parts in the transparent backgrounds.

Left is latest dev snapshot, right is the PR build.
1
2
3


Edit: New issue possibly. This only happens when z-buffer is enabled. Lara's Home, room 55.

Left is latest dev snapshot, right is the PR build.
1


  • The health bar doesn't display when highlighting a medi pack in the inventory.
  • If you use F5/F6 or flip through the passport pages - the OPTION text blinks. It's subtle but noticeable.

@rr-
Copy link
Collaborator Author

rr- commented Dec 3, 2024

@aredfan re: weird colors of UI, that's just the way it is with 8-bit palettes. Notice how the good part is actually rendered on top of the keys meshes which have a different background.

@aredfan
Copy link
Collaborator

aredfan commented Dec 6, 2024

I found these issues while testing.


The end of level stats background uses the main menu image instead, with these steps:

  1. /play 1
  2. /L

20241206_180202_The_Great_Wall


The end of level stats background looks bugged, with these steps:

  1. /play 1
  2. open then close the inventory
  3. /L
  4. skip cutscene

20241206_180220_The_Great_Wall


The game crashes with these steps:

  1. /play 1
  2. open then close the inventory
  3. /title

or

  1. /play 4
  2. open then close the inventory
  3. /L

I found this new issue, if you have bilinear filter enabled and keep pressing F12, the textures will keep zooming in.

20241206_182600_The_Great_Wall

@lahm86
Copy link
Collaborator

lahm86 commented Dec 6, 2024

A few things noticed (clean config/install):

  • Wide/squashed Lara now happens (for me at least) in either windowed of full-screen mode
  • The issue of the window not coming to the front seems to have regressed
  • The bars are cut off in windowed mode
    image
    image

@rr-
Copy link
Collaborator Author

rr- commented Dec 6, 2024

Wide/squashed Lara now happens (for me at least) in either windowed of full-screen mode

This is likely caused by the aspect ratio mode setting. ((Just a quick reminder, it's now located in the config instead of -setup, and it should be possible to change it at runtime with /set). I'll keep this tracked under the aspect ratio issues checkbox.

The issue of the window not coming to the front seems to have regressed

Can I ask for help with this one? The original fix was to call SDL_RaiseWindow after SDL_ShowWindow which hasn't been touched since.

The bars are cut off in windowed mode

I'll tackle this as part of the black rectangles issue.

@aredfan
Copy link
Collaborator

aredfan commented Dec 7, 2024

The regressions in my previous reply are fixed, thank you. There are some more issues I found while doing further tests.


  • The end of level stats background is now a black screen. In OG, the end of level stats uses the carpet background like the inventory.

  • The game crashes with these steps:
  1. /play 1
  2. open the inventory or F5 or F6
  3. /title

  • The game crashes with these steps:
  1. /play 1
  2. open the inventory or F5 or F6
  3. /demo
  4. ending the demo crashes the game

  • If TR2X is behind another window e.g. notepad, while in the main menu, the game freezes and I get a black screen when the demo mode starts. Conversely, this issue happens when the demo ends while another window is in front of TR2X

  • In the inventory, when the medi pack is highlighted and you switch to another item, the health bar persists until the next item is highlighted. In OG, the health bar would disappear the moment you press left/right to switch.
  • Similar issue to above, if you have a medi pack highlighted when switching to rings above or below, the health bar is slow to disappear and quick to reappear. In OG, the health bar would appear/disappear at the same time as the green arrows in the middle ring.

  • The water/acid/mercury/lava animated textures is now static.

@lahm86
Copy link
Collaborator

lahm86 commented Dec 7, 2024

Wide/squashed Lara

Got it, apologies. Yes, it looks OK on 16:9 in windowed mode again (so just full-screen issue remains). Maybe this should be the default aspect ration as the default window size is 1280x720? Would it be helpful if I provide a diff for the config tool option additions? Or if you'd like to keep that as a separate PR, that's understandable.

Cut-off bars in windowed mode

Just to add here that this only happens in windowed 4:3 aspect ratio, 16:9 appears normal.

Window to front

I can't find the solution to this. I am wondering if it's Windows blocking it for some reason, there are a lot of criteria seemingly for setting the foreground window (I assume SDL is eventually calling this Windows function under the hood). Perhaps it's related to the fact the exe is still Tomb2.exe and Windows thinks we're trying to steal focus (although in my head the criteria is met so I'm really not sure). It's certainly not an issue in TR1X, so maybe we come back to address this one at a later date.
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setforegroundwindow#remarks

@rr-
Copy link
Collaborator Author

rr- commented Dec 7, 2024

Wide/squashed Lara

Got it, apologies. Yes, it looks OK on 16:9 in windowed mode again (so just full-screen issue remains). Maybe this should be the default aspect ration as the default window size is 1280x720? Would it be helpful if I provide a diff for the config tool option additions? Or if you'd like to keep that as a separate PR, that's understandable.

Yeah – let's default to 16:9. I also plan to add letterboxing in case the player chooses 4:3 aspect mode but has a bigger window. I suppose we should provide some degree of configuration in the config tool, but IMO not all settings make sense, such as window width or height, or the fullscreen option. In any event I'd appreciate a diff to consolidate into this PR with the rest of the settings.

Cut-off bars in windowed mode

Just to add here that this only happens in windowed 4:3 aspect ratio, 16:9 appears normal.

Thanks, but I believe in general the viewport logic needs adjustment as it's clearly cut when the window size is not a multiple of 32.

Window to front

I can't find the solution to this. I am wondering if it's Windows blocking it for some reason, there are a lot of criteria seemingly for setting the foreground window (I assume SDL is eventually calling this Windows function under the hood). Perhaps it's related to the fact the exe is still Tomb2.exe and Windows thinks we're trying to steal focus (although in my head the criteria is met so I'm really not sure). It's certainly not an issue in TR1X, so maybe we come back to address this one at a later date. https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setforegroundwindow#remarks

Thanks for looking into it. Yeah, I think it's best to tackle it as a follow-up issue.

@lahm86
Copy link
Collaborator

lahm86 commented Dec 7, 2024

@rr- LMK if this looks OK. I've only added three config options: aspect ratio, fade effects and mic at Lara. Everything else I agree doesn't make sense in the config tool.
I've updated camera.c too to reference the mic setting. I suppose we could do away with g_Camera.is_lara_mic but I'm not sure if it's used anywhere else in code yet to be decompiled. I've checked this and it works, so e.g. /play 0 /tp 43 2 89 - depending on the setting, you will either hear the clock after pushing the button when the camera shifts or not.

diff --git a/src/tr2/config_map.def b/src/tr2/config_map.def
index 1f5f6202..e4dfa1ab 100644
--- a/src/tr2/config_map.def
+++ b/src/tr2/config_map.def
@@ -9,7 +9,7 @@ CFG_BOOL(g_Config, visuals.enable_fade_effects, true)
 CFG_BOOL(g_Config, visuals.fix_item_rots, true)
 CFG_ENUM(g_Config, rendering.screenshot_format, SCREENSHOT_FORMAT_JPEG, SCREENSHOT_FORMAT)
 CFG_ENUM(g_Config, rendering.render_mode, RM_HARDWARE, RENDER_MODE)
-CFG_ENUM(g_Config, rendering.aspect_mode, AM_ANY, ASPECT_MODE)
+CFG_ENUM(g_Config, rendering.aspect_mode, AM_16_9, ASPECT_MODE)
 CFG_ENUM(g_Config, rendering.texture_filter, GFX_TF_NN, GFX_TEXTURE_FILTER)
 CFG_BOOL(g_Config, rendering.enable_zbuffer, true)
 CFG_BOOL(g_Config, rendering.enable_perspective_filter, true)
diff --git a/src/tr2/game/camera.c b/src/tr2/game/camera.c
index 4da1e9e3..f2f8e13b 100644
--- a/src/tr2/game/camera.c
+++ b/src/tr2/game/camera.c
@@ -31,6 +31,7 @@
 
 void __cdecl Camera_Initialise(void)
 {
+    g_Camera.is_lara_mic = g_Config.audio.enable_lara_mic;
     Camera_ResetPosition();
     Output_AlterFOV(GAME_FOV * PHD_DEGREE);
     Camera_Update();
diff --git a/tools/tr2/config/TR2X_ConfigTool/Resources/Lang/en.json b/tools/tr2/config/TR2X_ConfigTool/Resources/Lang/en.json
index a567aa39..00060384 100644
--- a/tools/tr2/config/TR2X_ConfigTool/Resources/Lang/en.json
+++ b/tools/tr2/config/TR2X_ConfigTool/Resources/Lang/en.json
@@ -10,6 +10,11 @@
     "screenshot_format": {
       "jpg": "JPEG",
       "png": "PNG"
+    },
+    "aspect_mode": {
+      "any": "Any",
+      "16:9": "16:9",
+      "4:3": "4:3"
     }
   },
   "Properties": {
@@ -41,9 +46,21 @@
       "Title": "Key item pre-selection",
       "Description": "When Lara presses action against a keyhole or puzzle slot, and she has the corresponding item in the inventory, that item will be pre-selected."
     },
+    "aspect_mode": {
+      "Title": "Aspect mode",
+      "Description": "Set the aspect ratio of the game output."
+    },
     "screenshot_format": {
       "Title": "Screenshot format",
       "Description": "Screenshot file format."
+    },
+    "enable_lara_mic" : {
+      "Title": "Microphone at Lara",
+      "Description": "Set the microphone to be at Lara's position. If disabled, the microphone will be at the camera's position."
+    },
+    "enable_fade_effects": {
+      "Title": "Fade effects",
+      "Description": "Enable fade transitions, for example between credit graphics."
     }
   }
 }
diff --git a/tools/tr2/config/TR2X_ConfigTool/Resources/specification.json b/tools/tr2/config/TR2X_ConfigTool/Resources/specification.json
index 53c99167..e3a71e8b 100644
--- a/tools/tr2/config/TR2X_ConfigTool/Resources/specification.json
+++ b/tools/tr2/config/TR2X_ConfigTool/Resources/specification.json
@@ -3,6 +3,11 @@
     "screenshot_format": [
       "jpg",
       "png"
+    ],
+    "aspect_mode": [
+      "any",
+      "16:9",
+      "4:3"
     ]
   },
   "CategorisedProperties": [
@@ -70,6 +75,12 @@
           "DataType": "Bool",
           "DefaultValue": true
         },
+        {
+          "Field": "aspect_mode",
+          "DataType": "Enum",
+          "EnumKey": "aspect_mode",
+          "DefaultValue": "16:9"
+        },
         {
           "Field": "screenshot_format",
           "DataType": "Enum",
@@ -82,14 +93,22 @@
       "ID": "sound",
       "Image": "Graphics/graphic6.jpg",
       "Properties": [
-
+        {
+          "Field": "enable_lara_mic",
+          "DataType": "Bool",
+          "DefaultValue": false
+        }
       ]
     },
     {
       "ID": "ui",
       "Image": "Graphics/graphic7.jpg",
       "Properties": [
-
+        {
+          "Field": "enable_fade_effects",
+          "DataType": "Bool",
+          "DefaultValue": true
+        }
       ]
     }
   ]

@rr-
Copy link
Collaborator Author

rr- commented Dec 7, 2024

I believe the g_Camera fix should go as a separately tracked issue/PR pair as it seems to be an OG bug.

@walkawayy
Copy link
Collaborator

I just tested the latest version with the HWR and:

  • The game window was brought to the front for me with no issue. I had a window open, launched the game, and it appeared at the front with no issue.
  • Console fails to get drawn on non-1x-scaling only happens to me in windowed mode. At scalings 2-4, the console is drawn fine for me in fullscreen. It looks like the font is getting bigger though in windowed mode at these scalings which I'm guessing means the console is getting drawn offscreen or something?
  • I couldn't reproduce a crash using the new scaling option. I tried F1 / shift F1 ing a lot with no issue.
  • I don't know what the F2 key does, but it seems broken. It moves the game window increasingly offscreen in both windowed and fullscreen. Here's a screenshot of what happens:
    image

@lahm86
Copy link
Collaborator

lahm86 commented Dec 8, 2024

I've noticed since previous checks the skybox appearing in the distance in e.g. Offshore Rig, but I'm wondering if this can be fixed by introducing draw dist/fade settings. And if so, it'd be fine as a follow up task IMO. I don't think this is a new issue in the PR by the way, I just skipped past certain levels with the problem.

image

One bigger issue has appeared though since testing yesterday: SWR mode crashes for me in windowed mode, but it seems to be dependent on the window size. Unfortunately the log file doesn't produce a trace. The default window size is fine, but it consistently crashes with these values (for example) in the config.

"width" : 1999,
"height" : 1180,

@rr- rr- requested a review from aredfan December 10, 2024 22:08
Copy link
Collaborator

@walkawayy walkawayy left a comment

Choose a reason for hiding this comment

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

LGTM

@walkawayy
Copy link
Collaborator

Only thing I noticed was the z-buffer issues in HWR and SWR but it's under known issues.

image

Copy link
Collaborator

@aredfan aredfan left a comment

Choose a reason for hiding this comment

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

A small issue I noticed when using shift+f7 - the OSD says Z-Buffer On.

Apart from that, everything LGTM, and thank you. 👍

@rr-
Copy link
Collaborator Author

rr- commented Dec 11, 2024

Only thing I noticed was the z-buffer issues in HWR and SWR but it's under known issues.

image

Thank you for re-testing. To clarify, I see the screenshot above is taken with the software renderer, so the z-buffer setting isn't relevant there, and this sorting issue matches the OG's behavior. The issues mainly arise in HWR with the Z buffer on, when we encounter depth races in shadows or culling of objects close to the camera, which differ from the original's behavior.

20241211_085504_Laras_Home
20241211_085503_Laras_Home

@rr-
Copy link
Collaborator Author

rr- commented Dec 11, 2024

Rebased on top of #2004 which'll need to go first. Added a fix for the Z buffer near plane clipping, and an additional fix to support wireframe mode in the inventory screen.

@rr-
Copy link
Collaborator Author

rr- commented Dec 12, 2024

Added changes from #2007. This resolved visual depth issues when viewing multiple transparent surfaces that are either in close proximity or intersect with one another, with the z-buffer enabled.
@aredfan can I ask for one last round of sanity checks?

@aredfan
Copy link
Collaborator

aredfan commented Dec 12, 2024

@rr- The transparent surfaces fix is working well, and it also fixes the same issue that was apparent in Lara's basement.

I also re-checked all the issues listed in the OP, LGTM.

Copy link
Collaborator

@walkawayy walkawayy left a comment

Choose a reason for hiding this comment

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

LGTM!

- fixed black borders in windowed mode (#1645)
- fixed "Failed to create device" when toggling fullscreen (#1842)
- fixed distant rooms sometimes not appearing, causing the skybox to be visible when it shouldn't (#2000)
- replaced fully the Windows Registry configuration with .json files
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick but this is slightly awkward wording imo. I would remove fully.

@rr- rr- merged commit 7d158da into develop Dec 12, 2024
5 checks passed
@rr- rr- deleted the tr2-opengl branch December 12, 2024 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Improvement of an existing feature TR2
Projects
Status: Done
4 participants