spinning cube (from rust-for-dreamcast examples)
This commit is contained in:
parent
ed96599058
commit
c578379890
5 changed files with 242 additions and 12 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
/target
|
||||||
|
/build
|
||||||
|
/disk
|
||||||
|
cake.cdi
|
|
@ -2,6 +2,7 @@
|
||||||
name = "dccake"
|
name = "dccake"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
build = "src/build.rs"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
|
|
18
Justfile
18
Justfile
|
@ -1,17 +1,19 @@
|
||||||
BUILD:="build"
|
BUILD:="disk"
|
||||||
PROJECT_NAME:="cake"
|
PROJECT_NAME:="cake"
|
||||||
TARGET:="target/sh-elf/release/dccake.elf"
|
TARGET:="target/sh-elf/release/dccake.elf"
|
||||||
|
|
||||||
logo:
|
logo:
|
||||||
convert cake.png -resize 256x256 cakes.png
|
mkdir -p build
|
||||||
convert cakes.png +dither -colors 127 cakec.png
|
convert assets/cake.png -resize 320x90 build/cakes.png
|
||||||
|
convert build/cakes.png +dither -colors 127 build/cakec.png
|
||||||
|
|
||||||
build: logo
|
build: logo
|
||||||
kos-cargo build --release
|
kos-cargo build --release
|
||||||
sh-elf-objcopy -R .stack -O binary {{TARGET}} output.bin
|
sh-elf-objcopy -R .stack -O binary {{TARGET}} build/output.bin
|
||||||
$KOS_BASE/utils/scramble/scramble output.bin {{BUILD}}/1ST_READ.bin
|
|
||||||
mkdir -p {{BUILD}}
|
mkdir -p {{BUILD}}
|
||||||
|
mkdir -p build
|
||||||
|
$KOS_BASE/utils/scramble/scramble build/output.bin {{BUILD}}/1ST_READ.bin
|
||||||
rm {{BUILD}}/IP.BIN || true
|
rm {{BUILD}}/IP.BIN || true
|
||||||
makeip ip.txt -l /tmp/cakec.png {{BUILD}}/IP.BIN
|
makeip ip.txt -l build/cakec.png {{BUILD}}/IP.BIN
|
||||||
mkisofs -C 0,11702 -V {{PROJECT_NAME}} -G {{BUILD}}/IP.BIN -r -J -l -o {{PROJECT_NAME}}.iso {{BUILD}}
|
mkisofs -C 0,11702 -V {{PROJECT_NAME}} -G {{BUILD}}/IP.BIN -r -J -l -o build/{{PROJECT_NAME}}.iso {{BUILD}}
|
||||||
cdi4dc {{PROJECT_NAME}}.iso {{PROJECT_NAME}}.cdi
|
cdi4dc build/{{PROJECT_NAME}}.iso {{PROJECT_NAME}}.cdi
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
generate_textures(vec!["tex_claw", "tex_dc", "tex_dcwiki", "tex_gcc", "tex_kos", "tex_rust"]);
|
generate_textures(vec!["caketops", "exterior", "interiors", "slices"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_textures(names: Vec<&str>) {
|
fn generate_textures(names: Vec<&str>) {
|
||||||
let vqenc_cmd = format!("{}/utils/vqenc/vqenc", std::env::var("KOS_BASE").unwrap());
|
let vqenc_cmd = format!("{}/utils/vqenc/vqenc", std::env::var("KOS_BASE").unwrap());
|
||||||
|
|
||||||
for texname in names {
|
for texname in names {
|
||||||
let jpgfile = format!("rsrc/{}.jpg", texname);
|
let jpgfile = format!("assets/{}.jpg", texname);
|
||||||
let vqfile = format!("rsrc/{}.vq", texname);
|
let vqfile = format!("assets/{}.vq", texname);
|
||||||
let outfile = format!("{}/{}.vq", std::env::var("OUT_DIR").unwrap(), texname);
|
let outfile = format!("{}/{}.vq", std::env::var("OUT_DIR").unwrap(), texname);
|
||||||
std::process::Command::new(&vqenc_cmd)
|
std::process::Command::new(&vqenc_cmd)
|
||||||
.args(["-t", "-v", &jpgfile])
|
.args(["-t", "-v", &jpgfile])
|
225
src/main.rs
225
src/main.rs
|
@ -1,3 +1,226 @@
|
||||||
|
use kos::ffi::{
|
||||||
|
dc::maple,
|
||||||
|
MAPLE_FOREACH,
|
||||||
|
};
|
||||||
|
use gldc::{
|
||||||
|
gl::*, glext::*, glkos::*, glu::*,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Include texture data generated by build script
|
||||||
|
static CLAW_DATA: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/exterior.vq"));
|
||||||
|
static DC_DATA: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/exterior.vq"));
|
||||||
|
static DCWIKI_DATA: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/exterior.vq"));
|
||||||
|
static GCC_DATA: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/interiors.vq"));
|
||||||
|
static KOS_DATA: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/caketops.vq"));
|
||||||
|
static RUST_DATA: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/slices.vq"));
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
unsafe {
|
||||||
|
// Initialize GLdc
|
||||||
|
glKosInit();
|
||||||
|
|
||||||
|
// Say hello to the world!
|
||||||
|
println!("\nHello, world from Rust! - gldc-cube example");
|
||||||
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
gluPerspective(45.0, 640.0 / 480.0, 0.1, 100.0);
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glLoadIdentity();
|
||||||
|
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
glShadeModel(GL_SMOOTH);
|
||||||
|
glClearColor(0.0, 0.0, 0.0, 0.5);
|
||||||
|
glClearDepth(1.0);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
|
||||||
|
let mut tex_claw: u32 = 0;
|
||||||
|
glGenTextures(1, &mut tex_claw);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex_claw);
|
||||||
|
glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_565_VQ_TWID_KOS,
|
||||||
|
512, 512, 0, CLAW_DATA.len() as u32, CLAW_DATA.as_ptr() as *const c_void);
|
||||||
|
|
||||||
|
let mut tex_dc: u32 = 0;
|
||||||
|
glGenTextures(1, &mut tex_dc);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex_dc);
|
||||||
|
glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_565_VQ_TWID_KOS,
|
||||||
|
512, 512, 0, DC_DATA.len() as u32, DC_DATA.as_ptr() as *const c_void);
|
||||||
|
|
||||||
|
let mut tex_dcwiki: u32 = 0;
|
||||||
|
glGenTextures(1, &mut tex_dcwiki);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex_dcwiki);
|
||||||
|
glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_565_VQ_TWID_KOS,
|
||||||
|
512, 512, 0, DCWIKI_DATA.len() as u32, DCWIKI_DATA.as_ptr() as *const c_void);
|
||||||
|
|
||||||
|
let mut tex_gcc: u32 = 0;
|
||||||
|
glGenTextures(1, &mut tex_gcc);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex_gcc);
|
||||||
|
glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_565_VQ_TWID_KOS,
|
||||||
|
512, 512, 0, GCC_DATA.len() as u32, GCC_DATA.as_ptr() as *const c_void);
|
||||||
|
|
||||||
|
let mut tex_kos: u32 = 0;
|
||||||
|
glGenTextures(1, &mut tex_kos);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex_kos);
|
||||||
|
glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_565_VQ_TWID_KOS,
|
||||||
|
512, 512, 0, KOS_DATA.len() as u32, KOS_DATA.as_ptr() as *const c_void);
|
||||||
|
|
||||||
|
let mut tex_rust: u32 = 0;
|
||||||
|
glGenTextures(1, &mut tex_rust);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex_rust);
|
||||||
|
glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_565_VQ_TWID_KOS,
|
||||||
|
512, 512, 0, RUST_DATA.len() as u32, RUST_DATA.as_ptr() as *const c_void);
|
||||||
|
|
||||||
|
let mut xrot: f32 = 0.0;
|
||||||
|
let mut yrot: f32 = 0.0;
|
||||||
|
let mut zrot: f32 = 0.0;
|
||||||
|
|
||||||
|
let mut draw_gl = || {
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
glLoadIdentity();
|
||||||
|
glTranslatef(0.0, 0.0, -5.0);
|
||||||
|
|
||||||
|
glRotatef(xrot, 1.0, 0.0, 0.0);
|
||||||
|
glRotatef(yrot, 0.0, 1.0, 0.0);
|
||||||
|
glRotatef(zrot, 0.0, 0.0, 1.0);
|
||||||
|
|
||||||
|
// Front face
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex_claw);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
|
glTexCoord2f(1.0, 0.0);
|
||||||
|
glVertex3f(-1.0, -1.0, 1.0);
|
||||||
|
glTexCoord2f(0.0, 0.0);
|
||||||
|
glVertex3f(1.0, -1.0, 1.0);
|
||||||
|
glTexCoord2f(0.0, 1.0);
|
||||||
|
glVertex3f(1.0, 1.0, 1.0);
|
||||||
|
glTexCoord2f(1.0, 1.0);
|
||||||
|
glVertex3f(-1.0, 1.0, 1.0);
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// Back face
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex_gcc);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
|
glTexCoord2f(0.0, 0.0);
|
||||||
|
glVertex3f(-1.0, -1.0, -1.0);
|
||||||
|
glTexCoord2f(0.0, 1.0);
|
||||||
|
glVertex3f(-1.0, 1.0, -1.0);
|
||||||
|
glTexCoord2f(1.0, 1.0);
|
||||||
|
glVertex3f(1.0, 1.0, -1.0);
|
||||||
|
glTexCoord2f(1.0, 0.0);
|
||||||
|
glVertex3f(1.0, -1.0, -1.0);
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// Top face
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex_dcwiki);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
|
glTexCoord2f(1.0, 1.0);
|
||||||
|
glVertex3f(-1.0, 1.0, -1.0);
|
||||||
|
glTexCoord2f(1.0, 0.0);
|
||||||
|
glVertex3f(-1.0, 1.0, 1.0);
|
||||||
|
glTexCoord2f(0.0, 0.0);
|
||||||
|
glVertex3f(1.0, 1.0, 1.0);
|
||||||
|
glTexCoord2f(0.0, 1.0);
|
||||||
|
glVertex3f(1.0, 1.0, -1.0);
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// Bottom face
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex_kos);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
|
glTexCoord2f(0.0, 1.0);
|
||||||
|
glVertex3f(-1.0, -1.0, -1.0);
|
||||||
|
glTexCoord2f(1.0, 1.0);
|
||||||
|
glVertex3f(1.0, -1.0, -1.0);
|
||||||
|
glTexCoord2f(1.0, 0.0);
|
||||||
|
glVertex3f(1.0, -1.0, 1.0);
|
||||||
|
glTexCoord2f(0.0, 0.0);
|
||||||
|
glVertex3f(-1.0, -1.0, 1.0);
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// Right face
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex_dc);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
|
glColor3f(0.0, 1.0, 0.0);
|
||||||
|
glTexCoord2f(0.0, 0.0);
|
||||||
|
glVertex3f(1.0, -1.0, -1.0);
|
||||||
|
glColor3f(0.3, 0.5, 1.0);
|
||||||
|
glTexCoord2f(0.0, 1.0);
|
||||||
|
glVertex3f(1.0, 1.0, -1.0);
|
||||||
|
glColor3f(1.0, 0.3, 0.5);
|
||||||
|
glTexCoord2f(1.0, 1.0);
|
||||||
|
glVertex3f(1.0, 1.0, 1.0);
|
||||||
|
glColor3f(0.5, 0.5, 0.5);
|
||||||
|
glTexCoord2f(1.0, 0.0);
|
||||||
|
glVertex3f(1.0, -1.0, 1.0);
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
// Left face
|
||||||
|
glBindTexture(GL_TEXTURE_2D, tex_rust);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
|
glColor3f(1.0, 0.0, 0.0);
|
||||||
|
glTexCoord2f(1.0, 0.0);
|
||||||
|
glVertex3f(-1.0, -1.0, -1.0);
|
||||||
|
glColor3f(1.0, 1.0, 0.0);
|
||||||
|
glTexCoord2f(0.0, 0.0);
|
||||||
|
glVertex3f(-1.0, -1.0, 1.0);
|
||||||
|
glColor3f(0.0, 1.0, 1.0);
|
||||||
|
glTexCoord2f(0.0, 1.0);
|
||||||
|
glVertex3f(-1.0, 1.0, 1.0);
|
||||||
|
glColor3f(0.0, 0.0, 1.0);
|
||||||
|
glTexCoord2f(1.0, 1.0);
|
||||||
|
glVertex3f(-1.0, 1.0, -1.0);
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
|
||||||
|
xrot += 56.0;
|
||||||
|
yrot += 44.0;
|
||||||
|
zrot += 72.0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Done setting up, now let's loop!
|
||||||
|
loop {
|
||||||
|
let mut done = false;
|
||||||
|
|
||||||
|
MAPLE_FOREACH!(maple::MAPLE_FUNC_CONTROLLER, maple::controller::cont_state_t, state, || {
|
||||||
|
if ((*state).buttons & maple::controller::CONT_START) != 0 {
|
||||||
|
println!("Start pressed! Quitting...");
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
if done == true {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
draw_gl();
|
||||||
|
|
||||||
|
glKosSwapBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up our textures
|
||||||
|
glDeleteTextures(1, &mut tex_claw);
|
||||||
|
glDeleteTextures(1, &mut tex_dc);
|
||||||
|
glDeleteTextures(1, &mut tex_dcwiki);
|
||||||
|
glDeleteTextures(1, &mut tex_gcc);
|
||||||
|
glDeleteTextures(1, &mut tex_kos);
|
||||||
|
glDeleteTextures(1, &mut tex_rust);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Bye!");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue