Skip to content

Commit 5ef9e08

Browse files
authored
Added sdl+vitagl example (#5)
1 parent 7341fbe commit 5ef9e08

File tree

12 files changed

+176
-9
lines changed

12 files changed

+176
-9
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ jobs:
1111
steps:
1212
- name: Checkout code
1313
uses: actions/checkout@v4
14+
- name: Install Northfear SDL fork
15+
run: |
16+
chown -R 1000:1000 northfear-sdl2
17+
cd northfear-sdl2
18+
sudo --preserve-env=VITASDK -u \#1000 vita-makepkg
19+
vdpm sdl2-*-arm.tar.xz
1420
- name: Build
1521
run: |
1622
cargo vita build vpk --release --package vita-std-tests --tests

.github/workflows/release.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ jobs:
1717
steps:
1818
- name: Checkout code
1919
uses: actions/checkout@v4
20+
- name: Install Northfear SDL fork
21+
run: |
22+
chown -R 1000:1000 northfear-sdl2
23+
cd northfear-sdl2
24+
sudo --preserve-env=VITASDK -u \#1000 vita-makepkg
25+
vdpm sdl2-*-arm.tar.xz
2026
- name: Build
2127
run: |
2228
cargo vita build vpk --release --package vita-std-tests --tests

Cargo.lock

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/0-std-tests/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(fs_try_exists)]
2-
31
mod tests_fs;
42
mod tests_pthread;
53
mod tests_tcp;

