kmamal / node-sdl

🎮 SDL bindings for Node.js
https://www.npmjs.com/package/@kmamal/sdl
MIT License
120 stars 10 forks source link

Add support for wsl #33

Closed ckir closed 10 months ago

ckir commented 1 year ago

Running the "Hello, World!" example from within my wsl Ubuntu 22.04.2 console I get:

resize { width: 640, height: 480, type: 'resize' }
expose { type: 'expose' }
show { type: 'show' }

but no window :) No problem when running it outside wsl.

kmamal commented 1 year ago

@ckir that's interesting. I just got access to a Windows system with wsl and tried it myself an it worked fine. The microsoft docs also say that X11 forwarding should work automatically. Can you paste what you get when you do console.log(sdl.info) inside wsl?

kmamal commented 1 year ago

Also as a second test, try creating a window with the accelerated: false flag set like so:

sdl.video.createWindow({ accelerated: false })
ckir commented 1 year ago

@kmamal Running this

import sdl from '@kmamal/sdl'

const window = sdl.video.createWindow({ title: "Hello, World!" })
console.log(sdl.info)
window.on('*', console.log)

I get

{
  version: {
    compile: { major: 2, minor: 26, patch: 4 },
    runtime: { major: 2, minor: 26, patch: 4 }
  },
  platform: 'Linux',
  drivers: {
    video: { all: [Array], current: 'wayland' },
    audio: { all: [Array], current: 'alsa' }
  }
}
resize { width: 640, height: 480, type: 'resize' }
expose { type: 'expose' }
show { type: 'show' }

but no window

ckir commented 1 year ago

@kmamal Running this

import sdl from '@kmamal/sdl'

const window = sdl.video.createWindow({ title: "Hello, World!", accelerated: false })
console.log(sdl.info)
window.on('*', console.log)

I get

/home/user/DEVELOPMENT/tests/test_kmamal-sdl/node_modules/@kmamal/sdl/src/javascript/video/window.js:92
                const result = Bindings.window_create(
                                        ^

Error: SDL_CreateRenderer(1, 1) error: Couldn't find matching render driver

    at new Window (/home/user/DEVELOPMENT/tests/test_kmamal-sdl/node_modules/@kmamal/sdl/src/javascript/video/window.js:92:27)
    at Object.createWindow (/home/user/DEVELOPMENT/tests/test_kmamal-sdl/node_modules/@kmamal/sdl/src/javascript/video/index.js:19:29)
    at file:///home/user/DEVELOPMENT/tests/test_kmamal-sdl/test01.mjs:3:26
    at ModuleJob.run (node:internal/modules/esm/module_job:192:25)
kmamal commented 1 year ago

@ckir Alright, it looks like you are using Wayland. Can you tell me how to enable that in wsl so I can try it? My wsl ubuntu system is using X11 so that 's probably why it works for me. Also what happens if you launch the example with the SDL_VIDEODRIVER variable set like: SDL_VIDEODRIVER=x11 node index.js

ckir commented 1 year ago

@kmamal Starting it with SDL_VIDEODRIVER=x11 gives me

                const result = Bindings.window_create(
                                        ^

Error: SDL_CreateWindow() error: x11 not available

with and without accelerated: false

kmamal commented 1 year ago

@ckir Right, I get the same thing when I try SDL_VIDEODRIVER=wayland on my system. Have you modified the default ubuntu instalation somehow to get it to use wayland? Or did it come like that out of the box?

ckir commented 1 year ago

@kmamal Out of the box. Looking at my env looks like this

SHELL=/bin/bash
LIBGL_ALWAYS_INDIRECT=1
NVM_INC=/home/user/.nvm/versions/node/v20.1.0/include/node
WSL2_GUI_APPS_ENABLED=1
WSL_DISTRO_NAME=Ubuntu-22.04
CNN_FEARANDGREEDURL=https://script.google.com/macros/s/AKfycbwbN-NBmazuxiLwnVdUYXX66FtbV2HefP5pMtnw724ekA1DlyTsltS-_rH0k5Chs_z7/exec
NAME=W1121H2
PWD=/home/user/DEVELOPMENT/tests/test_kmamal-sdl
LOGNAME=user
HOME=/home/user
LANG=C.UTF-8
WSL_INTEROP=/run/WSL/12508_interop
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
WAYLAND_DISPLAY=wayland-0
NVM_DIR=/home/user/.nvm
LESSCLOSE=/usr/bin/lesspipe %s %s
TERM=xterm-256color
LESSOPEN=| /usr/bin/lesspipe %s
USER=user
DISPLAY=192.168.1.1:0.0                                        <- this one is required for many X programs to work
SHLVL=1
NVM_CD_FLAGS=
XDG_RUNTIME_DIR=/mnt/wslg/runtime-dir
ckir commented 1 year ago

@kmamal Good news. I just tried to start it like DISPLAY=:0 node ... and it works :)

kmamal commented 1 year ago

@ckir that's good to hear. I'm still kanda weirded out by this issue though. It's most likely something wrong with WSLg, but I can't point to what exactly. Are you maybe on an older version? Could you maybe post the output from wsl --version and (if you dare) see if wsl --update changes anything. Other than that I thing I'm going to stop digging for now.

ckir commented 1 year ago

@kmamal Wait. There is more. The second example (the canvas one) does not start when using DISPLAY=:0 but it starts without it. Another strange think is the appearance of the opened window is different. canvas

ckir commented 1 year ago

@kmamal

wsl --version
WSL version: 1.2.5.0
Kernel version: 5.15.90.1
WSLg version: 1.0.51
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22000.1936
ckir commented 1 year ago

@kmamal

PS C:\Windows> wsl --update
Checking for updates.
The most recent version of Windows Subsystem for Linux is already installed.
ckir commented 1 year ago

@kmamal Sorry, please ignore my comment above regarging the windows appearance. I was keen to run the tests and I forgot to read the code :)