Skip to content

Commit

Permalink
Added sdl+vitagl example
Browse files Browse the repository at this point in the history
  • Loading branch information
nikarh committed Jul 22, 2024
1 parent 7341fbe commit c869d90
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 3 deletions.
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
- 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
- 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: 1 addition & 1 deletion crates/3-sdl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ fn dummy_texture<'a>(
}

pub fn main() -> Result<(), String> {
let sdl_context = sdl2::init()?;
let sdl_context: sdl2::Sdl = sdl2::init()?;
let video_subsystem = sdl_context.video()?;

// Init controller
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,
};
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
}

0 comments on commit c869d90

Please sign in to comment.