spinning cake

This commit is contained in:
Andy Killorin 2025-01-03 13:00:49 -05:00
parent c578379890
commit b871694538
Signed by: ank
GPG key ID: 23F9463ECB67FE8C
2 changed files with 38 additions and 60 deletions

View file

@ -2,6 +2,9 @@ BUILD:="disk"
PROJECT_NAME:="cake" PROJECT_NAME:="cake"
TARGET:="target/sh-elf/release/dccake.elf" TARGET:="target/sh-elf/release/dccake.elf"
run: build
flycast cake.cdi
logo: logo:
mkdir -p build mkdir -p build
convert assets/cake.png -resize 320x90 build/cakes.png convert assets/cake.png -resize 320x90 build/cakes.png

View file

@ -7,21 +7,16 @@ use gldc::{
}; };
// Include texture data generated by build script // Include texture data generated by build script
static CLAW_DATA: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/exterior.vq")); static EXTERIOR: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/exterior.vq"));
static DC_DATA: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/exterior.vq")); static INTERIOR: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/interiors.vq"));
static DCWIKI_DATA: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/exterior.vq")); static TOP: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/caketops.vq"));
static GCC_DATA: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/interiors.vq")); static SLICE: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/slices.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() {
unsafe { unsafe {
// Initialize GLdc // Initialize GLdc
glKosInit(); glKosInit();
// Say hello to the world!
println!("\nHello, world from Rust! - gldc-cube example");
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
gluPerspective(45.0, 640.0 / 480.0, 0.1, 100.0); gluPerspective(45.0, 640.0 / 480.0, 0.1, 100.0);
@ -35,43 +30,31 @@ fn main() {
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
let mut tex_claw: u32 = 0; let mut tex_exterior: u32 = 0;
glGenTextures(1, &mut tex_claw); glGenTextures(1, &mut tex_exterior);
glBindTexture(GL_TEXTURE_2D, tex_claw); glBindTexture(GL_TEXTURE_2D, tex_exterior);
glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_565_VQ_TWID_KOS, 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); 512, 512, 0, EXTERIOR.len() as u32, EXTERIOR.as_ptr() as *const c_void);
let mut tex_dc: u32 = 0; let mut tex_interior: u32 = 0;
glGenTextures(1, &mut tex_dc); glGenTextures(1, &mut tex_interior);
glBindTexture(GL_TEXTURE_2D, tex_dc); glBindTexture(GL_TEXTURE_2D, tex_interior);
glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_565_VQ_TWID_KOS, 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); 512, 512, 0, INTERIOR.len() as u32, INTERIOR.as_ptr() as *const c_void);
let mut tex_dcwiki: u32 = 0; let mut tex_top: u32 = 0;
glGenTextures(1, &mut tex_dcwiki); glGenTextures(1, &mut tex_top);
glBindTexture(GL_TEXTURE_2D, tex_dcwiki); glBindTexture(GL_TEXTURE_2D, tex_top);
glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_565_VQ_TWID_KOS, 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); 512, 512, 0, TOP.len() as u32, TOP.as_ptr() as *const c_void);
let mut tex_gcc: u32 = 0; let mut tex_slice: u32 = 0;
glGenTextures(1, &mut tex_gcc); glGenTextures(1, &mut tex_slice);
glBindTexture(GL_TEXTURE_2D, tex_gcc); glBindTexture(GL_TEXTURE_2D, tex_slice);
glCompressedTexImage2DARB(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_565_VQ_TWID_KOS, 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); 512, 512, 0, SLICE.len() as u32, SLICE.as_ptr() as *const c_void);
let mut tex_kos: u32 = 0; let mut xrot: f32 = 1400.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 yrot: f32 = 0.0;
let mut zrot: f32 = 0.0; let mut zrot: f32 = 0.0;
@ -85,7 +68,7 @@ fn main() {
glRotatef(zrot, 0.0, 0.0, 1.0); glRotatef(zrot, 0.0, 0.0, 1.0);
// Front face // Front face
glBindTexture(GL_TEXTURE_2D, tex_claw); glBindTexture(GL_TEXTURE_2D, tex_exterior);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0); glColor3f(1.0, 1.0, 1.0);
@ -101,7 +84,7 @@ fn main() {
glEnd(); glEnd();
// Back face // Back face
glBindTexture(GL_TEXTURE_2D, tex_gcc); glBindTexture(GL_TEXTURE_2D, tex_exterior);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0); glColor3f(1.0, 1.0, 1.0);
@ -117,7 +100,7 @@ fn main() {
glEnd(); glEnd();
// Top face // Top face
glBindTexture(GL_TEXTURE_2D, tex_dcwiki); glBindTexture(GL_TEXTURE_2D, tex_top);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0); glColor3f(1.0, 1.0, 1.0);
@ -133,7 +116,7 @@ fn main() {
glEnd(); glEnd();
// Bottom face // Bottom face
glBindTexture(GL_TEXTURE_2D, tex_kos); glBindTexture(GL_TEXTURE_2D, tex_exterior);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0); glColor3f(1.0, 1.0, 1.0);
@ -149,46 +132,40 @@ fn main() {
glEnd(); glEnd();
// Right face // Right face
glBindTexture(GL_TEXTURE_2D, tex_dc); glBindTexture(GL_TEXTURE_2D, tex_exterior);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor3f(0.0, 1.0, 0.0); glColor3f(1.0, 1.0, 1.0);
glTexCoord2f(0.0, 0.0); glTexCoord2f(0.0, 0.0);
glVertex3f(1.0, -1.0, -1.0); glVertex3f(1.0, -1.0, -1.0);
glColor3f(0.3, 0.5, 1.0);
glTexCoord2f(0.0, 1.0); glTexCoord2f(0.0, 1.0);
glVertex3f(1.0, 1.0, -1.0); glVertex3f(1.0, 1.0, -1.0);
glColor3f(1.0, 0.3, 0.5);
glTexCoord2f(1.0, 1.0); glTexCoord2f(1.0, 1.0);
glVertex3f(1.0, 1.0, 1.0); glVertex3f(1.0, 1.0, 1.0);
glColor3f(0.5, 0.5, 0.5);
glTexCoord2f(1.0, 0.0); glTexCoord2f(1.0, 0.0);
glVertex3f(1.0, -1.0, 1.0); glVertex3f(1.0, -1.0, 1.0);
glEnd(); glEnd();
// Left face // Left face
glBindTexture(GL_TEXTURE_2D, tex_rust); glBindTexture(GL_TEXTURE_2D, tex_exterior);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0); glColor3f(1., 1., 1.);
glTexCoord2f(1.0, 0.0); glTexCoord2f(1.0, 0.0);
glVertex3f(-1.0, -1.0, -1.0); glVertex3f(-1.0, -1.0, -1.0);
glColor3f(1.0, 1.0, 0.0);
glTexCoord2f(0.0, 0.0); glTexCoord2f(0.0, 0.0);
glVertex3f(-1.0, -1.0, 1.0); glVertex3f(-1.0, -1.0, 1.0);
glColor3f(0.0, 1.0, 1.0);
glTexCoord2f(0.0, 1.0); glTexCoord2f(0.0, 1.0);
glVertex3f(-1.0, 1.0, 1.0); glVertex3f(-1.0, 1.0, 1.0);
glColor3f(0.0, 0.0, 1.0);
glTexCoord2f(1.0, 1.0); glTexCoord2f(1.0, 1.0);
glVertex3f(-1.0, 1.0, -1.0); glVertex3f(-1.0, 1.0, -1.0);
glEnd(); glEnd();
xrot += 56.0; //xrot += 56.0;
yrot += 44.0; yrot += 44.0;
zrot += 72.0; //zrot += 72.0;
}; };
@ -214,12 +191,10 @@ fn main() {
} }
// Clean up our textures // Clean up our textures
glDeleteTextures(1, &mut tex_claw); glDeleteTextures(1, &mut tex_exterior);
glDeleteTextures(1, &mut tex_dc); glDeleteTextures(1, &mut tex_interior);
glDeleteTextures(1, &mut tex_dcwiki); glDeleteTextures(1, &mut tex_top);
glDeleteTextures(1, &mut tex_gcc); glDeleteTextures(1, &mut tex_slice);
glDeleteTextures(1, &mut tex_kos);
glDeleteTextures(1, &mut tex_rust);
} }
println!("Bye!"); println!("Bye!");