What I wanted to do is to be able to upload an 8-bit 160x120 texture from a 2-dimensional array which I'll then draw as a 320x240 sprite to fill up the entire screen. The problem is, I can't get it to work.
This is for my little work-in-progress side-project I call M-Demo (which will be like a cracktro only with CDDA music). The texture thing which I'm having trouble with is for the real-time 8-bit plasma background.
Compile the following source code with PsyQ...
makefile.mak:
Code: Select all
all:
ccpsx -O -Xo$80010000 main.c -omain.cpe,main.sym
for_menu:
ccpsx -O -Xo$80010000 main.c \psx\lib\none2.obj -oarot.cpe
Code: Select all
// Includes
#include <sys/types.h>
#include <libetc.h>
#include <libgte.h>
#include <libgpu.h>
#include <libgs.h>
#include <stdio.h>
// Some definitions
#define OT_LENGTH 10
#define PACKETMAX (2048)
#define PACKETMAX2 (PACKETMAX*24)
// Object tables
GsOT myOT[2];
GsOT_TAG myOT_TAG[2][1<<OT_LENGTH];
PACKET GPUPacketArea[2][PACKETMAX2];
// Plasma tables
#include "PlasmaCLUT.h"
// Prototypes
int main(void);
void Init(void);
void Display(int ActiveBuffer);
// Main procedure
int main(void)
{
int ActiveBuffer=0;
u_short OTpos=0;
// For the plasma texture stuff
short px;
short py;
unsigned char pBuff[159][119]; // Enough for a 160x120 8-bit texture
u_short pClutID;
u_short pTexID;
RECT pTex;
GsSPRITE pSprite;
// Init stuff
Init();
/* Plasma effect notes:
320, 0, P5 - Texture coords
320, 255 - CLUT coords
*/
// This is where I'm having trouble with
pSprite.attribute = 1 * (2 ^ 24); // Set bits 24-25 to 1 for 8-bit CLUT texture
pSprite.x = 0;
pSprite.y = 0;
pSprite.w = 160;
pSprite.h = 120;
pSprite.tpage = 5;
pSprite.cx = 320;
pSprite.cy = 256;
pSprite.r = 128;
pSprite.g = 128;
pSprite.b = 128;
pSprite.scalex = 4096;
pSprite.scaley = 4096;
// Fractal texture coordinates (for LoadImage)
pTex.x = 320;
pTex.y = 0;
pTex.w = 80;
pTex.h = 120;
// Load the CLUT
pClutID = LoadClut((u_long*)&PlasmaCLUT[0], 320, 256);
// Draw a fractal test pattern
for (py=0; py<120; py=py+1)
{
for (px=0; px<160; px=px+1)
{
pBuff[px][py]=px|py;
}
}
// Upload the procedurally generated fractal texture
pTexID = LoadTPage((u_long*)&pBuff[0][0], 1, 0, 320, 0, 160, 120); // This doesn't seem to work
//result = LoadImage(&pTex, (u_long*)&pBuff[0][0]); // This doesn't seem to work as well
// I can't tell because stupid ePSXe doesn't let you view the entire framebuffer.
// Main loop
while (1)
{
ActiveBuffer = GsGetActiveBuff();
GsSetWorkBase((PACKET*)GPUPacketArea[ActiveBuffer]);
GsClearOt(0, 0, &myOT[ActiveBuffer]);
// Print some debugging junk
FntPrint("Buffer=%d\n", ActiveBuffer);
FntPrint("TexID=%d\n", pTexID);
FntPrint("ClutID=%d\n", pClutID);
// Draw the fractal texture (it doesn't work...I don't know why)
GsSortSprite(&pSprite, &myOT[ActiveBuffer], OTpos);
OTpos = OTpos + 1;
// Display and reset stuff for the next frame
Display(ActiveBuffer);
OTpos=0;
}
}
// Init
void Init(void)
{
long result=0;
// Initialize pads
PadInit(0);
// Initialize the graphics
GsInitGraph(320, 240, GsNONINTER|GsOFSGPU, 1, 0);
GsDefDispBuff(0, 0, 0, 240);
myOT[0].length = OT_LENGTH;
myOT[1].length = OT_LENGTH;
myOT[0].org = myOT_TAG[0];
myOT[1].org = myOT_TAG[1];
GsClearOt(0, 0, &myOT[0]);
GsClearOt(0, 0, &myOT[1]);
ResetGraph(0);
SetVideoMode(MODE_NTSC);
SetGraphDebug(0);
// Initialize debug font
FntLoad(960, 256);
FntOpen(0, 0, 320, 240, 0, 512);
}
void Display(int ActiveBuffer)
{
FntFlush(-1);
DrawSync(0);
VSync(0);
GsSwapDispBuff();
GsSortClear(0, 70, 0, &myOT[ActiveBuffer]);
GsDrawOt(&myOT[ActiveBuffer]);
}
Code: Select all
unsigned short PlasmaCLUT[] = {
0x0000,
0x0420,
0x0840,
0x0C61,
0x1081,
0x14A1,
0x18C2,
0x1CE2,
0x2522,
0x2943,
0x2D63,
0x3183,
0x35A4,
0x39C5,
0x3DE5,
0x4205,
0x4626,
0x4A46,
0x4E66,
0x5287,
0x56A7,
0x5AC7,
0x5AC8,
0x5EE8,
0x6308,
0x6729,
0x6B49,
0x6B4A,
0x6F6A,
0x6F6A,
0x738B,
0x738B,
0x77AC,
0x7BCC,
0x7BCD,
0x7BCD,
0x7BCD,
0x7FEE,
0x7FEE,
0x7FEE,
0x7FEF,
0x7FEF,
0x7FEF,
0x7FEF,
0x7FF0,
0x7FF0,
0x7FF0,
0x7FF1,
0x7FF1,
0x7BD1,
0x7BD2,
0x7BD2,
0x7BD2,
0x77B3,
0x77B3,
0x7393,
0x6F74,
0x6F74,
0x6B54,
0x6B54,
0x6735,
0x6315,
0x6315,
0x5EF6,
0x5AD6,
0x56B6,
0x5296,
0x4E77,
0x4A57,
0x4637,
0x4218,
0x4218,
0x39D8,
0x35B8,
0x3199,
0x2D79,
0x2959,
0x2539,
0x211A,
0x1CFA,
0x14BA,
0x109A,
0x0C7B,
0x085B,
0x043B,
0x001B,
0x043B,
0x085B,
0x0C7C,
0x14BC,
0x18DC,
0x1CFC,
0x211C,
0x253C,
0x295D,
0x2D7D,
0x35BD,
0x39DD,
0x3DFD,
0x3DFE,
0x421E,
0x463E,
0x4A5E,
0x4E7E,
0x529E,
0x56BE,
0x5ADE,
0x5EFE,
0x631E,
0x631F,
0x673F,
0x6B5F,
0x6F7F,
0x6F7F,
0x739F,
0x739F,
0x77BF,
0x77BF,
0x7BDF,
0x7BDF,
0x7BDF,
0x7FFF,
0x7FFF,
0x7FFF,
0x7FFF,
0x7FFF,
0x7FFF,
0x7FFF,
0x7FFF,
0x7FFF,
0x7FFF,
0x7FFF,
0x7FFF,
0x7FFF,
0x7BDF,
0x7BDF,
0x7BDF,
0x77BF,
0x77BF,
0x739F,
0x739F,
0x6F7F,
0x6F7F,
0x6B5F,
0x673F,
0x673F,
0x631F,
0x5EFE,
0x5ADE,
0x5ADE,
0x56BE,
0x529E,
0x4E7E,
0x4A5E,
0x463E,
0x421E,
0x3DFE,
0x39DD,
0x35BD,
0x319D,
0x295D,
0x253D,
0x211D,
0x1CFC,
0x18DC,
0x14BC,
0x109C,
0x0C7C,
0x043B,
0x001B,
0x001B,
0x043B,
0x085B,
0x0C7B,
0x14BA,
0x18DA,
0x1CFA,
0x211A,
0x2539,
0x2959,
0x2D79,
0x35B9,
0x39D9,
0x3DF8,
0x4218,
0x4638,
0x4A58,
0x4E77,
0x5297,
0x5297,
0x56B6,
0x5AD6,
0x5EF6,
0x6316,
0x6735,
0x6735,
0x6B55,
0x6F74,
0x6F74,
0x7394,
0x7394,
0x77B3,
0x77B3,
0x7BD3,
0x7BD2,
0x7BD2,
0x7FF2,
0x7FF1,
0x7FF1,
0x7FF0,
0x7FF0,
0x7FF0,
0x7FF0,
0x7FF0,
0x7FEF,
0x7FEF,
0x7FEE,
0x7FEE,
0x7FEE,
0x7BCD,
0x7BCD,
0x7BCD,
0x77AC,
0x77AC,
0x738C,
0x738B,
0x6F6A,
0x6F6A,
0x6B4A,
0x6729,
0x6729,
0x6309,
0x5EE8,
0x5AC8,
0x56A8,
0x5287,
0x5287,
0x4E67,
0x4A46,
0x4626,
0x4206,
0x3DE5,
0x39C5,
0x35A4,
0x3184,
0x2943,
0x2523,
0x2103,
0x1CE2,
0x18C2,
0x14A1,
0x0C61,
0x0841,
0x0420,
0x0000,
0x0000
};