Skip to content

Commit 16290fe

Browse files
authored
Use SDL3 (#6)
* sdl3 * sdl3 * WIP * bindgen * WIP * update sdl3
1 parent 872f52c commit 16290fe

11 files changed

+121
-94
lines changed

.cargo/config.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[env]
2+
# use pipewire for audio
3+
SDL_AUDIODRIVER = "pipewire"

.gitignore

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
.*
2-
!.gitignore
3-
4-
target/
1+
.vscode/
2+
target/

Cargo.lock

+16-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
[package]
22
name = "projectm_sdl"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55
rust-version = "1.68.2"
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
1010
libc = "*"
11-
sdl2 = "0.35"
12-
projectm-rs = "1.0.5"
13-
# projectm-rs = { path = "../projectm-rs" }
14-
#projectm-rs = { git = "https://github.com/projectM-visualizer/projectm-rs" }
11+
projectm = "1.0.5"
12+
# projectm = { path = "../projectm-rs" }
13+
#projectm = { git = "https://github.com/projectM-visualizer/projectm" }
14+
# sdl3 = { git = "https://github.com/revmischa/sdl3-rs.git", features = ["use-bindgen"] }
15+
sdl3 = "0.5.0"
16+
# sdl3 = { path = "../../sdl3-rs" }
1517

1618
# gl = "0.14.0"
1719

1820
[features]
21+
static-link = ["sdl3/static-link"]
1922
dummy_audio = []

README.md

+29-27
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
<br />
1212

13-
<h3 align="center">Frontend-SDL2-Rust</h3>
13+
<h3 align="center">ProjectM</h3>
1414

1515
<p align="center">
16-
Example rust app, utilizing the <a href="https://crates.io/crates/projectm-rs" target="_blank">projectM</a> crate
16+
Reference projectM application in Rust, utilizing the <a href="https://crates.io/crates/projectm" target="_blank">projectM</a> crate
1717
<br />
1818
<br />
19-
<a href="https://github.com/projectM-visualizer/frontend-sdl2-rust/issues" target="_blank">Report Bug</a>
19+
<a href="https://github.com/projectM-visualizer/frontend-sdl-rust/issues" target="_blank">Report Bug</a>
2020
·
21-
<a href="https://github.com/projectM-visualizer/frontend-sdl2-rust/issues" target="_blank">Request Feature</a>
21+
<a href="https://github.com/projectM-visualizer/frontend-sdl-rust/issues" target="_blank">Request Feature</a>
2222
</p>
2323
</div>
2424

@@ -45,6 +45,7 @@
4545
<br />
4646

4747
<!-- GETTING STARTED -->
48+
4849
## Getting Started
4950

5051
To get this crate up and running properly, you'll need to install some prerequisites.
@@ -56,29 +57,29 @@ development files. To build projectM, both binaries and development files need t
5657

5758
#### General build dependencies for all platforms:
5859

59-
* [**Rust**](https://www.rust-lang.org/tools/install)
60-
* A working build toolchain.
61-
* [**CMake**](https://cmake.org/): Used to generate platform-specific build files.
62-
* **OpenGL**: 3D graphics library. Used to render the visualizations.
63-
* or **GLES3**: OpenGL libraries for embedded systems, version 3. Required to build projectM on Android devices,
60+
- [**Rust**](https://www.rust-lang.org/tools/install)
61+
- A working build toolchain.
62+
- [**CMake**](https://cmake.org/): Used to generate platform-specific build files.
63+
- **OpenGL**: 3D graphics library. Used to render the visualizations.
64+
- or **GLES3**: OpenGL libraries for embedded systems, version 3. Required to build projectM on Android devices,
6465
Raspberry Pi, Emscripten and the Universal Windows Platform.
65-
* [**glm**](https://github.com/g-truc/glm): OpenGL Mathematics library. Optional, will use a bundled version with
66+
- [**glm**](https://github.com/g-truc/glm): OpenGL Mathematics library. Optional, will use a bundled version with
6667
autotools or if not installed.
67-
* [**SDL2**](https://github.com/libsdl-org/SDL): Simple Directmedia Layer. Version 2.0.5 or higher is required to build
68+
- [**SDL3**](https://github.com/libsdl-org/SDL): Simple Directmedia Layer >= 3. Provided by sdl3-rs.
6869
the test UI.
69-
* [**LLVM**](https://llvm.org/): Low-Level Virtual Machine. Optional and **experimental**, used to speed up preset
70+
- [**LLVM**](https://llvm.org/): Low-Level Virtual Machine. Optional and **experimental**, used to speed up preset
7071
execution by leveraging the LLVM JIT compiler.
7172

7273
#### Only relevant for Windows:
7374

74-
* [**vcpkg**](https://github.com/microsoft/vcpkg): C++ Library Manager for Windows. _Optional_, but recommended to
75+
- [**vcpkg**](https://github.com/microsoft/vcpkg): C++ Library Manager for Windows. _Optional_, but recommended to
7576
install the aforementioned library dependencies.
76-
* [**GLEW**](http://glew.sourceforge.net/): The OpenGL Extension Wrangler Library. Only required if using CMake to
77-
configure the build, the pre-created solutions use a bundled copy of GLEW.
77+
- [**GLEW**](http://glew.sourceforge.net/): The OpenGL Extension Wrangler Library. Only required if using CMake to
78+
configure the build, the pre-created solutions use a bundled copy of GLEW.
7879
<p align="right">(<a href="#readme-top">back to top</a>)</p>
7980

80-
8181
<!-- USAGE EXAMPLES -->
82+
8283
## Usage
8384

8485
```
@@ -92,8 +93,8 @@ cargo build
9293
### If using SDL installed via Homebrew
9394

9495
```
95-
RUSTFLAGS="-L$(brew --prefix sdl2)/lib" cargo build
96-
RUSTFLAGS="-L$(brew --prefix sdl2)/lib" cargo run
96+
RUSTFLAGS="-L$(brew --prefix sdl3)/lib" cargo build
97+
RUSTFLAGS="-L$(brew --prefix sdl3)/lib" cargo run
9798
```
9899

99100
### Optimized build
@@ -104,9 +105,8 @@ cargo run --release
104105

105106
<p align="right">(<a href="#readme-top">back to top</a>)</p>
106107

107-
108-
109108
<!-- CONTRIBUTING -->
109+
110110
## Contributing
111111

112112
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
@@ -122,23 +122,24 @@ Don't forget to give the project a star! Thanks again!
122122

123123
<p align="right">(<a href="#readme-top">back to top</a>)</p>
124124

125-
126-
127125
<!-- LICENSE -->
126+
128127
## License
129128

130129
Distributed under the LGPL-2.1 license. See `LICENSE` for more information.
131130

132131
<p align="right">(<a href="#readme-top">back to top</a>)</p>
133132

134133
<!-- SUPPORT -->
134+
135135
## Support
136136

137137
[![Discord][discord-shield]][discord-url]
138138

139139
<p align="right">(<a href="#readme-top">back to top</a>)</p>
140140

141141
<!-- CONTACT -->
142+
142143
## Contact
143144

144145
Blaquewithaq (Discord: SoFloppy#1289) - [@anomievision](https://twitter.com/anomievision) - [email protected]
@@ -147,16 +148,17 @@ Blaquewithaq (Discord: SoFloppy#1289) - [@anomievision](https://twitter.com/anom
147148

148149
<!-- MARKDOWN LINKS & IMAGES -->
149150
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
151+
150152
[contributors-shield]: https://img.shields.io/github/contributors/projectM-visualizer/projectm-rs.svg?style=for-the-badge
151-
[contributors-url]: https://github.com/projectM-visualizer/frontend-sdl2-rust/graphs/contributors
153+
[contributors-url]: https://github.com/projectM-visualizer/frontend-sdl-rust/graphs/contributors
152154
[forks-shield]: https://img.shields.io/github/forks/projectM-visualizer/projectm-rs.svg?style=for-the-badge
153-
[forks-url]: https://github.com/projectM-visualizer/frontend-sdl2-rust/network/members
155+
[forks-url]: https://github.com/projectM-visualizer/frontend-sdl-rust/network/members
154156
[stars-shield]: https://img.shields.io/github/stars/projectM-visualizer/projectm-rs.svg?style=for-the-badge
155-
[stars-url]: https://github.com/projectM-visualizer/frontend-sdl2-rust/stargazers
157+
[stars-url]: https://github.com/projectM-visualizer/frontend-sdl-rust/stargazers
156158
[issues-shield]: https://img.shields.io/github/issues/projectM-visualizer/projectm-rs.svg?style=for-the-badge
157-
[issues-url]: https://github.com/projectM-visualizer/frontend-sdl2-rust/issues
159+
[issues-url]: https://github.com/projectM-visualizer/frontend-sdl-rust/issues
158160
[license-shield]: https://img.shields.io/github/license/projectM-visualizer/projectm-rs.svg?style=for-the-badge
159-
[license-url]: https://github.com/projectM-visualizer/frontend-sdl2-rust/blob/master/LICENSE
161+
[license-url]: https://github.com/projectM-visualizer/frontend-sdl-rust/blob/master/LICENSE
160162
[crates-shield]: https://img.shields.io/crates/v/projectm-rs?style=for-the-badge
161163
[crates-url]: https://crates.io/crates/projectm-rs
162164
[crates-dl-shield]: https://img.shields.io/crates/d/projectm-rs?style=for-the-badge

src/app.rs

+27-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::sync::{Arc, Mutex};
22

3-
use projectm_rs::core::{ProjectMHandle, Projectm};
4-
use sdl2::video::GLProfile;
3+
use projectm::core::{ProjectMHandle, Projectm};
4+
use sdl3::video::GLProfile;
55

66
pub mod audio;
77
pub mod config;
@@ -15,12 +15,12 @@ pub type ProjectMWrapped = Arc<Mutex<ProjectMHandle>>;
1515
/// Application state
1616
pub struct App {
1717
pm: ProjectMWrapped,
18-
playlist: projectm_rs::playlist::Playlist,
19-
sdl_context: sdl2::Sdl,
20-
window: sdl2::video::Window,
18+
playlist: projectm::playlist::Playlist,
19+
sdl_context: sdl3::Sdl,
20+
window: sdl3::video::Window,
2121
config: config::Config,
2222
audio: audio::Audio,
23-
_gl_context: sdl2::video::GLContext,
23+
_gl_context: sdl3::video::GLContext,
2424
}
2525

2626
pub fn default_config() -> config::Config {
@@ -30,7 +30,13 @@ pub fn default_config() -> config::Config {
3030
impl App {
3131
pub fn new(config: Option<crate::app::config::Config>) -> Self {
3232
// setup sdl
33-
let sdl_context = sdl2::init().unwrap();
33+
let sdl_context = sdl3::init().unwrap();
34+
// print SDL version
35+
let version = sdl3::version::version();
36+
println!(
37+
"SDL version: {}.{}.{}",
38+
version.major, version.minor, version.patch
39+
);
3440
let video_subsystem = sdl_context.video().unwrap();
3541

3642
// request GL version
@@ -45,14 +51,22 @@ impl App {
4551
// create window
4652
// get screen dimensions
4753
let display_index = 0;
48-
let display_mode = video_subsystem.desktop_display_mode(display_index).unwrap();
49-
let window_width = display_mode.w as u32;
50-
let window_height = display_mode.h as u32;
54+
let driver = video_subsystem.current_video_driver();
55+
println!("Using video driver: {}", driver);
56+
let display_id = video_subsystem.get_primary_display_id();
57+
let display_mode = video_subsystem.current_display_mode(display_id).unwrap();
58+
let window_width = 100; // display_mode.w as u32;
59+
let window_height = 100; // display_mode.h as u32;
60+
println!(
61+
"Display {} is {}x{}",
62+
display_index, window_width, window_height
63+
);
5164
let window = video_subsystem
5265
.window("ProjectM", window_width, window_height)
5366
.opengl()
67+
.maximized()
5468
.position_centered()
55-
.allow_highdpi()
69+
// .allow_highdpi()
5670
.build()
5771
.expect("could not initialize video subsystem");
5872

@@ -64,10 +78,10 @@ impl App {
6478
let pm = Projectm::create();
6579

6680
// and a preset playlist
67-
let playlist = projectm_rs::playlist::Playlist::create(pm);
81+
let playlist = projectm::playlist::Playlist::create(pm);
6882

6983
// get/set window size
70-
let (width, height) = window.drawable_size(); // highDPI aware
84+
let (width, height) = window.size(); // TODO: need high DPI support here https://github.com/libsdl-org/SDL/issues/7134
7185
Projectm::set_window_size(pm, width.try_into().unwrap(), height.try_into().unwrap());
7286

7387
// create a mutex to protect the projectM instance

0 commit comments

Comments
 (0)