Giter VIP home page Giter VIP logo

sdl12-compat's Introduction

Simple DirectMedia Layer (SDL) sdl12-compat

https://www.libsdl.org/

This is the Simple DirectMedia Layer, a general API that provides low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D framebuffer across multiple platforms.

This code is a compatibility layer; it provides a binary and source compatible API for programs written against SDL 1.2, but it uses SDL 2.0 behind the scenes. If you are writing new code, please target SDL 2.0 directly and do not use this layer.

If you absolutely must have the real SDL 1.2 ("SDL 1.2 Classic"), please use the source tree at https://github.com/libsdl-org/SDL-1.2, which occasionally gets bug fixes but no formal release. But we strongly encourage you not to do that.

How to use:

  • Build the library. This will need access to SDL2's headers (v2.0.7 or newer), CMake and the build tools of your choice. Once built, you will have a drop-in replacement that can be used with any existing binary that relies on SDL 1.2. You can copy this library over the existing 1.2 build, or force it to take priority over a system copy with LD_LIBRARY_PATH, etc. At runtime, sdl12-compat needs to be able to find a copy of SDL2 (v2.0.7 or newer -- v2.0.12 or newer for Windows), so plan to include it with the library if necessary.

  • If you want to build an SDL 1.2 program from source code, we have included compatibility headers, so that sdl12-compat can completely replace SDL 1.2 at all points. These headers are just the bare minimum needed for source-level compatibility and don't have a lot of documentation or fanciness at all. The new headers are also under the zlib license. Note that sdl12-compat itself does not use these headers, so if you just want the library, you don't need them.

Building the library:

These are quick-start instructions; there isn't anything out of the ordinary here if you're used to using CMake.

You'll need to use CMake to build sdl12-compat. Download at cmake.org or install from your package manager (sudo apt-get install cmake on Ubuntu, etc).

Please refer to the CMake documentation for complete details, as platform and build tool details vary.

You'll need a copy of SDL 2.0.x to build sdl12-compat, because we need the SDL2 headers. You can build this from source or install from a package manager. Windows and Mac users can download prebuilt binaries from SDL's download page; make sure you get the "development libraries" and not "runtime binaries" there.

Linux users might need some packages from their Linux distribution. On Ubuntu, you might need to do:

sudo apt-get install build-essential cmake libsdl2-2.0-0 libsdl2-dev libgl-dev

Now just point CMake at sdl12-compat's directory. Here's a command-line example:

cd sdl12-compat
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release .
cmake --build build

On Windows or macOS, you might prefer to use CMake's GUI, but it's the same idea: give it the directory where sdl12-compat is located, click "Configure," choose your favorite compiler, then click "Generate." Now you have project files! Click "Open Project" to launch your development environment. Then you can build however you like with Visual Studio, Xcode, etc.

If necessary, you might have to fill in the location of the SDL2 headers when using CMake. sdl12-compat does not need SDL2's library to build, just its headers (although it may complain about the missing library, you can ignore that). From the command line, add -DSDL2_INCLUDE_DIR=/path/to/SDL2/include, or find this in the CMake GUI and set it appropriately, click "Configure" again, and then "Generate."

When the build is complete, you'll have a shared library you can drop in as a replacement for an existing SDL 1.2 build. This will also build the original SDL 1.2 test apps, so you can verify the library is working.

Building for older CPU architectures on Linux:

There are a lot of binaries from many years ago that used SDL 1.2, which is to say they are for CPU architectures that are likely not your current system's.

If you want to build a 32-bit x86 library on an x86-64 Linux machine, for compatibility with older games, you should install some basic 32-bit development libraries for your distribution. On Ubuntu, this would be:

sudo apt-get install gcc-multilib libsdl2-dev:i386

...and then add -m32 to your build options:

cd sdl12-compat
cmake -Bbuild32 -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS=-m32
cmake --build build32

Building for older CPU architectures on macOS:

macOS users can try adding -DCMAKE_OSX_ARCHITECTURES='arm64;x86_64' instead of -DCMAKE_C_FLAGS=-m32 to make a Universal Binary for both 64-bit Intel and Apple Silicon machines. If you have an older (or much older!) version of Xcode, you can try to build with "i386" or maybe even "powerpc" for 32-bit Intel or PowerPC systems, but Xcode (and macOS itself) has not supported either of these for quite some time, and you will likely struggle to get SDL2 to compile here in small ways, as well...but with some effort, it's maybe possible to run SDL2 and sdl12-compat on Apple's abandoned architectures.

Building for older CPU architectures on Windows:

Windows users just select a 32-bit version of Visual Studio when running CMake, when it asks you what compiler to target in the CMake GUI.

Configuration options:

sdl12-compat has a number of configuration options which can be used to work around issues with individual applications, or to better fit your system or preferences.

These options are all specified as environment variables, and can be set by running your application with them set on the command-line, for example:

SDL12COMPAT_HIGHDPI=1 SDL12COMPAT_OPENGL_SCALING=0 %command%

will run %command% with high-dpi monitor support enabled, but OpenGL scaling support disabled.

