Skip to content

Commit a5f786e

Browse files
authored
Merge pull request #69 from fjtrujy/addingClutExample
Creating an example of using a texture with Clut
2 parents a745f10 + a1bda5c commit a5f786e

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

examples/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ SUBDIRS += atlas
1515
SUBDIRS += basic
1616
SUBDIRS += bigtex
1717
SUBDIRS += coverflow
18+
SUBDIRS += clut
1819
SUBDIRS += cube
1920
SUBDIRS += fb
2021
SUBDIRS += fhdbg

examples/clut/Makefile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# ____ ___ | / _____ _____
2+
# | __ | |___/ | |
3+
# |___| ___| | \ __|__ | gsKit Open Source Project.
4+
# ----------------------------------------------------------------------
5+
# Copyright 2004 - Chris "Neovanglist" Gilbert <[email protected]>
6+
# Licenced under Academic Free License version 2.0
7+
# Review gsKit README & LICENSE files for further details.
8+
#
9+
# examples/clut/Makefile - Makefile for "clut" example.
10+
#
11+
12+
EE_BIN = clut.elf
13+
EE_OBJS = clut.o
14+
15+
include ../../Makefile.pref
16+
include ../Makefile.global

examples/clut/clut.c

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// ____ ___ | / _____ _____
2+
// | __ | |___/ | |
3+
// |___| ___| | \ __|__ | gsKit Open Source Project.
4+
// ----------------------------------------------------------------------
5+
// Copyright 2004 - Chris "Neovanglist" Gilbert <[email protected]>
6+
// Licenced under Academic Free License version 2.0
7+
// Review gsKit README & LICENSE files for further details.
8+
//
9+
// textures.c - Example demonstrating gsKit texture operation.
10+
//
11+
12+
#include <stdio.h>
13+
#include <malloc.h>
14+
15+
#include <gsKit.h>
16+
#include <dmaKit.h>
17+
#include <gsToolkit.h>
18+
#include <gsInline.h>
19+
#include <gsTexture.h>
20+
21+
#define CLUT_SIZE 256
22+
#define TEXTURE_WIDTH 320
23+
#define TEXTURE_HEIGHT 240
24+
25+
int main(int argc, char *argv[])
26+
{
27+
GSGLOBAL *gsGlobal;
28+
GSTEXTURE tex;
29+
uint32_t i, j, offset;
30+
uint32_t totalVertices = 2;
31+
uint64_t White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00);
32+
gs_rgbaq color = color_to_RGBAQ(0x80, 0x80, 0x80, 0x80, 0);
33+
34+
gsGlobal = gsKit_init_global();
35+
36+
gsGlobal->PSM = GS_PSM_CT24;
37+
gsGlobal->PSMZ = GS_PSMZ_16S;
38+
39+
dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
40+
D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
41+
42+
// Initialize the DMAC
43+
dmaKit_chan_init(DMA_CHANNEL_GIF);
44+
45+
gsKit_init_screen(gsGlobal);
46+
gsKit_TexManager_init(gsGlobal);
47+
gsKit_mode_switch(gsGlobal, GS_ONESHOT);
48+
49+
tex.Width = TEXTURE_WIDTH;
50+
tex.Height = TEXTURE_HEIGHT;
51+
tex.PSM = GS_PSM_T8;
52+
tex.ClutPSM = GS_PSM_CT32;
53+
tex.Clut = memalign(128, gsKit_texture_size_ee(CLUT_SIZE, 1, tex.ClutPSM));
54+
tex.Mem = memalign(128, gsKit_texture_size_ee(tex.Width, tex.Height, tex.PSM));
55+
56+
printf("Tex VRAM Range = 0x%X - 0x%X\n",tex.Vram, tex.Vram +gsKit_texture_size(tex.Width, tex.Height, tex.PSM) - 1);
57+
58+
gsKit_set_clamp(gsGlobal, GS_CMODE_CLAMP);
59+
60+
// initialize texture
61+
uint8_t *tex256 = (uint8_t*)tex.Mem;
62+
for (j = 0; j < tex.Height; ++j) {
63+
for (i = 0; i < tex.Width; ++i) {
64+
tex256[i + j * tex.Width] = j ^ i;
65+
}
66+
}
67+
68+
GSPRIMUVPOINT *verts = (GSPRIMUVPOINT*)malloc(sizeof(GSPRIMUVPOINT) * totalVertices);
69+
verts[0].xyz2 = vertex_to_XYZ2(gsGlobal, 0, 0, 0);
70+
verts[0].rgbaq = color;
71+
verts[0].uv = vertex_to_UV(&tex, 0, 0);
72+
73+
verts[1].xyz2 = vertex_to_XYZ2(gsGlobal, gsGlobal->Width, gsGlobal->Height, 0);
74+
verts[1].rgbaq = color;
75+
verts[1].uv = vertex_to_UV(&tex, tex.Width, tex.Height);
76+
77+
offset = 0;
78+
79+
while(1) {
80+
unsigned int* clut = tex.Clut;
81+
for (i = 0; i < CLUT_SIZE; ++i) {
82+
unsigned int j = (i + offset)&0xff;
83+
*(clut++) = (j << 24)|(j << 16)|(j << 8)|(j);
84+
}
85+
86+
gsKit_clear(gsGlobal, White);
87+
gsKit_TexManager_invalidate(gsGlobal, &tex);
88+
gsKit_TexManager_bind(gsGlobal, &tex);
89+
gskit_prim_list_sprite_texture_uv_3d(gsGlobal, &tex, totalVertices, verts);
90+
91+
gsKit_queue_exec(gsGlobal);
92+
gsKit_sync_flip(gsGlobal);
93+
gsKit_TexManager_nextFrame(gsGlobal);
94+
95+
offset++;
96+
}
97+
98+
free(verts);
99+
100+
return 0;
101+
}

0 commit comments

Comments
 (0)