aboutsummaryrefslogtreecommitdiff
path: root/examples/graphics
diff options
context:
space:
mode:
authorspicyjpeg <thatspicyjpeg@gmail.com>2022-08-10 22:49:49 +0200
committerspicyjpeg <thatspicyjpeg@gmail.com>2022-08-10 22:49:49 +0200
commita1081f296bca4f718cf31e5b6a262661d132e9e4 (patch)
treeee979fe0120fed803d0c63ca824dbff3921dadc6 /examples/graphics
parentce33eee403c678d3e2850046955f265585af76d7 (diff)
downloadpsn00bsdk-a1081f296bca4f718cf31e5b6a262661d132e9e4.tar.gz
Misc. fixes, add texturing to graphics/gte example
Diffstat (limited to 'examples/graphics')
-rw-r--r--examples/graphics/gte/CMakeLists.txt4
-rw-r--r--examples/graphics/gte/main.c51
-rw-r--r--examples/graphics/gte/texture.timbin0 -> 16928 bytes
3 files changed, 40 insertions, 15 deletions
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..ba96ace 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 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 );
@@ -250,7 +265,7 @@ void init() {
SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES );
/* Enable draw area clear and dither processing */
- setRGB0( &db[0].draw, 63, 0, 127 );
+ setRGB0( &db[0].draw, 0, 255, 0 );
db[0].draw.isbg = 1;
db[0].draw.dtd = 1;
@@ -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
new file mode 100644
index 0000000..54ce2f0
--- /dev/null
+++ b/examples/graphics/gte/texture.tim
Binary files differ