crates/0-std-tests/src/tests_fs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod tests {
66

77
impl Drop for FsScope {
88
fn drop(&mut self) {
9-
if fs::try_exists("ux0:/data/.rust_test").unwrap_or(false) {
9+
if fs::exists("ux0:/data/.rust_test").unwrap_or(false) {
1010
fs::remove_dir_all("ux0:/data/.rust_test").expect("unable to cleanup");
1111
}
1212
}
@@ -54,7 +54,7 @@ mod tests {
5454
assert!(&data == "contents", "invalid file contents");
5555

5656
assert!(
57-
fs::try_exists("ux0:/data/.rust_test/file").unwrap(),
57+
fs::exists("ux0:/data/.rust_test/file").unwrap(),
5858
"file does not exist",
5959
);
6060

@@ -69,7 +69,7 @@ mod tests {
6969

7070
fs::remove_file("ux0:/data/.rust_test/file").expect("unable to delete file");
7171
assert!(
72-
!fs::try_exists("ux0:/data/.rust_test/file").unwrap(),
72+
!fs::exists("ux0:/data/.rust_test/file").unwrap(),
7373
"file exists, but should not",
7474
);
7575

crates/3-sdl/src/main.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// These linker flags are only necessary with Northfear SDL2 fork
2+
#[link(name = "SDL2", kind = "static")]
3+
#[link(name = "vitaGL", kind = "static")]
4+
#[link(name = "vitashark", kind = "static")]
5+
#[link(name = "SceShaccCg_stub", kind = "static")]
6+
#[link(name = "mathneon", kind = "static")]
7+
#[link(name = "SceShaccCgExt", kind = "static")]
8+
#[link(name = "taihen_stub", kind = "static")]
9+
#[link(name = "SceKernelDmacMgr_stub", kind = "static")]
10+
#[link(name = "SceIme_stub", kind = "static")]
11+
extern "C" {}
12+
13+
114
use crate::game_of_life::{PLAYGROUND_HEIGHT, PLAYGROUND_WIDTH, SQUARE_SIZE};
215
use sdl2::keyboard::Keycode;
316
use sdl2::mouse::MouseButton;

crates/4-vitasdk/src/debug/font.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pub struct DebugFont {
33
pub width: usize,
44
pub height: usize,
55
pub first: u8,
6-
pub last: u8,
76
pub size_w: usize,
87
pub size_h: usize,
98
}
@@ -13,7 +12,6 @@ pub const DEBUG_FONT: DebugFont = DebugFont {
1312
width: 8,
1413
height: 8,
1514
first: 0,
16-
last: 255,
1715
size_w: 8,
1816
size_h: 8,
1917
};

crates/4-vitasdk/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::backtrace::Backtrace;
22
use std::fmt::Write;
3-
use std::panic::{self, PanicInfo};
3+
use std::panic::{self, PanicHookInfo};
44
use std::thread;
55
use std::time::Duration;
66

@@ -25,7 +25,7 @@ pub fn main() {
2525
thread::sleep(Duration::from_secs(5));
2626
}
2727

28-
fn custom_panic_hook(info: &PanicInfo<'_>) {
28+
fn custom_panic_hook(info: &PanicHookInfo<'_>) {
2929
// The current implementation always returns `Some`.
3030
let location = info.location().unwrap();
3131

crates/5-vitasdk-gles/Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "vita-example-sdl-gles"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
license = "MIT OR Apache-2.0"
7+
repository = "https://github.com/vita-rust/examples"
8+
homepage = "https://github.com/vita-rust/examples/crates/4-vitasdk"
9+
10+
description = "VITASDK example"
11+
12+
[dependencies]
13+
rand = "0.8.5"
14+
gl = "0.10.0"
15+
sdl2 = { version = "0.35.2", features = ["use-pkgconfig"] }
16+
17+
[package.metadata.vita]
18+
title_id = "RUSTTEST5"
19+
title_name = "SDL+GL test"

crates/5-vitasdk-gles/src/main.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#[link(name = "SDL2", kind = "static")]
2+
#[link(name = "vitaGL", kind = "static")]
3+
#[link(name = "vitashark", kind = "static")]
4+
#[link(name = "SceShaccCg_stub", kind = "static")]
5+
#[link(name = "mathneon", kind = "static")]
6+
#[link(name = "SceShaccCgExt", kind = "static")]
7+
#[link(name = "taihen_stub", kind = "static")]
8+
#[link(name = "SceKernelDmacMgr_stub", kind = "static")]
9+
#[link(name = "SceIme_stub", kind = "static")]
10+
extern "C" {}
11+
12+
fn main() {
13+
let sdl = sdl2::init().unwrap();
14+
let video_subsystem = sdl.video().unwrap();
15+
let window = video_subsystem
16+
.window("Game", 900, 700)
17+
.opengl()
18+
.build()
19+
.unwrap();
20+
21+
let _gl_context = window.gl_create_context().unwrap();
22+
let _gl = gl::load_with(|s| video_subsystem.gl_get_proc_address(s) as *const std::os::raw::c_void);
23+
24+
unsafe {
25+
gl::ClearColor(0.3, 0.3, 0.5, 1.0);
26+
}
27+
28+
let mut event_pump = sdl.event_pump().unwrap();
29+
'main: loop {
30+
for event in event_pump.poll_iter() {
31+
match event {
32+
sdl2::event::Event::Quit {..} => break 'main,
33+
_ => {},
34+
}
35+
}
36+
37+
unsafe {
38+
gl::Clear(gl::COLOR_BUFFER_BIT);
39+
}
40+
41+
window.gl_swap_window();
42+
}
43+
}

northfear-sdl2/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
src
2+
pkg
3+
*gz
4+
*xz

northfear-sdl2/VITABUILD

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
pkgname=sdl2
2+
pkgver=2.24.0
3+
pkgrel=1
4+
gitrev=0867aceb28a493b489f54a3407a3b820b092206a
5+
url='https://www.libsdl.org'
6+
source=(
7+
"https://github.com/Northfear/SDL/archive/${gitrev}.tar.gz"
8+
)
9+
sha256sums=(
10+
SKIP
11+
)
12+
13+
pkgver() {
14+
cd "SDL-${gitrev}"
15+
ref_major=$(sed -ne 's/^#define SDL_MAJOR_VERSION *//p' include/SDL_version.h)
16+
ref_minor=$(sed -ne 's/^#define SDL_MINOR_VERSION *//p' include/SDL_version.h)
17+
ref_micro=$(sed -ne 's/^#define SDL_PATCHLEVEL *//p' include/SDL_version.h)
18+
echo "${ref_major}.${ref_minor}.${ref_micro}"
19+
}
20+
21+
prepare() {
22+
cd "SDL-${gitrev}"
23+
}
24+
25+
build() {
26+
cd "SDL-${gitrev}"
27+
rm -rf build; mkdir build && cd build
28+
cmake .. -DCMAKE_TOOLCHAIN_FILE=$VITASDK/share/vita.toolchain.cmake -DCMAKE_INSTALL_PREFIX=$prefix -DCMAKE_BUILD_TYPE=Release -DSDL_TEST=OFF -DVIDEO_VITA_VGL=ON
29+
make -j$(nproc)
30+
}
31+
32+
package () {
33+
cd "SDL-${gitrev}"
34+
cd build
35+
make DESTDIR=$pkgdir install
36+
}

0 commit comments

Comments
 (0)