(While these environment variables are checked at various times throughout the lifetime of the app, sdl12-compat expects these to be set before the process starts and not change during the life of the process, and any places where changing it later might affect operation is purely accidental and might change. That is to say: don't write an SDL 1.2-based app with plans to tweak these values on the fly!)

The available options are:

  • SDL12COMPAT_DEBUG_LOGGING: (checked at startup) If enabled, print debugging messages to stderr. These messages are mostly useful to developers, or when trying to track down a specific bug.

  • SDL12COMPAT_FAKE_CDROM_PATH: (checked during SDL_Init) A path to a directory containing MP3 files (named trackXX.mp3, where XX is a two-digit track number) to be used by applications which play CD audio. Using an absolute path is recommended: relative paths are not guaranteed to work correctly.

  • SDL12COMPAT_OPENGL_SCALING: (checked during SDL_Init) Enables scaling of OpenGL applications to the current desktop resolution. If disabled, applications can change the real screen resolution. This option is enabled by default, but not all applications are compatible with it: try changing this if you can only see a black screen.

  • SDL12COMPAT_FIX_BORDERLESS_FS_WIN: (checked during SDL_SetVideoMode) Enables turning borderless windows at the desktop resolution into actual fullscreen windows (so they'll go into a separate space on macOS and properly hide dock windows on other desktop environments, etc). If disabled, applications may not get the full display to theirselves as they expect. This option is enabled by default, but this option is here so it can be manually disabled, in case this causes some negative result we haven't anticipated.

  • SDL12COMPAT_SCALE_METHOD: (checked during SDL_Init) Choose the scaling method used when applications render at a non-native resolution. The options are nearest, for nearest-neighbour sampling (more pixelated) and linear for bilinear sampling (blurrier).

  • SDL12COMPAT_HIGHDPI: (checked during SDL_SetVideoMode) Advertise the application as supporting high-DPI displays. Enabling this will usually result in sharper graphics, but on some applications text and other elements may become very small.

  • SDL12COMPAT_SYNC_TO_VBLANK: (checked during SDL_SetVideoMode) Force the application to sync (or not sync) to the vertical blanking interval (VSync). When enabled, this will cap the application's framerate to the screen's refresh rate (and may resolve issues with screen tearing).

  • SDL12COMPAT_USE_KEYBOARD_LAYOUT: (checked during SDL_Init) Make all keyboard input take the current keyboard layout into account. This may need to be disabled for applications which provide their own keyboard layout support, or if the position of the keys on the keyboard is more important than the character they produce. Note that text input (in most applications) will take the keyboard layout into account regardless of this option.

  • SDL12COMPAT_USE_GAME_CONTROLLERS: (checked during SDL_Init) Use SDL2's higher-level Game Controller API to expose joysticks instead of its lower-level joystick API. The benefit of this is that you can exert more control over arbitrary hardware (deadzones, button mapping, device name, etc), and button and axes layouts are consistent (what is physically located where an Xbox360's "A" button is will always be SDL 1.2 joystick button 0, "B" will be 1, etc). The downside is it might not expose all of a given piece of hardware's functionality, or simply not make sense in general...if you need to use a flight stick, for example, you should not use this hint. If there is no known game controller mapping for a joystick, and this hint is in use, it will not be listed as an availble device.

  • SDL12COMPAT_WINDOW_SCALING: (checked during SDL_SetVideoMode) When creating non-fullscreen, non-resizable windows, use this variable to size the window differently. If, for example, you have a 4K monitor and the game is running in a window the size of a postage stamp, you might set this to 2 to double the size of the window. Fractional values work, so "1.5" might be a more-pleasing value on your hardware. You can even shrink the window with values less than 1.0! When scaling a window like this, sdl12-compat will use all the usual scaling options (SDL12COMPAT_OPENGL_SCALING, SDL12COMPAT_SCALE_METHOD, etc). If sdl12-compat can't scale the contents of the window for various technical reasons, it will create the window at the originally-requested size. If this variable isn't specified, it defaults to 1.0 (no scaling).

  • SDL12COMPAT_MAX_VIDMODE: (checked during SDL_Init) This is a string in the form of WxH, where W is the maximum width and H is the maximum height (for example: 640x480). The list of valid resolutions that will be reported by SDL_ListModes and SDL_VideoModeOK will not include any dimensions that are wider or taller than these sizes. A size of zero will be ignored, so for 0x480 a resolution of 1920x480 would be accepted). If not specified, or set to 0x0, no resolution clamping is done. This is for old software-rendered games that might always choose the largest resolution offered, but never conceived of 4K displays. In these cases, it might be better for them to use a smaller resolution and let sdl12-compat scale their output up with the GPU.

  • SDL_MOUSE_RELATIVE_SCALING: (checked during SDL_SetVideoMode) If enabled, relative mouse motion is scaled when the application is running at a non-native resolution. This may be required with some applications which use their own mouse cursors. See also: https://wiki.libsdl.org/SDL_HINT_MOUSE_RELATIVE_SCALING

  • SDL12COMPAT_ALLOW_THREADED_DRAWS: (checked during SDL_Init) Enabled by default. If disabled, calls to SDL_UpdateRects() from non-main threads are converted into requests for the main thread to carry out the update later. The thread that called SDL_SetVideoMode() is treated as the main thread.

  • SDL12COMPAT_ALLOW_THREADED_PUMPS: (checked during SDL_Init) Enabled by default. If disabled, calls to SDL_PumpEvents() from non-main threads are completely ignored. The thread that called SDL_SetVideoMode() is treated as the main thread.

  • SDL12COMPAT_ALLOW_SYSWM: (checked during SDL_Init) Enabled by default. If disabled, SDL_SYSWMEVENT events will not be delivered to the app, and SDL_GetWMInfo() will fail; this is useful if you have a program that tries to access X11 directly through SDL's interfaces, but can survive without it, becoming compatible with, for example, Wayland, or perhaps just avoiding a bug in target-specific code. Note that sdl12-compat already disallows SysWM things unless SDL2 is using its "windows" or "x11" video backends, because SDL 1.2 didn't have wide support for its SysWM APIs outside of Windows and X11 anyhow.

  • SDL12COMPAT_NO_QUIT_VIDEO: (checked during SDL_QuitSubsystem) If enabled, SDL_Quit() and SDL_QuitSubsystem() will never shut down the video subsystem. This works around buggy applications which try to use the video subsystem after shutting it down.

Compatibility issues with OpenGL scaling

The OpenGL scaling feature of sdl12-compat allows applications which wish to run at a non-native screen resolution to do so without changing the system resolution. It does this by redirecting OpenGL rendering calls to a "fake" backbuffer which is scaled when rendering.

This works well for simple applications, but for more complicated applications which use Frame Buffer Objects, sdl12-compat needs to intercept and redirect some OpenGL calls. Applications which access these functions without going though SDL (even if via a library) may not successfully render anything, or may render incorrectly if OpenGL scaling is enabled.

In these cases, you can disable OpenGL scaling by setting the environment variable:

SDL12COMPAT_OPENGL_SCALING=0

Compatibility issues with applications directly accessing underlying APIs

Some applications combine the use of SDL with direct access to the underlying OS or window system. When running these applications on the same OS and SDL video driver (e.g. a program written for X11 on Linux is run on X11 on Linux), sdl12-compat is usually compatible.

However, if you wish to run an application on a different video driver, the application will be unable to access the underlying API it is expecting, and may fail. This often occurs trying to run applications written for X11 under Wayland, and particularly affects a number of popular OpenGL extension loaders.

In this case, the best workaround is to run under a compatibility layer like XWayland, and set the SDL_VIDEODRIVER environment variable to the driver the program is expecting:

SDL_VIDEODRIVER=x11

sdl12-compat's People

Contributors

1bsyl avatar akb825 avatar alarixnia avatar albertvaka avatar ccawley2011 avatar cg9999 avatar conan-kudo avatar danielgibson avatar foxmccloud45 avatar icculus avatar jmroot avatar lanodan avatar madebr avatar manisandro avatar rtissera avatar sezero avatar slouken avatar smcv avatar sulix avatar twolife avatar tylerlm avatar zmanuel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sdl12-compat's Issues

High DPI

Doesn't it make sense to set "SDL_WINDOW_ALLOW_HIGHDPI" in flags20 since the output is automatically rescaled anyway? I patched sdl12-compat to unconditionally set it and tried it with UT2004 and it works well on Sway @3840x2160 2x scaled.

segfault upon video quit and re-init because of stale static data

Consider this code:

	SDL_FreeSurface(screen);
	SDL_QuitSubSystem(SDL_INIT_VIDEO);	// also unloads the opengl driver

	SDL_InitSubSystem(SDL_INIT_VIDEO);

	SDL_GL_LoadLibrary(NULL);	// then load gl funcs

	VID_SetMode (newmode);		// calls SDL_WM_SetIcon and SDL_SetVideoMode

It segfaults like:

#0  0x04f23473 in ?? () from /usr/lib/libGL.so.1
#1  0x04f25e51 in ?? () from /usr/lib/libGL.so.1
#2  0x04efe558 in glXDestroyContext () from /usr/lib/libGL.so.1
#3  0x00326223 in X11_GL_DeleteContext (_this=0x888ecb8, context=0x89be1a8) at /opt/src/SDL/src/video/x11/SDL_x11opengl.c:947
#4  0x00303af0 in SDL_GL_DeleteContext_REAL (context=0x89be1a8) at /opt/src/SDL/src/video/SDL_video.c:3830
#5  0x00220bf5 in SDL_GL_DeleteContext (a=0x89be1a8) at /opt/src/SDL/src/dynapi/SDL_dynapi_procs.h:595
#6  0x001cfa90 in SDL_SetVideoMode (width=1024, height=768, bpp=16, flags12=2) at /opt/src/sdl12-compat/src/SDL12_compat.c:2856
#7  0x0805d5cb in VID_SetMode (modenum=3) at ../h2shared/gl_vidsdl.c:458
#8  0x0805f7a7 in VID_ChangeVideoMode (newmode=3) at ../h2shared/gl_vidsdl.c:1294
#9  0x0805f8b4 in VID_Restart_f () at ../h2shared/gl_vidsdl.c:1347

