Can anyone help me with textures and displaying it?

General Programming help in C, C++ or ASM, Compiling / Debugging, and R3000A Central Processing Unit (CPU) information
Post Reply
User avatar
LameGuy64
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 388
Joined: Apr 10, 2013
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

Can anyone help me with textures and displaying it?

Post by LameGuy64 » May 16th, 2013, 3:39 pm

I've been trying to upload and draw a texture but it doesn't seem to work for me. I don't really know why and I doubt anyone can help because those who know how to properly upload and display a texture have probably left this forum by now.

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
main.c:

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]);

}
PlasmaCLUT.h:

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
};
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

Orion_
Verified
Legendary Programmer
Legendary Programmer
Posts: 240
Joined: Aug 13, 2012
I am a: Programmer
PlayStation Model: Net Yaroze
Location: France
Contact:

Post by Orion_ » May 16th, 2013, 8:46 pm

There are many C language syntax error in your program:
First, unsigned char pBuff[159][119]; // Enough for a 160x120 8-bit texture
is not correct, it should be pBuff[160][120];

This pSprite.attribute = 1 * (2 ^ 24); is not correct either,
'^' is not a "power of" in C
'^' is xor.
so use: pSprite.attribute = 1 << 24;

Also, initialise, pSprite.u and pSprite.v to 0

Don't hardcore the tpage: use: GetTPage(1/*8bits*/, 0, pTex.x, pTex.y);

And then use LoadImage
Retro game development on Playstation and other consoles http://orionsoft.free.fr/

User avatar
LameGuy64
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 388
Joined: Apr 10, 2013
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

Post by LameGuy64 » May 17th, 2013, 1:29 am

Then how can I draw the tpage? GsSortSprite still does nothing to the screen.
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

Orion_
Verified
Legendary Programmer
Legendary Programmer
Posts: 240
Joined: Aug 13, 2012
I am a: Programmer
PlayStation Model: Net Yaroze
Location: France
Contact:

Post by Orion_ » May 17th, 2013, 4:22 am

I just tried and it's working for me on epsxe.

I corrected some little thing on the order of x/y of your texture tab.

Code: Select all

   int ActiveBuffer=0;
   u_short OTpos=0;


   // For the plasma texture stuff
   short px;
   short py;
   unsigned char pBuff[120][160]; // 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 << 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    = GetTPage(1, 0, 320, 0);
   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++)
   {
	  for (px=0; px<160; px++)
	  {
		 pBuff[py][px]=px|py;
	  }
   }
Retro game development on Playstation and other consoles http://orionsoft.free.fr/

User avatar
LameGuy64
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 388
Joined: Apr 10, 2013
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

Post by LameGuy64 » May 17th, 2013, 10:02 am

It finally works! Thanks for the help!

All I had to do now is fix the CLUT for the plasma texture (I got the color bits incorrectly ordered) and port my high-speed plasma routine.
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

User avatar
inc^lightforce
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 248
Joined: Mar 07, 2013
I am a: Programmer Windows+PS1, GFX Artist
PlayStation Model: Black
Location: Germany

Post by inc^lightforce » May 18th, 2013, 7:25 am

when it's done, please show us a video :) --> or publish the psx exe .

User avatar
LameGuy64
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 388
Joined: Apr 10, 2013
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

Post by LameGuy64 » May 18th, 2013, 11:34 pm

No problem! Give me 1 or 2 days before release.

Its just a cute little demo with some graphical potential tacked onto it (real-time plasma!) to show that my production label, Meido-Tek Productions, enters the PSX-DEV scene.
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

User avatar
bizarro2011
Serious PSXDEV User
Serious PSXDEV User
Posts: 118
Joined: Mar 27, 2012
Location: Brazil

Post by bizarro2011 » May 21st, 2013, 10:16 pm

maybe you can help me.
you created it.

unsigned short PlasmaCLUT[] = {
0x0000,

need to create it.

unsigned long PlasmaCLUT[] = {
0x04210000,

you can explain to me how it's done.

User avatar
LameGuy64
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 388
Joined: Apr 10, 2013
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

Post by LameGuy64 » May 21st, 2013, 11:48 pm

You don't need to convert the data values to unsigned long in order to be able to upload it to the framebuffer...Just pass the pointer to the array as (u_long*)&YourArray[0] and should work on all variable types provided that the size of the array in bytes meets to what the procedure needs. Also, the PlasmaCLUT array in my demo is generated by a program I wrote in QB64 for the plasma background...Each array element is a SRGB color component (1 bit transparency, 5 bits red, 5 bits green, 5 bits blue).

Variable type size reference:
char - 1 byte.
short - 2 bytes.
int/long/float - 4 bytes.

The same sizes applies to the unsigned counterparts of the variables.


Example pointer passing:

Code: Select all

pClutID = LoadClut((u_long*)&PlasmaCLUT[0], 320, 256);
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

User avatar
bizarro2011
Serious PSXDEV User
Serious PSXDEV User
Posts: 118
Joined: Mar 27, 2012
Location: Brazil

Post by bizarro2011 » May 23rd, 2013, 2:51 am

Here's what I do.

works well.

extern u_long mat0[]; <----- image Tim here. (I do not know create)

tpage[0] = LoadTPage(mat0+0x80, 0, 0, 640, 0, 256,256);
clut[0] = LoadClut(mat0, 0,500);


-------------------------x-----------------------------------
just does not work.

extern unsigned char mat0[]; <------ image Tim here. (know to create)

tpage[0] = LoadTPage(mat0+0x80, 0, 0, 640, 0, 256,256);
clut[0] = LoadClut(mat0, 0,500);

User avatar
LameGuy64
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 388
Joined: Apr 10, 2013
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

Post by LameGuy64 » May 23rd, 2013, 10:41 am

Like I said, pass the array pointers as (u_long*).

So your code from this:

Code: Select all

extern unsigned char mat0[];

tpage[0] = LoadTPage(mat0+0x80, 0, 0, 640, 0, 256,256);
clut[0] = LoadClut(mat0, 0,500);
Should be this:

Code: Select all

extern unsigned char mat0[];

tpage[0] = LoadTPage((u_long*)mat0[0x80], 0, 0, 640, 0, 256,256);
clut[0] = LoadClut((u_long*)mat0[0], 0,500);
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

User avatar
bizarro2011
Serious PSXDEV User
Serious PSXDEV User
Posts: 118
Joined: Mar 27, 2012
Location: Brazil

Post by bizarro2011 » May 23rd, 2013, 11:59 am

error
cast to pointer from integer of different size.

what can be?

User avatar
LameGuy64
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 388
Joined: Apr 10, 2013
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

Post by LameGuy64 » May 23rd, 2013, 4:51 pm

Oops, I've made a mistake on the corrected code...You're supposed to add a & before the array name when passing an array with an index.

So, it should be like this:

Code: Select all

extern unsigned char mat0[];

tpage[0] = LoadTPage((u_long*)&mat0[0x80], 0, 0, 640, 0, 256,256);
clut[0] = LoadClut((u_long*)&mat0[0], 0,500);
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

User avatar
bizarro2011
Serious PSXDEV User
Serious PSXDEV User
Posts: 118
Joined: Mar 27, 2012
Location: Brazil

Post by bizarro2011 » May 24th, 2013, 1:35 pm

Now is working.
thank you.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests