Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sdl+vitagl example #5

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Northfear SDL fork
run: |
chown -R 1000:1000 northfear-sdl2
cd northfear-sdl2
sudo --preserve-env=VITASDK -u \#1000 vita-makepkg
vdpm sdl2-2.30.2-1-arm.tar.xz
nikarh marked this conversation as resolved.
Show resolved Hide resolved
- name: Build
run: |
cargo vita build vpk --release --package vita-std-tests --tests
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Northfear SDL fork
run: |
chown -R 1000:1000 northfear-sdl2
cd northfear-sdl2
sudo --preserve-env=VITASDK -u \#1000 vita-makepkg
vdpm sdl2-2.30.2-1-arm.tar.xz
nikarh marked this conversation as resolved.
Show resolved Hide resolved
- name: Build
run: |
cargo vita build vpk --release --package vita-std-tests --tests
Expand Down
44 changes: 44 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions crates/0-std-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(fs_try_exists)]

mod tests_fs;
mod tests_pthread;
mod tests_tcp;
Expand Down
6 changes: 3 additions & 3 deletions crates/0-std-tests/src/tests_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod tests {

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

assert!(
fs::try_exists("ux0:/data/.rust_test/file").unwrap(),
fs::exists("ux0:/data/.rust_test/file").unwrap(),
"file does not exist",
);

Expand All @@ -69,7 +69,7 @@ mod tests {

fs::remove_file("ux0:/data/.rust_test/file").expect("unable to delete file");
assert!(
!fs::try_exists("ux0:/data/.rust_test/file").unwrap(),
!fs::exists("ux0:/data/.rust_test/file").unwrap(),
"file exists, but should not",
);

Expand Down
13 changes: 13 additions & 0 deletions crates/3-sdl/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// These linker flags are only necessary with Northfear SDL2 fork
#[link(name = "SDL2", kind = "static")]
#[link(name = "vitaGL", kind = "static")]
#[link(name = "vitashark", kind = "static")]
#[link(name = "SceShaccCg_stub", kind = "static")]
#[link(name = "mathneon", kind = "static")]
#[link(name = "SceShaccCgExt", kind = "static")]
#[link(name = "taihen_stub", kind = "static")]
#[link(name = "SceKernelDmacMgr_stub", kind = "static")]
#[link(name = "SceIme_stub", kind = "static")]
extern "C" {}


use crate::game_of_life::{PLAYGROUND_HEIGHT, PLAYGROUND_WIDTH, SQUARE_SIZE};
use sdl2::keyboard::Keycode;
use sdl2::mouse::MouseButton;
Expand Down
2 changes: 0 additions & 2 deletions crates/4-vitasdk/src/debug/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pub struct DebugFont {
pub width: usize,
pub height: usize,
pub first: u8,
pub last: u8,
pub size_w: usize,
pub size_h: usize,
}
Expand All @@ -13,7 +12,6 @@ pub const DEBUG_FONT: DebugFont = DebugFont {
width: 8,
height: 8,
first: 0,
last: 255,
size_w: 8,
size_h: 8,
};
4 changes: 2 additions & 2 deletions crates/4-vitasdk/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::backtrace::Backtrace;
use std::fmt::Write;
use std::panic::{self, PanicInfo};
use std::panic::{self, PanicHookInfo};
use std::thread;
use std::time::Duration;

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

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

Expand Down
19 changes: 19 additions & 0 deletions crates/5-vitasdk-gles/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "vita-example-sdl-gles"
version = "0.1.0"
edition = "2021"

license = "MIT OR Apache-2.0"
repository = "https://github.com/vita-rust/examples"
homepage = "https://github.com/vita-rust/examples/crates/4-vitasdk"

description = "VITASDK example"

[dependencies]
rand = "0.8.5"
gl = "0.10.0"
sdl2 = { version = "0.35.2", features = ["use-pkgconfig"] }

[package.metadata.vita]
title_id = "RUSTTEST5"
title_name = "SDL+GL test"
43 changes: 43 additions & 0 deletions crates/5-vitasdk-gles/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#[link(name = "SDL2", kind = "static")]
#[link(name = "vitaGL", kind = "static")]
#[link(name = "vitashark", kind = "static")]
#[link(name = "SceShaccCg_stub", kind = "static")]
#[link(name = "mathneon", kind = "static")]
#[link(name = "SceShaccCgExt", kind = "static")]
#[link(name = "taihen_stub", kind = "static")]
#[link(name = "SceKernelDmacMgr_stub", kind = "static")]
#[link(name = "SceIme_stub", kind = "static")]
extern "C" {}

fn main() {
let sdl = sdl2::init().unwrap();
let video_subsystem = sdl.video().unwrap();
let window = video_subsystem
.window("Game", 900, 700)
.opengl()
.build()
.unwrap();

let _gl_context = window.gl_create_context().unwrap();
let _gl = gl::load_with(|s| video_subsystem.gl_get_proc_address(s) as *const std::os::raw::c_void);

unsafe {
gl::ClearColor(0.3, 0.3, 0.5, 1.0);
}

let mut event_pump = sdl.event_pump().unwrap();
'main: loop {
for event in event_pump.poll_iter() {
match event {
sdl2::event::Event::Quit {..} => break 'main,
_ => {},
}
}

unsafe {
gl::Clear(gl::COLOR_BUFFER_BIT);
}

window.gl_swap_window();
}
}
28 changes: 28 additions & 0 deletions northfear-sdl2/VITABUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
pkgname=sdl2
pkgver=2.30.2
pkgrel=1
gitrev=0867aceb28a493b489f54a3407a3b820b092206a
url='https://www.libsdl.org'
source=(
"https://github.com/Northfear/SDL/archive/${gitrev}.tar.gz"
)
sha256sums=(
SKIP
)

prepare() {
cd "SDL-${gitrev}"
}

build() {
cd "SDL-${gitrev}"
mkdir build && cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=$VITASDK/share/vita.toolchain.cmake -DCMAKE_INSTALL_PREFIX=$prefix -DCMAKE_BUILD_TYPE=Release -DSDL_TEST=OFF -DVIDEO_VITA_VGL=ON
make -j$(nproc)
}

package () {
cd "SDL-${gitrev}"
cd build
make DESTDIR=$pkgdir install
}
Loading