sdl
sdl
The module strives to support 100% of the SDL2 API.
So, among many other things, you can:
- Open windows and accelerated rendering contexts
- Render basic 2D graphics
- Handle input events from keyboards, touches, mice, gamepads and joysticks
- Play audio, sound effects and music
Install
If you want to use SDL2
v2.0.8
v install sdl
If you want to use another version of SDL2 you will, currently, have to install
it via
git
An example of installing the system provided version of SDL2 via
git
git clone https://github.com/vlang/sdl.git ~/.vmodules/sdl
v ~/.vmodules/sdl/setup.vsh
Should
sdl2-config
An example of installing SDL2
v2.0.12
git
git clone https://github.com/vlang/sdl.git ~/.vmodules/sdl
cd ~/.vmodules/sdl
git checkout 2.0.12
and for Windows:
git clone https://github.com/vlang/sdl.git %HOMEPATH%/.vmodules/sdl
cd %HOMEPATH%/.vmodules/sdl
git checkout 2.0.12
Then follow the steps in the
Windows
You can see what
sdl
Also note that you'll need the SDL2 libraries available on your system
see the
Dependencies
Version notes
SDL2
v2.0.8
v2.0.8
Also note that SDL2
is not
v1.x
Notes on garbage collection and memory issues
Currently, with some setups, SDL2 is known to trigger crashes when used in conjunction
with V's default garbage collector. In these cases running apps importing
sdl
v run
main__main: RUNTIME ERROR: invalid memory access
We are tracking the issue here: https://github.com/vlang/sdl/issues/744
The crashes can be avoided by passing
-d sdl_memory_no_gc
import sdl
destroy
sdl.free/1
Support
sdl
- Linux
- MacOS (via
homebrew
) - Windows
Examples
You can run the tVintris example like this :
v run sdl/examples/tvintris/tvintris.v
Dependencies
Linux
Fedora
sudo dnf install SDL2-devel SDL2_ttf-devel SDL2_mixer-devel SDL2_image-devel
Ubuntu
sudo apt install libsdl2-ttf-dev libsdl2-mixer-dev libsdl2-image-dev
Arch
sudo pacman -S sdl2 sdl2_image sdl2_mixer sdl2_ttf
ClearLinux
sudo swupd bundle-add devpkg-SDL2_ttf devpkg-SDL2_mixer devpkg-SDL2_image
MacOS
Brew
brew install sdl2 sdl2_gfx sdl2_ttf sdl2_mixer sdl2_image sdl2_net
If you get no music with the above, try:
brew reinstall --build-from-source --force sdl2 sdl2_gfx sdl2_image sdl2_mixer sdl2_net sdl2_ttf webp libtiff libmodplug libogg
Windows
It is necessary to install the sdl2 development libraries for Windows.
To do this, change to the root directory of the sdl module, like
cd %HOMEPATH%\.vmodules\sdl
v run windows_install_dependencies.vsh
copy thirdparty\SDL2-2.0.8\lib\x64\SDL2.dll examples\basic_window\
cd ..
v run sdl\examples\basic_window\main.v
Contributions
- nsauzede
- spytheman
- adlesh
- Larpon