This happens beacuse of stale non-NULL VideoGLContext20 after video quit.
I suggest that we call EndVidModeCreate() from Quit12Video(), like:

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 5b1513d..4c69305 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -1344,16 +1344,19 @@ SDL_WasInit(Uint32 sdl12flags)
 
     return InitFlags20to12(SDL20_WasInit(sdl20flags)) | extraflags;
 }
 
+static SDL12_Surface *EndVidModeCreate(void);
 static void
 Quit12Video(void)
 {
     int i;
 
     SDL20_FreeSurface(VideoIcon20);
     VideoIcon20 = NULL;
 
+    EndVidModeCreate(); /* clean-up static data. */
+
     for (i = 0; i < VideoModesCount; i++) {
         SDL20_free(VideoModes[i].modeslist12);
         SDL20_free(VideoModes[i].modes12);
     }

Comments?

[patch] Initial Dosbox compatibility

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: unspecified
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2020-12-23 15:41:17 +0000, Malte Kießling wrote:

Created attachment 4599
Dosbox compatibility

Im throwing everything in this one as im too stupid to base patches on each other.

This patch does three things

  • A messy solution (set scancode to 0) for bug 5412
  • Same change as in bug 5413 letting SDL_GetHWInfo return 0 instead of -1

The thrid thing comes from something weird dosbox does:
To check for the presence of double buffering they have two ways: they either check via SDL_DOUBLEBUF or they check the screen surface via SDL_MUSTLOCK.

Currently, compat sets DOUBLEBUF but not HWSURFACE, thus causing dosbox to draw into one surface (cuase doublebuf is present!) but then not upating stuff properly (cause MUSTLOCK returns 0).

So the thrid thing this patch does is set SDL_HWSURFACE next to SDL_DOUBLEBUF for VideoSurface12.

That was a little weird to figure out.

Happy holidays and whatnot to everyone :D

~mkalte

macOS: Fullscreen not working like SDL2 on multi monitor setup

On macOS (if that makes a difference in this case) with a multi monitor setup going fullscreen with SDL2 only uses the monitor the SDL2 app is currently active. The only screen change is on the one the app is active on. All other monitors can still be used, the SDL2 app stays visible while other apps are acitve.

With SDL 1.2x the app goes fullscreen on the main screen and all others go black, no matter on which monitor the active SDL app was.

With sdl12-compat it behaves strangely:

  • if you go fullscreen on the main screen (center screen), the other screens go black as with SDL 1.2x
  • if you go fullscreen on another screen, all screens go black for a moment, the SDL app will be fullscreen on the monitor it was active on, the other monitors are useable. BUT if you use an app on the other monitors the SDL app will go black until you switch to it.

Tested with DOSBox SVN (there is also a patch for DOSBox to use SDL2 and with that fullscreen behaves like it should with SDL2).

Write zlib-licensed 1.2 headers...

This is super not-urgent right now, but it would be nice if we have SDL 1.2 headers under the zlib license, so sdl12-compat can be used not only as a binary-compatible drop-in replacement for libSDL-1.2, but can also be used to compile 1.2 apps from source, removing the need for distros to ship real SDL 1.2 "development" packages.

I don't know what sort of effort this would take. There's a good chance we can relicense some parts of the 1.2 headers, as its likely Sam or I wrote most of it, but I'd have to sort through them all. It's also possible that it doesn't need to be super-fancy, and we just need to have some extremely basic headers with some function declarations and macros and call it a day.

Add an sdl-config script...

This is the only (?) thing missing to completely replace SDL 1.2 infrastructure: the sdl-config script that reports CFLAGS and LDFLAGS for using SDL 1.2.

This is probably trivial, just needs to be written.

[UT2004] Can't type certain symbols in-game

This bug report was migrated from our old Bugzilla tracker.

Reported in version: unspecified
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2019-08-04 13:50:27 +0000, wrote:

First of all, thanks for working on this!
I was playing around with this fun little thing and noticed the following problem:
You can't type certain symbols, like colon ':', or question mark '?' while playing UT2004 64-bit for linux. This makes difficult connecting to servers, as you can't specify port.
Haven't tested with other games so far.

OS: openSUSE 15.1
Package source: https://build.opensuse.org/package/show/home:khnazile:libSDL12-compat/libSDL12-compat

cdrom code

We have stubs for cdrom code in sdl12-compat.

Should we import the code from SDL-1.2? If we ever do that,
would there be licence issues (can any of the authors still be
reached, etc)?

If we'll keep the stubs, close this.

sdltheoraplay: Unknown pixel format with `--rgb` or `--rgba` command line

  • install dev packages for libogg, libvorbis, and libtheora
  • install dev package for SDL 1.2 (so we have sdl-config, headers, and a lib to link against)
  • Find an Ogg Theora file to play.
  • hg clone https://hg.icculus.org/icculus/theoraplay
  • cd theoraplay/test
  • ./maketest.sh
  • LD_LIBRARY_PATH=/where/i/built/sdl12-compat ./sdltheoraplay --rgb /path/to/my/theora/video.ogv

Output:

[...other debug stuff...]
Shadow surface failed: Unknown pixel format
Initialization failed!

Haven't researched this further yet. --rgba does this too.

[patch] SDL_GetWMInfo always returns -1, some applications only test against 0

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: unspecified
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2020-12-23 15:06:31 +0000, Malte Kießling wrote:

Created attachment 4598
Let SDL_GetWMInfo return 0 "not implemented" for now.

SDL_GetWMInfo is currently returning -1. Documentation states this means the struct is not filled.

Dosbox and some other places (http://sdl.beuc.net/sdl.wiki/SDL_GetWMInfo) however do

if (SDL_GetWMInfo(&info))

So correct behavior on the compat layer side still breaks stuff :(
I suggest always returning 0 as long as no wrapper is constructed. As long as the return value is somewhat managed, i think this would increase compatibility.

~mkalte

SDL_SetVideoMode will fail when called twice if returned surface is freed with SDL_FreeSurface

This bug report was migrated from our old Bugzilla tracker.

Reported in version: unspecified
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2019-03-21 11:50:31 +0000, Dario wrote:

SDL_SetVideoMode(int,int,int,Uint32) returns a VideoSurface12 (SDL12_Surface *).
An application hold this pointer and call to SDL_FreeSurface(SDL12_Surface *).

A second call to SDL_SetVideo_Mode results in a segmentation fault because VideoSurface12 has been invalidated, is not NULL and will be accessed.

I can bypass this issue by adding a conditional on the SDL_FreeSurface that tests the SDL12_Surface pointer for equality against the VideoSurface12.

I encountered this problem while trying a game development engine called BennuGD (https://bitbucket.org/dacucar/bennugd/src/master/) which runs on SDL 1.2.

After doing my small hack, I was able to run a relatively complex game without much trouble.

If you need additional information, let me know.

On 2019-03-21 15:15:19 +0000, Ryan C. Gordon wrote:

Ah, interesting...you aren't supposed to call SDL_FreeSurface() on the return value from SDL_SetVideoMode(), but I see that SDL 1.2 checks for this case and returns immediately if trying to free the screen surface.

I'll fix that.

--ryan.

On 2019-03-21 16:09:13 +0000, Dario wrote:

Interesting, that is exactly what I did to solve it.

You are right in any case, I checked the SDL 1.2 documentation and it says the surface should not be freed.

So I guess I will have to report that too to the other project :).

I can also advance that, when adding the VideoSurface12 check and returning on the SDL_FreeSurface I encountered that when switching from FullScreen to Windowed mode, the game was not correctly scaled: it is as if the game stayed "large" but the area was clipt to the size of the window screen.

On 2019-03-21 16:47:52 +0000, Dario wrote:

Regarding the later, I will investigate further and report when I know more.

On 2019-03-22 13:44:44 +0000, Ryan C. Gordon wrote:

Regarding the later, I will investigate further and report when I know more.

Please do, and open a separate bug for it so we don't forget to fix it! :)

As for this bug: fixed in https://hg.libsdl.org/sdl12-compat/rev/f4f3bf9e36e1, thanks!

--ryan.

SDL 2.0 fails to load at runtime

This bug report was migrated from our old Bugzilla tracker.

Reported in version: unspecified
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2019-03-12 20:07:38 +0000, Mathieu Comandon wrote:

After building the project on Ubuntu 18.10, I was unable to run any game using it, there seems to be an issue with loading the SDL2 shared libraries with dlopen.

Games will consistently crash with the following:

ERROR: sdl12-compat failed to load SDL 2.0! Aborting!
[1] 9699 abort (core dumped) ./ut2004-bin

I had to pass custom arguments for the lib to build with the following command:

C_INCLUDE_PATH="/usr/include/SDL2" make

This was reproduced on UT2003 and Rune (32bit) and UT2004.

Reading through the code, the problem seems to be with the LoadSDL20Library function, the required file (libSDL2-2.0.so.0) is available for both 32 and 64 bit on the system.

error while loading shared libraries: libSDL-1.2.so.0: wrong ELF class: ELFCLASS64

This bug report was migrated from our old Bugzilla tracker.

Reported in version: unspecified
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2019-03-20 23:44:33 +0000, wrote:

Hi, I'm trying to test out sdl12-compat with my set of SDL 1.2 games, and several of them have the following message:
error while loading shared libraries: libSDL-1.2.so.0: wrong ELF class: ELFCLASS64

I've compiled the sdl12-compat using this: gcc -o libSDL-1.2.so.0 -fvisibility=hidden -shared -fPIC -Wall -O0 -ggdb3 -Wl,-soname,libSDL-1.2.so.0 src/SDL12_compat.c sdl2-config --cflags-ldl -lm

I then rename the old libSDL-1.2.so.0 file in the game's directory to orig-libSDL-1.2.so.0, and paste in the compat library to take its place.

Both Aquaria & Crayon Physics Deluxe show this error message in the terminal when trying to run them.

./aquaria: error while loading shared libraries: libSDL-1.2.so.0: wrong ELF class: ELFCLASS64

./crayon: error while loading shared libraries: libSDL-1.2.so.0: wrong ELF class: ELFCLASS64

The rest of my system specs:
Kubuntu 18.10 64 bit
Kernel: 4.18.0-15-generic
KDE 5.13.5

Thanks!

On 2019-03-22 13:53:24 +0000, Ryan C. Gordon wrote:

So what this is telling you is that libSDL-1.2.so.0 is a 64-bit library, but the game in question is 32-bit.

Assuming you have a 32-bit SDL2 somewhere, which sdl12-compat will eventually try to load in this case, you can probably get a 32-bit libSDL-1.2.so.0 by adding "-m32" to your compile command line.

(you might need some 32-bit compatibility packages installed, too, but hopefully this will Just Work when you use -m32.)

Building a 32-bit SDL2 on a 64-bit system with all the desired features turns out to be more difficult, so the quickest solution is to grab the prebuilt version out of the Steam Runtime, which tends to be built with all the features in a distro-agnostic way.

If you have Steam installed, this is sitting in $HOME/steam/ubuntu12_32/steam-runtime/i386/usr/lib/i386-linux-gnu, but I've put a copy here for convenience, too:

https://icculus.org/~icculus/tmp/SDL2-x86-steam-runtime-03222019.tar.bz2

--ryan.

Wolf4SDL loses inputs when mouse grabbed

This bug report was migrated from our old Bugzilla tracker.

Reported in version: unspecified
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2019-10-11 22:57:08 +0000, Rohit Nirmal wrote:

Wolf4SDL build from this git repo: https://github.com/mozzwald/wolf4sdl

When Wolf4SDL is run with sdl12-compat in the default fullscreen mode or with the --windowed-mouse command line option, using the Up and Down arrows in the menu does nothing (Enter and Escape work though). Additionally, the player is always moving during gameplay, even when the mouse and keyboard aren't used.

The problem seems to be related to the SDL_WM_GrabInput call made here: https://github.com/mozzwald/wolf4sdl/blob/master/id_in.cpp#L395

In normal SDL 1.2, moving the mouse up and down can move the menu cursor. I suspect sdl12-compat is somehow misreporting mouse movement when the mouse is grabbed.

Unable to link under OS X

This bug report was migrated from our old Bugzilla tracker.

Reported in version: unspecified
Reported for operating system, platform: macOS 10.13, x86_64

Comments on the original bug report:

On 2019-04-11 07:29:05 +0000, C.W. Betts wrote:

After working around the issue of SDL2 header locations, it fails to link under Mac, complaining about a missing function. The function can be found in src/SDL12_compat_objc.m. After fixing that, it still doesn't link because of a couple new undefined symbols, both related to Objective-C. Telling the linker to link against the AppKit fixes this issue.

Strange behaviour of SDL_SetVideoMode when using it to change between FULL_SCREEN and Windowed

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: unspecified
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2019-03-22 20:33:24 +0000, Dario wrote:

Created attachment 3708
Patch to resolve described issue.

I have a game that uses SDL_SetVideMode to run on SDL_FULLSCREEN mode on a 2560x1440. The non-scaled resolution of the game when running in fullscreen is 1280x720.

The game allows using non-full screen mode, and with GDB I have seen it results invoking SDL_SetVideoMode again without the SDL_FULLSCREEN flag. The target size of the window is 640 x 360.

For some reason, when switching from full screen to windowed, the "surface" does not get resized. It remains at 2560x1440 which results in a clipped area.

When SDL_SetVideoMode is invoked a second time with the 640x360 Windowed, the contents are resized correctly.

I was able to overcome this problem by forcing a EnvVidModeCreate() when the target width and height does not match the width and height that VideoSurface12 contained. See patch.

There might be however a better way of resolving this. I tried to do a lot of debugging but this is as far I could get :).

On 2019-03-22 20:57:46 +0000, Dario wrote:

Created attachment 3709
A video showing game behaviour with submitted patch.

On 2019-03-22 20:59:11 +0000, Dario wrote:

Created attachment 3710
A video showing game behaviour without patch

GBM+GLES?

Last I tested this on my Rockchip RK3328 using an application compiled for GBM and GLES2. I dropped this in place of the SDL1.2 library, the application crashed as it was initializing it's graphics stack. It was months ago so wanted to check if this was a known issue and has since been resolved or if I should plan to get logs for a future issue report. Thanks in advance!

Renderer without SDL_RENDERER_PRESENTVSYNC by default?

This bug report was migrated from our old Bugzilla tracker.

Reported in version: unspecified
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2019-03-22 21:23:53 +0000, Dario wrote:

In SDL_SetVideoMode, the SDL20_CreateRenderer for non-OpenGL windows uses the SDL_RENDER_PRESENTVSYNC by default.

This limits the FPS of a game to my monitor refresh rate, which does not happen with SDL 1.2

According to https://discourse.libsdl.org/t/vsync/8855 VSYNC was not enabled by default on SDL 1.2.

Linux: Unreal Tournament 2004 mouse error

I've tried this to Play UT 04, but the mouse is not registered correctly. I mean the game is not registering mouse moving or blocking in the middle of the screen. I use 1280x1024 monitor.

PC specs:

OS: Ubuntu 20.04 LTS
CPU: Core 2 Duo E7200
GPU: GT 8500 512 MB
RAM: 8 GB DDR2.

The game have no such issues with SDL CL.

https://github.com/MrAlert/sdlcl

SDL_ListModes vs Quakespasm....

(As noted in #42 ... )

Almost certainly it means this line in sdl12-compat's SDL_ListModes() is wrong (where format12 is the pointer that you memset'd in quakespasm)...

if (format12 && (format12 != VideoInfo12.vfmt)) {
    fmt = SDL20_MasksToPixelFormatEnum(format12->BitsPerPixel, format12->Rmask, format12->Gmask, format12->Bmask, format12->Amask);

I'd have to check SDL-1.2, but I suspect there's a minor incompatibility here we need to flush out. I'll open an issue so we don't forget to look into this, but it doesn't appear to be extremely urgent.

Originally posted by @icculus in #42 (comment)

sdl12_compat does not support antialiasing (ut2004)

This bug report was migrated from our old Bugzilla tracker.

Reported in version: unspecified
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2020-05-27 14:07:08 +0000, Tom B wrote:

This compatibility tool works great for playing the game, but it is missing the ability to use antialiasing.

In SDL1.2 you can specify the following in UT2004.ini to get antialiasing:

[OpenGLDrv.OpenGLRenderDevice]
MultisampleBuffers=1
MultisampleSamples=8
MultisampleHint=2

When using sdl12_compat, antialiasing is no longer enabled.

mouse wheel events broken

With current git, we only get mouse wheel 'released' events, no 'pressed' ones.
Also, as far as I can see, the SDL_BUTTON_X1/2 are also broken.

@icculus, @slouken: If no objections, I intend to apply the following patch.
The WHEEL parts of it are tested. BUTTON_X1/2 parts not yet tested (will
test if I can find some mouse that has those buttons.)

With this, I can play quakespasm and uhexen2 quite well with an ordinary
wheel mouse.

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index a8dacc7..e0f9494 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -2003,7 +2003,6 @@ EventFilter20to12(void *data, SDL_Event *event20)
 {
     //const int maxUserEvents12 = SDL12_NUMEVENTS - SDL12_USEREVENT;
     SDL12_Event event12;
-    int x, y;
 
     SDL_assert(data == NULL);  /* currently unused. */
 
@@ -2115,6 +2114,9 @@ EventFilter20to12(void *data, SDL_Event *event20)
             event12.type = SDL12_MOUSEBUTTONDOWN;
             event12.button.which = (Uint8) event20->button.which;
             event12.button.button = event20->button.button;
+            if (event12.button.button > 3) {
+                event12.button.button += 2; /* SDL_BUTTON_X1/2 */
+            }
             event12.button.state = event20->button.state;
             event12.button.x = (Uint16) event20->button.x;
             event12.button.y = (Uint16) event20->button.y;
@@ -2124,6 +2126,9 @@ EventFilter20to12(void *data, SDL_Event *event20)
             event12.type = SDL12_MOUSEBUTTONUP;
             event12.button.which = (Uint8) event20->button.which;
             event12.button.button = event20->button.button;
+            if (event12.button.button > 3) {
+                event12.button.button += 2; /* SDL_BUTTON_X1/2 */
+            }
             event12.button.state = event20->button.state;
             event12.button.x = (Uint16) event20->button.x;
             event12.button.y = (Uint16) event20->button.y;
@@ -2136,12 +2141,13 @@ EventFilter20to12(void *data, SDL_Event *event20)
             event12.type = SDL12_MOUSEBUTTONDOWN;
             event12.button.which = (Uint8) event20->wheel.which;
             event12.button.button = (event20->wheel.y > 0) ? 4 : 5;  /* wheelup is 4, down is 5. */
-            event12.button.state = SDL_GetMouseState(&x, &y);
-            event12.button.x = (Uint16) x;
-            event12.button.y = (Uint16) y;
+            event12.button.state = SDL_PRESSED;
+            event12.button.x = 0;
+            event12.button.y = 0;
             PushEventIfNotFiltered(&event12);
 
             event12.type = SDL12_MOUSEBUTTONUP;  /* immediately release mouse "button" at the end of this switch. */
+            event12.button.state = SDL_RELEASED;
             break;
 
         case SDL_JOYAXISMOTION:

sdltheoraplay: playfile: Assertion `opengl' failed.

  • install dev packages for libogg, libvorbis, and libtheora
  • install dev package for SDL 1.2 (so we have sdl-config, headers, and a lib to link against)
  • Find an Ogg Theora file to play.
  • hg clone https://hg.icculus.org/icculus/theoraplay
  • cd theoraplay/test
  • ./maketest.sh
  • LD_LIBRARY_PATH=/where/i/built/sdl12-compat ./sdltheoraplay --fullscreen /path/to/my/theora/video.ogv

Output:

[...other debug stuff...]
sdltheoraplay: ./sdltheoraplay.c:743: playfile: Assertion `opengl' failed.
Aborted (core dumped)

This is asserting in here in sdltheoraplay:

#if SUPPORT_OPENGL
case SDL_VIDEORESIZE:
    assert(opengl);

This happens because if you tell the app to render with OpenGL, it calls SDL_SetVideoMode with SDL_OPENGL | SDL_RESIZABLE because it can scale video with OpenGL, but the software renderer cannot, so it doesn't use SDL_RESIZABLE.

Introducing the --fullscreen flag, of course, adds SDL_FULLSCREEN to the mix.

What I assume is happening here is that SDL_WINDOW_FULLSCREEN_DESKTOP, which sdl12-compat now uses, generates a resize event (or several) as it settles down, and we shouldn't be passing those on to the 1.2-based app for non-resizable windows. As far as the 1.2 fullscreen window is concerned, they never resize, and all the scaling for both software and OpenGL windows happens behind the scenes.

Mac keyboard issue with function keys

Noticed one thing with keys: With SDL-1.2, I'd hit FN+<funckey> to use
the functions keys, e.g. FN+F3 to load a game, FN+F10 to quit the game.
With the compat-layer, FN+F3 is OK, but FN+F10 does something different,
I have to use <Option>+F10 for it.

Originally posted by @sezero in #28 (comment)

SMPEG YUV overlay issues...

SMPEG uses a YUV overlay for MPEG playback. But its rendering loop is:

  • Lock the overlay
  • Call Display on the overlay
  • copy new data to the locked overlay
  • Unlock the overlay

Which is a problem, because sdl12-compat tries to render with the overlay data during Display.

This feels like maybe a bug in SMPEG, but it still works with SDL 1.2; in case this was a common usage pattern, we need to support it.

To build SMPEG with 1.2 support instead of 2.0:

svn co svn://svn.icculus.org/smpeg/trunk@398 smpeg
cd smpeg
./autogen
CFLAGS="-w" ./configure  # need the -w because of an issue with modern gcc
make  # will fail on gtv, but plaympeg will build.
./plaympeg /any/valid/mpeg1/video.mpg

lbreakout2 - no menu

lbreakout2 doesn't render the menu on the start screen. The menu works if you click blindly and the game works fine. It breifly appears when you quit the game.

macOS: building testsprite fails

after running cmake I get this compile error for testsprite (the lib builds correctly):

[100%] Linking C executable testsprite
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
     (maybe you meant: _SDL_main)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [testsprite] Error 1
make[1]: *** [CMakeFiles/testsprite.dir/all] Error 2
make: *** [all] Error 2

macOS 11.2.2 using SDK 10.15

SMPEG flicker

Now that video renders with Issue #48 fixed, there's still a flicker in it that looks like...vsync tearing? I'm not sure; there's a horizontal black bar or something that pops up at different vertical points as the video progresses.

Maybe it's not updating the whole YUV overlay every time, or it's only drawing a piece of it to the display as a dirty-rectangle thing? I'll have to check.

testpalette.c issues...

Now that the test apps build, we can see some problems in them.

testpalette looks incorrect, like this:

2021-05-24_13-00

...and when you hit ESC to quit, on return from main(), it detects stack corruption and aborts.

Scancodes are different between 1.2 and 2.0

This bug report was migrated from our old Bugzilla tracker.

Reported in version: unspecified
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2020-12-23 02:10:12 +0000, Malte Kießling wrote:

So, the good old sdl 1.2 documentation states that scancodes are "best left alone".

Turns out that people didn't care. There is the issue now that dosbox (to give an example) is somewhat activly using scancodes (dosbox/src/gui_sdl_mapper.cpp:421; function called GetKeyCode). The bounds-checking is also only an assert, so this is a guaranteed crash.

I have "fixed" this by permanently setting the scancode of the key event to zero. I have no idea if that is an actual fix - who knows what else depends on the scancodes. Emulating old behaviour here is probalby preferable.

testalpha.c broken...

So this is what testalpha.c should look like:

2021-05-27_14-44

...this is what it does look like...

2021-05-27_14-43

The yellow on the first picture is where I've dragged the mouse (not rendering at all in sdl12-compat). The smiley face fades in and out, and that is working, but the bounding rectangle on that sprite is also fading to black, and that's the trail being left in the second shot; as it fades to black, that rectangle leaves damage on the background, lighter or darker depending on how much it has faded in and out at the moment.

CMakeLists.txt is missing some target link libraries

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: unspecified
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2019-11-24 02:22:52 +0000, Lyle wrote:

When I run ldd on my locally installed SDL 1.2 shared object file I get the following:

linux-vdso.so.1 (0x00007ffc557f7000)
libm.so.6 => /usr/lib/libm.so.6 (0x00007f2f0c219000)
libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f2f0c214000)
libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f2f0c1f2000)
libc.so.6 => /usr/lib/libc.so.6 (0x00007f2f0c02b000)
/usr/lib64/ld-linux-x86-64.so.2 (0x00007f2f0c44d000)

However, when using cmake to generate a Makefile, sdl12-compat does not get linked against all of these. This results in differences in regards to compiling applications which depend on them. A perfect example of this is the build of testsprite which occurs automatically and fails linking with undefined references to symbols which are found in libm and libdl. It looks like this:

testsprite.c:(.text+0x35b): undefined reference to `sin'
/usr/bin/ld: libSDL-1.2.so.1.2.50: undefined reference to `dlopen'
/usr/bin/ld: libSDL-1.2.so.1.2.50: undefined reference to `dlclose'
/usr/bin/ld: libSDL-1.2.so.1.2.50: undefined reference to `dlsym'

The same thing can be observed with the legacy Lazy Foo tutorials (which have require libdl). You can fix this by linking testsprite directly against libm and libdl, but this is not necessary when using vanilla SDL 1.2. That step is only necessary when using sdl12-compat. Therefor, these libraries should be linked against sdl12-compat to match the behavior. This can be accomplished by adding the following line immediately after line 4 in CMakeLists.txt:

target_link_libraries(SDL dl m)

This still does not include libpthread as can be seen in the original SDL shared object file as I have not yet seen evidence of misbehavior due to that and I am not yet familiar enough with the project to say for certain that it won't work correctly without it.

On 2020-12-22 21:47:19 +0000, Malte Kießling wrote:

Created attachment 4596
Give CMakeLists.txt a chance to find libs and add missing libs

Afaik, you should not need pthread, as threading should be handled by SDL.

Assuming that this should keep working in weird environments where Find_SDL, Find_X11 and the like are not available for whatever reason (cross compilation with borked roots come to mind), i have added a bit of code to try to find the include paths independent of that. This works for me, but YMMV.

If anyone knows a file that is exclusive to sdl1 (as SDL_haptic.h is for sdl2), this would make this a better try at finding the header. A generally better way than this would also be preferable.

~mkalte

On 2020-12-22 21:52:18 +0000, Malte Kießling wrote:

Created attachment 4597
Give CMakeLists.txt a chance to find libs and add missing libs

Oops, and of course, OP of this is right, linking should happen with the wrapper, not the test program. Sorry for the extra spam x.X

Port to Windows

This bug report was migrated from our old Bugzilla tracker.

Reported in version: unspecified
Reported for operating system, platform: Other, x86

Comments on the original bug report:

On 2019-03-13 19:45:13 +0000, Ryan C. Gordon wrote:

Most of the sdl12-compat code will work out of the box on Windows, but I probably need to sort out the SDL_main politics.

--ryan.

On 2019-03-14 17:13:16 +0000, Rohit Nirmal wrote:

A few notes:

  1. CloseSDL20Library() for _WINDOWS has an extra open bracket that causes compile errors.
  2. On MinGW, _WINDOWS is not defined, causing the #error to trigger.
  3. stdio.h needs to be #included for stderr.
  4. stdlib.h needs to be #included to avoid an implicit declaration warning for abort().
  5. On MinGW, SDL20_CreateMutex and SDL20_CreateSemaphore are undefined for some reason. As a quick fix, I changed them to SDL20_SYM from SDL20_SYM_PASSTHROUGH in SDL20_syms.h and created SDL_CreateMutex and SDL_CreateSemaphore functions in SDL12_compat.c to simply call them.

DOSBox rendering glitches with aspect=true and output=surface

DOSBox 0.74-3 has some very strange rendering issues when aspect ratio correction is enabled, the "surface" output system (SDL 1.2 Surfaces) is selected, and a video mode with non-square pixels is being emulated.

What appears to be happening is that full-screen updates (e.g., scrolling, palette updates, etc) are not being scaled to the correct aspect ratio, leaving a blank bar at the bottom of the screen. However, partial updates (moving sprites, menu item highlights, etc), are rendered with the correct aspect ratio, and so appear further down the screen, potentially leaving trails behind them.

Commander Keen 1 under DOSBox

I tested this on X11 and Wayland, it was easily reproducible on both. This issue is not reproducible with either the "opengl" or "overlay" (SDL 1.2 YUV overlay) output video systems, both of which seem to work perfectly under sdl12-compat. (The "ddraw" path relies pretty heavily on the hwdata field of SDL_Surface, so while I didn't test under windows, there's no realistic chance of it working.)

From a quick look at DOSBox's code, it seems to have a number of different ways it can render in "surface" mode, depending on whether the window surface is double buffered. On sdl12-compat on my systems, it uses its "blit" path, where it creates a surface and renders into that (interestingly, without locking the surface, but unlocking it afterwards), then SDL_BlitSurface()-ing it into the window surface, and calling SDL_Flip(). The non-blit path, on the other hand, locks the window surface directly and then uses either SDL_Flip() for full-screen updates and SDL_UpdateRects(), and this is the path which normal SDL 1.2 uses. It's possible that DOSBox on the "blit" codepath is just broken, of course…

macOS needs VERSION/SOVERSION set

I've tried testing sdl12-compat with DOSBox but just replacing the SDL 1.2x dylib is not possible because the reported compatibility version and current version (compatibility version 0.0.0, current version 0.0.0) do not match the original SDL 1.2x version linked to (compatibility version 12.0.0, current version 12.5.0).
Adding to the Apple properties in CMakeLists

        VERSION "12.50.0"
        SOVERSION "12.50.0"

worked for DOSBox and its dependencies SDL_Sound and SDL_Net.

I noticed that this is set to

        VERSION "1.2.50"
        SOVERSION "0"

for other platforms. Is that not so important on these or is the VERSION/SOVERSION handled differently on those than on Apple, so that the set number is so different?

Mac version not trying to load SDL2.framework

Mac version should first try loading SDL2.framework/Versions/A/SDL2
from ~/Library/Frameworks and /Library/Frameworks folders (is the
order correct?), and then try libSDL2-2.0.0.dylib if the framework
fails.

missing symbols left:

After the #30 and #8 patches are in, these are only three SDL-1.2
symbols missing in sdl12-compat: SDL_GL_Lock, SDL_GL_UpdateRects
and SDL_GL_Unlock.

I don't know whether they can ever be implemented.

macOS: Possible to link against the SDL2 framework or library instead of hardcoding the locations?

if sdl12-compat were linked against the SDL2 framework or dylib it would be much easier to manipulate the compat library with install_name_tool to point at the dynamic library in a bundle or a framework.

Right now it is semi hard coded. findSDL2 in the CMake finds my SDL2 dylib but once i start an app with the sdl12-compat replacement it only looks for the dynamic library in /usr/local/lib (and possibly the framework paths you coded in).

Another way to handle this could be to add a search for @loader_path/SDL20_LIBNAME (and maybe something like @loader_path/Frameworks/DL20_FRAMEWORK <- but that is probably too specific for the many ways people are bundling things) which should take care of all bundles that have all the libs in one folder.

SDL_SoftStretch

Below is a patch that implements SDL_SoftStretch() and fixes two gotchas:

  • SDL_UpperBlit: srcrect is a const ptr, so no need converting it back to
    SDL-1.2 format after SDL20_UpperBlit returns

  • SDL_LowerBlit: fix typo srcrect12 -> dstrect12

  • Implement SDL_SoftStretch(): seems exactly the same between 1.2 and 2.0.
    And, as far as I can see, it doesn't need save/restore destalpha.

Is the patch correct? OK to apply?

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 114aa5a..9ca3089 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -3330,10 +3330,6 @@ SDL_UpperBlit(SDL12_Surface *src12, SDL12_Rect *srcrect12, SDL12_Surface *dst12,
 
     RestoreDestAlpha(dst12, dstalpha);
 
-    if (srcrect12) {
-        Rect20to12(&srcrect20, srcrect12);
-    }
-
     if (dstrect12) {
         Rect20to12(&dstrect20, dstrect12);
     }
@@ -3363,7 +3359,7 @@ SDL_LowerBlit(SDL12_Surface *src12, SDL12_Rect *srcrect12, SDL12_Surface *dst12,
         Rect20to12(&srcrect20, srcrect12);
     }
 
-    if (srcrect12) {
+    if (dstrect12) {
         Rect20to12(&dstrect20, dstrect12);
     }
 
@@ -3371,6 +3367,16 @@ SDL_LowerBlit(SDL12_Surface *src12, SDL12_Rect *srcrect12, SDL12_Surface *dst12,
 }
 
 DECLSPEC int SDLCALL
+SDL_SoftStretch(SDL12_Surface *src12, SDL12_Rect *srcrect12, SDL12_Surface *dst12, SDL12_Rect *dstrect12)
+{
+    SDL_Rect srcrect20, dstrect20;
+    return SDL20_SoftStretch(src12->surface20,
+                             srcrect12 ? Rect12to20(srcrect12, &srcrect20) : NULL,
+                             dst12->surface20,
+                             dstrect12 ? Rect12to20(dstrect12, &dstrect20) : NULL);
+}
+
+DECLSPEC int SDLCALL
 SDL_SetAlpha(SDL12_Surface *surface12, Uint32 flags12, Uint8 value)
 {
     const SDL_bool addkey = (flags12 & SDL12_SRCALPHA) ? SDL_TRUE : SDL_FALSE;
diff --git a/src/SDL20_syms.h b/src/SDL20_syms.h
index 92aec50..4d76b49 100644
--- a/src/SDL20_syms.h
+++ b/src/SDL20_syms.h
@@ -96,6 +96,7 @@ SDL20_SYM(int,LockSurface,(SDL_Surface *a),(a),return)
 SDL20_SYM(void,UnlockSurface,(SDL_Surface *a),(a),)
 SDL20_SYM(int,UpperBlit,(SDL_Surface *a,const SDL_Rect *b,SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return)
 SDL20_SYM(int,LowerBlit,(SDL_Surface *a,const SDL_Rect *b,SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return)
+SDL20_SYM(int,SoftStretch,(SDL_Surface *a,const SDL_Rect *b,SDL_Surface *c,const SDL_Rect *d),(a,b,c,d),return)
 SDL20_SYM(SDL_bool,HasColorKey,(SDL_Surface *a),(a),return)
 SDL20_SYM(int,SetColorKey,(SDL_Surface *a, int b, Uint32 c),(a,b,c),return)
 SDL20_SYM(int,GetColorKey,(SDL_Surface *a, Uint32 *b),(a,b),return)
diff --git a/src/SDL20_include_wrapper.h b/src/SDL20_include_wrapper.h
index b3816a7..7098a39 100644
--- a/src/SDL20_include_wrapper.h
+++ b/src/SDL20_include_wrapper.h
@@ -88,6 +88,7 @@
 #define SDL_LoadWAV_RW IGNORE_THIS_VERSION_OF_SDL_LoadWAV_RW
 #define SDL_UpperBlit IGNORE_THIS_VERSION_OF_SDL_UpperBlit
 #define SDL_LowerBlit IGNORE_THIS_VERSION_OF_SDL_LowerBlit
+#define SDL_SoftStretch IGNORE_THIS_VERSION_OF_SDL_SoftStretch
 #define SDL_ConvertSurface IGNORE_THIS_VERSION_OF_SDL_ConvertSurface
 #define SDL_SetColorKey IGNORE_THIS_VERSION_OF_SDL_SetColorKey
 #define SDL_LockSurface IGNORE_THIS_VERSION_OF_SDL_LockSurface
@@ -191,6 +192,7 @@ typedef void (__cdecl *pfnSDL_CurrentEndThread) (unsigned);
 #undef SDL_LoadWAV_RW
 #undef SDL_UpperBlit
 #undef SDL_LowerBlit
+#undef SDL_SoftStretch
 #undef SDL_ConvertSurface
 #undef SDL_SetColorKey
 #undef SDL_LockSurface

Psychonauts "highlight" effect bleeds through objects with OpenGL Logical Scaling

In Psychonauts, the blue "highlight" effects appears in front of the object being highlighted when OpenGL Logical Scaling is enabled. With Logical Scaling disabled, it looks the same as it does on regular SDL 1.2. This happens with all objects in the game that are highlighted.

With Logical Scaling:
Incorrect

Without Logical Scaling:
Expected

These were taken in windowed mode with MSAA disabled, but also appear in fullscreen and with the MSAA patch in #61. The missing UI elements in the first image are expected: the game fades them away deliberately when they're not needed.

I checked the SDL_GL_SetAttribute() calls, and it looks like the game is trying to use a 24-bit depth buffer, which matches the hardcoded value in the Logical Scaling FBO, so I don't think a different depth precision is causing it (though I could be wrong). I haven't tried to debug it further, though…

Duke 3D runs too fast and doesn't show some screens

This bug report was migrated from our old Bugzilla tracker.

Reported in version: unspecified
Reported for operating system, platform: Linux, x86

Comments on the original bug report:

On 2019-03-18 21:38:16 +0000, Rohit Nirmal wrote:

I used the Duke 3D Linux binaries from duke3d_retail_bins_linux_x86.zip in the following directory: https://icculus.org/mojosetup/examples/duke3d/data/

Using sdl12-compat, the game runs too fast. Also, the 3D Realms logo screen (the one that says "Reality Is Our Game") appears as black. It appears normally with stock SDL 1.2.

On 2019-03-23 03:12:26 +0000, Ryan C. Gordon wrote:

The game speed is fixed in https://hg.libsdl.org/sdl12-compat/rev/911a1e7bf8b7 ...still have to look into the logo screen.

--ryan.

On 2019-04-04 03:37:58 +0000, Ryan C. Gordon wrote:

The 3D Realms logo is fixed in https://hg.libsdl.org/sdl12-compat/rev/dc55edfe5d2f, closing bug!

--ryan.

Software renderer issues:

When uhexen2 (http://uhexen2.sf.net/) is isrun in software renderer
mode, and the resoultion is not the desktop resolution:

  • Windowed mode is OK, that much is fine.

  • Alt-Enter toggling to fullscreen adjusts the drawable area, but
    the non-drawable area, i.e. the left and right sides of the screen
    are left not drawn, has desktop leftovers and flickers (e.g. with
    a 1024x768 game window, 1920x1080 desktop.)

  • Alt-Enter back to windowed mode: The drawable area is shifted to
    right, making the game unplayable: See the attached screenshot.

The issues seem to be related to SDL_WINDOW_FULLSCREEN_DESKTOP:
Using SDL_WINDOW_FULLSCREEN makes the issues go away.

Should we check that the game window resolution matches the desktop
before deciding to use SDL_WINDOW_FULLSCREEN_DESKTOP? Or a better
solution?
sshot

bad revcpy implementation

pointed out by kkofler 4c5e3b2#commitcomment-50963635

This implementation is incorrect. The point of SDL_revcpy (reverse copy) is to copy from the end to the start rather than from the start to the end as SDL_memcpy does, which matters in case the buffers are overlapping. Compare:
https://github.com/libsdl-org/SDL-1.2/blob/b8aa08c87e3f6e87bf918e1f2e26ebabe5f07122/src/stdlib/SDL_string.c#L320
vs.
https://github.com/libsdl-org/SDL-1.2/blob/b8aa08c87e3f6e87bf918e1f2e26ebabe5f07122/src/stdlib/SDL_string.c#L276

See also the difference between memcpy and memmove in the standard C library (except that memmove automatically detects the copy direction to use whereas SDL_revcpy requires you to manually choose between SDL_memcpy and SDL_revcpy). So you either have to copy the implementation of SDL_revcpy here or call SDL_memmove, not SDL_memcpy.

Note that this bug will lead to corruption of the memory area being moved, so it needs urgent fixing.

(Note that SDL_memmove is also subtly different in that it does not always reverse-copy, but auto-detects the safe direction to use. I am not sure whether that can be an issue in practice. But calling SDL_memcpy always does the wrong thing if SDL_revcpy is expected and will definitely break when used instead of SDL_revcpy on overlapping buffers.)

Lack of unicode support breaks keyboard input in some applications.

This bug report was migrated from our old Bugzilla tracker.

Reported in version: unspecified
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2019-11-24 01:51:19 +0000, Lyle wrote:

Some applications, such as the game Frozen Synapse and this legacy SDL tutorial from Lazy Foo http://www.lazyfoo.net/SDL_tutorials/lesson23/index.php pull keyboard input through event.key.keysym.unicode. Currently, this is always set to 0, which results in these applications failing to recognize any input. This occurs due to the following line in SDL12_compat.c:

event12.key.keysym.unicode = 0;  FIXME("unicode");

However, since the unicode character set is a superset of ASCII, we can provide partial functionality here very easily just by passing through the sym value. For example:

event12.key.keysym.unicode = event12.key.keysym.sym;

I'll admit that I don't know exactly what will happen here if someone does input a character which requires unicode support. However, I have verified that this change restores keyboard input functionality for me for the sign-in screen of the game Frozen Synapse as well as the above linked legacy Lazy Foo tutorial. Until such time that someone is prepared to fully implement the needed bits for unicode, I think this or something very much like it would be a change for the better.

[Feature Request] id's SDL_GL_DisableContext and SDL_GL_EnableContext_Thread functions

This bug report was migrated from our old Bugzilla tracker.

Reported in version: unspecified
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2019-03-13 18:14:43 +0000, REA wrote:

Greetings,

Some id Tech 4 games such as Quake 4 and Enemy Territory: Quake Wars use custom SDL functions named SDL_GL_DisableContext and SDL_GL_EnableContext_Thread to enable threaded renderer. As the patch available for those functions, can they be added into sdl12-compat, please? Thank you.

Patch:
https://github.com/liflg/etqw_1.5-multilingual_x86/blob/master/data/sdl.1.2.12.patch

Original library:
https://github.com/liflg/etqw_1.5-multilingual_x86/blob/master/data/libSDL-1.2.id.so.0

SDLCL and related topic:
MrAlert/sdlcl#14
https://github.com/MrAlert/sdlcl/

On 2019-03-22 14:55:09 +0000, Ryan C. Gordon wrote:

I added these in https://hg.libsdl.org/sdl12-compat/rev/ea2ce36617d5, but these are untested; please reopen this bug if I screwed this up. :)

--ryan.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.