aboutsummaryrefslogtreecommitdiff
path: root/examples/graphics/gte/main.c
diff options
context:
space:
mode:
authorJohn "Lameguy" Wilbert Villamor <lameguy64@gmail.com>2022-09-26 16:49:56 +0800
committerGitHub <noreply@github.com>2022-09-26 16:49:56 +0800
commitc4a2533d21dfd05cde841ea48c67b05e0e6a853f (patch)
treec7ef61653b157b69fb0956709366996ddbc4ecfa /examples/graphics/gte/main.c
parenta8b404b3400c3ebd8e0b923dcaefcc49ea563e36 (diff)
parent86f0064afb8200e60dd80827535cac30d0eab028 (diff)
downloadpsn00bsdk-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/gte/main.c')
-rw-r--r--examples/graphics/gte/main.c49
1 files changed, 36 insertions, 13 deletions
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
+}