diff options
| author | John "Lameguy" Wilbert Villamor <lameguy64@gmail.com> | 2022-09-26 16:49:56 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-26 16:49:56 +0800 |
| commit | c4a2533d21dfd05cde841ea48c67b05e0e6a853f (patch) | |
| tree | c7ef61653b157b69fb0956709366996ddbc4ecfa /examples/graphics | |
| parent | a8b404b3400c3ebd8e0b923dcaefcc49ea563e36 (diff) | |
| parent | 86f0064afb8200e60dd80827535cac30d0eab028 (diff) | |
| download | psn00bsdk-c4a2533d21dfd05cde841ea48c67b05e0e6a853f.tar.gz | |
Merge pull request #55 from spicyjpeg/psxmdec
Full MDEC support, C library refactors, cleanups and bugfixes (v0.20)
Diffstat (limited to 'examples/graphics')
| -rw-r--r-- | examples/graphics/balls/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | examples/graphics/balls/ball16c.h | 16 | ||||
| -rw-r--r-- | examples/graphics/balls/main.c | 16 | ||||
| -rw-r--r-- | examples/graphics/gte/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | examples/graphics/gte/main.c | 49 | ||||
| -rw-r--r-- | examples/graphics/gte/texture.tim | bin | 0 -> 16928 bytes |
6 files changed, 50 insertions, 39 deletions
diff --git a/examples/graphics/balls/CMakeLists.txt b/examples/graphics/balls/CMakeLists.txt index f5297c3..deee473 100644 --- a/examples/graphics/balls/CMakeLists.txt +++ b/examples/graphics/balls/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.20) project( balls - LANGUAGES C + LANGUAGES C ASM VERSION 1.0.0 DESCRIPTION "PSn00bSDK sprites example" HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" @@ -15,4 +15,6 @@ file(GLOB _sources *.c) psn00bsdk_add_executable(balls STATIC ${_sources}) #psn00bsdk_add_cd_image(balls_iso balls iso.xml DEPENDS balls) +psn00bsdk_target_incbin(balls PRIVATE ball16c ball16c.tim) + install(FILES ${PROJECT_BINARY_DIR}/balls.exe TYPE BIN) diff --git a/examples/graphics/balls/ball16c.h b/examples/graphics/balls/ball16c.h deleted file mode 100644 index c79f273..0000000 --- a/examples/graphics/balls/ball16c.h +++ /dev/null @@ -1,16 +0,0 @@ -unsigned int ball16c_size=192; -unsigned char ball16c[] = { -0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10, -0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d, -0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a, -0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01, -0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32, -0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52, -0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31, -0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4, -0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce, -0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7, -0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e, -0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4, -0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00 -}; diff --git a/examples/graphics/balls/main.c b/examples/graphics/balls/main.c index e429a4b..5af0bfb 100644 --- a/examples/graphics/balls/main.c +++ b/examples/graphics/balls/main.c @@ -18,14 +18,12 @@ * */ -#include <sys/types.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <psxetc.h> #include <psxgte.h> #include <psxgpu.h> -#include "ball16c.h" - #define MAX_BALLS 1024 @@ -42,10 +40,10 @@ DISPENV disp; DRAWENV draw; -char pribuff[2][65536]; /* Primitive packet buffers */ -u_long ot[2][OT_LEN]; /* Ordering tables */ -char *nextpri; /* Pointer to next packet buffer offset */ -int db = 0; /* Double buffer index */ +char pribuff[2][65536]; /* Primitive packet buffers */ +uint32_t ot[2][OT_LEN]; /* Ordering tables */ +char *nextpri; /* Pointer to next packet buffer offset */ +int db = 0; /* Double buffer index */ /* Ball struct and array */ @@ -57,6 +55,8 @@ typedef struct { BALL_TYPE balls[MAX_BALLS]; +/* Ball texture reference */ +extern const uint32_t ball16c[]; /* TIM image parameters for loading the ball texture and drawing sprites */ TIM_IMAGE tim; @@ -96,7 +96,7 @@ void init() { /* Upload the ball texture */ printf("Upload texture... "); - GetTimInfo( (u_long*)ball16c, &tim ); /* Get TIM parameters */ + GetTimInfo( ball16c, &tim ); /* Get TIM parameters */ LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */ if( tim.mode & 0x8 ) { diff --git a/examples/graphics/gte/CMakeLists.txt b/examples/graphics/gte/CMakeLists.txt index f95c5ff..90d897b 100644 --- a/examples/graphics/gte/CMakeLists.txt +++ b/examples/graphics/gte/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.20) project( gte - LANGUAGES C + LANGUAGES C ASM VERSION 1.0.0 DESCRIPTION "PSn00bSDK GTE 3D cube example" HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" @@ -15,4 +15,6 @@ file(GLOB _sources *.c) psn00bsdk_add_executable(gte STATIC ${_sources}) #psn00bsdk_add_cd_image(gte_iso gte iso.xml DEPENDS gte) +psn00bsdk_target_incbin(gte PRIVATE tim_texture texture.tim) + install(FILES ${PROJECT_BINARY_DIR}/gte.exe TYPE BIN) diff --git a/examples/graphics/gte/main.c b/examples/graphics/gte/main.c index a7ddb6b..6907c84 100644 --- a/examples/graphics/gte/main.c +++ b/examples/graphics/gte/main.c @@ -12,13 +12,15 @@ * * Changelog: * - * May 10, 2021 - Variable types updated for psxgpu.h changes. + * Aug 10, 2022 - Added texture to cube faces. + * + * May 10, 2021 - Variable types updated for psxgpu.h changes. * * Jan 26, 2019 - Initial version. * */ -#include <sys/types.h> +#include <stdint.h> #include <stdio.h> #include <psxgpu.h> #include <psxgte.h> @@ -39,10 +41,10 @@ /* Double buffer structure */ typedef struct { - DISPENV disp; /* Display environment */ - DRAWENV draw; /* Drawing environment */ - u_long ot[OT_LEN]; /* Ordering table */ - char p[PACKET_LEN]; /* Packet buffer */ + DISPENV disp; /* Display environment */ + DRAWENV draw; /* Drawing environment */ + uint32_t ot[OT_LEN]; /* Ordering table */ + char p[PACKET_LEN]; /* Packet buffer */ } DB; /* Double buffer variables */ @@ -98,9 +100,9 @@ INDEX cube_indices[] = { /* source color when using gte_nccs(). 4096 is 1.0 in this matrix */ /* A column of zeroes disables the light source. */ MATRIX color_mtx = { - ONE, 0, 0, /* Red */ - ONE, 0, 0, /* Green */ - ONE, 0, 0 /* Blue */ + ONE / 2, 0, 0, /* Red */ + ONE / 2, 0, 0, /* Green */ + ONE / 2, 0, 0 /* Blue */ }; /* Light matrix */ @@ -114,6 +116,13 @@ MATRIX light_mtx = { }; +/* Reference texture data */ +extern const uint32_t tim_texture[]; + +/* TPage and CLUT values */ +uint16_t texture_tpage; /* For the scrolling blending pattern */ +uint16_t texture_clut; + /* Function declarations */ void init(); void display(); @@ -128,7 +137,7 @@ int main() { VECTOR pos = { 0, 0, 400 }; /* Translation vector for TransMatrix */ MATRIX mtx,lmtx; /* Rotation matrices for geometry and lighting */ - POLY_F4 *pol4; /* Flat shaded quad primitive pointer */ + POLY_FT4 *pol4; /* Flat shaded textured quad primitive pointer */ /* Init graphics and GTE */ @@ -159,7 +168,7 @@ int main() { /* Draw the cube */ - pol4 = (POLY_F4*)db_nextpri; + pol4 = (POLY_FT4*)db_nextpri; for( i=0; i<CUBE_FACES; i++ ) { @@ -192,7 +201,7 @@ int main() { continue; /* Initialize a quad primitive */ - setPolyF4( pol4 ); + setPolyFT4( pol4 ); /* Set the projected vertices to the primitive */ gte_stsxy0( &pol4->x0 ); @@ -218,6 +227,11 @@ int main() { /* Store result to the primitive */ gte_strgb( &pol4->r0 ); + /* Set face texture */ + setUVWH( pol4, 0, 1, 128, 128 ); + pol4->tpage = texture_tpage; + pol4->clut = texture_clut; + /* Sort primitive to the ordering table */ addPrim( db[db_active].ot+(p>>2), pol4 ); @@ -240,6 +254,7 @@ int main() { } void init() { + TIM_IMAGE tim; /* Reset the GPU, also installs a VSync event handler */ ResetGraph( 0 ); @@ -287,7 +302,15 @@ void init() { /* Set light ambient color and light color matrix */ gte_SetBackColor( 63, 63, 63 ); gte_SetColorMatrix( &color_mtx ); + + /* Load .TIM file */ + GetTimInfo(tim_texture, &tim); + if( tim.mode & 0x8 ) + LoadImage( tim.crect, tim.caddr ); /* Upload CLUT if present */ + LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */ + texture_tpage = getTPage(tim.mode, 1, tim.prect->x, tim.prect->y); + texture_clut = getClut(tim.crect->x, tim.crect->y); } void display() { @@ -313,4 +336,4 @@ void display() { /* Start drawing the OT of the last buffer */ DrawOTag( db[1-db_active].ot+(OT_LEN-1) ); -}
\ No newline at end of file +} diff --git a/examples/graphics/gte/texture.tim b/examples/graphics/gte/texture.tim Binary files differnew file mode 100644 index 0000000..54ce2f0 --- /dev/null +++ b/examples/graphics/gte/texture.tim |
