32 bits texturing problem !!

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Shito
Posts: 21
Joined: Wed May 11, 2005 1:38 am

32 bits texturing problem !!

Post by Shito »

Ok guys, been playing around a bit with the psp sdk for the last days. I've been able to "blit" a 16-bits texture on screen. Now all I wanna do is doing the same, but with a 32-bits texture.
"Ok, easy, just need to convert my bitmap image to 32 bit values now, and let know the psp i'm using a 32 bits texture, mwhahahah".
Well, doesn't work, and obviously I'm missing a very obvious thing there. :/

So, time for the boring part : TEH code !!

Here's my GU initialisation :

Code: Select all

#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
#define PIXEL_SIZE (4) /* change this if you change to another screenmode */
#define FRAME_SIZE (BUF_WIDTH * SCR_HEIGHT * PIXEL_SIZE)
#define ZBUF_SIZE (BUF_WIDTH SCR_HEIGHT * 2) /* zbuffer seems to be 16-bit? */

	sceGuInit();

	// setup
	sceGuStart(GU_DIRECT,list);

	sceGuDrawBuffer(GU_PSM_8888,(void*)0,BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)FRAME_SIZE,BUF_WIDTH);
	sceGuDepthBuffer((void*)(FRAME_SIZE*2),BUF_WIDTH);
	sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
	sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
	sceGuDepthRange(0xc350,0x2710);
	sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuFrontFace(GU_CW);
	sceGuEnable(GU_TEXTURE_2D);
	sceGuEnable(GU_BLEND);
	sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
	sceGuFinish();
	sceGuSync(0,0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);
The paint function :

Code: Select all

void paint(long dt)
{
	sceGuStart(GU_DIRECT,list);

		// clear screen
		sceGuClearColor(0xff000000);
		sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

		// setup blend-mode
		sceGuBlendFunc(GU_ADD,GU_SRC_ALPHA,GU_ONE_MINUS_SRC_ALPHA,0,0);

		sceGuColor(0xffffffff);

		// Setup and render Tile Map
		setupTileMapTexture(&tilemap) ;
		bltTileMapRot90(&tilemap) ;

		// FPS
		pspDebugScreenSetXY(0,0);
		pspDebugScreenPrintf("fps=%ld", 1000/dt);

	sceGuFinish();
	sceGuSync(0,0);

//	sceDisplayWaitVblankStart();
	sceGuSwapBuffers();
}
Initialisation of the tilemap texture :

Code: Select all

void setupTileMapTexture(tilemap_t* tmap)
{
	sceGuTexMode(GU_PSM_8888,0,0,0);
	sceGuTexImage(0,tmap->image_width,tmap->image_height,tmap->image_width,(tmap->image));
	sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGBA);
	sceGuTexFilter(GU_NEAREST,GU_NEAREST);
	sceGuTexScale(1,1);
	sceGuTexOffset(0,0);
}
And finally, the tilemap drawing function :

Code: Select all

void bltTileMapRot90(tilemap_t* tmap)
{
	int i,j, index, nbprim ;
	struct Vertex* vertices = (struct Vertex*)sceGuGetMemory(2 * tmap->width * tmap->height * sizeof(struct Vertex));

	index = 0 ;
	nbprim = 0 ;
	for &#40;i=0; i<tmap->width; i++&#41;
		for &#40;j=0; j<tmap->height; j++&#41;
		&#123;
			int tile = tmap->tilemap&#91;i+j*tmap->width&#93; ;
			int tilex = &#40;tile-1&#41;%tmap->tiles_width ;
			int tiley = &#40;tile-1&#41;/tmap->tiles_width ;

			if &#40;tile < 0&#41;
			&#123;
				// Animated Tile
				int atile = -tile-1 ;
				
				if &#40;atile < tmap->anims_number&#41;
				&#123;
					atile = tmap->animated_tiles&#91;atile&#93;.frames&#91;tmap->animated_tiles&#91;atile&#93;.curr_frame&#93; ;
					tilex = &#40;atile-1&#41;%tmap->tiles_width ;
					tiley = &#40;atile-1&#41;/tmap->tiles_width ;

					vertices&#91;index<<1&#93;.u = tilex*tmap->frame_width; vertices&#91;index<<1&#93;.v = tiley*tmap->frame_height;
					vertices&#91;index<<1&#93;.x = SCREENWIDTH-&#40;tmap->y>>16&#41;-j*tmap->frame_width; vertices&#91;index<<1&#93;.y = &#40;tmap->x>>16&#41;+i*tmap->frame_height; vertices&#91;index<<1&#93;.z = 0;
					vertices&#91;&#40;index<<1&#41;+1&#93;.u = vertices&#91;index<<1&#93;.u+tmap->frame_width; vertices&#91;&#40;index<<1&#41;+1&#93;.v = vertices&#91;index<<1&#93;.v+tmap->frame_height;
					vertices&#91;&#40;index<<1&#41;+1&#93;.x = vertices&#91;index<<1&#93;.x-tmap->frame_height; vertices&#91;&#40;index<<1&#41;+1&#93;.y = vertices&#91;index<<1&#93;.y+tmap->frame_width; vertices&#91;&#40;index<<1&#41;+1&#93;.z = 0;
					index++ ;
					nbprim++ ;
				&#125;
			&#125;
			else if &#40;tile != 0&#41;
			&#123;
				vertices&#91;index<<1&#93;.u = tilex*tmap->frame_width; vertices&#91;index<<1&#93;.v = tiley*tmap->frame_height;
				vertices&#91;index<<1&#93;.x = SCREENWIDTH-&#40;tmap->y>>16&#41;-j*tmap->frame_width; vertices&#91;index<<1&#93;.y = &#40;tmap->x>>16&#41;+i*tmap->frame_height; vertices&#91;index<<1&#93;.z = 0;
				vertices&#91;&#40;index<<1&#41;+1&#93;.u = vertices&#91;index<<1&#93;.u+tmap->frame_width; vertices&#91;&#40;index<<1&#41;+1&#93;.v = vertices&#91;index<<1&#93;.v+tmap->frame_height;
				vertices&#91;&#40;index<<1&#41;+1&#93;.x = vertices&#91;index<<1&#93;.x-tmap->frame_height; vertices&#91;&#40;index<<1&#41;+1&#93;.y = vertices&#91;index<<1&#93;.y+tmap->frame_width; vertices&#91;&#40;index<<1&#41;+1&#93;.z = 0;
				index++ ;
				nbprim++ ;
			&#125;
		&#125;

	sceGuDrawArray&#40;GU_SPRITES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_2D,2 * nbprim,0,vertices&#41;;
&#125;
Now all i can get with this is a black screen, but going the same speed as when I blit my 16-bits tilemap, so I guess it *is* rendering something, and I just forgot a stupid flag or something somewhere.
Can anyone see my big and shamefull and evident mistake ?? ^^
Shito
Posts: 21
Joined: Wed May 11, 2005 1:38 am

Post by Shito »

Ok, got it displaying something, just needed to make my u,v,x,y and z floats in my vertex structure, silly me !!
The colors are way wrong, though.
Do you guys know if in 32 bits the format is ARGB ?
Would look weird as it seems to be ABGR in 16 bits. :/
Shito
Posts: 21
Joined: Wed May 11, 2005 1:38 am

Post by Shito »

(And 3 in a row)
Well, that was it, ARGB in 32 bits mode.
Now, why is it working in ABGR in 16 bits ?? °__°
What the fuck am i not understanding there ??
sexdwarf
Posts: 34
Joined: Thu Jul 14, 2005 12:07 am

Post by sexdwarf »

Shito wrote:(And 3 in a row)
Well, that was it, ARGB in 32 bits mode.
Now, why is it working in ABGR in 16 bits ?? °__°
What the fuck am i not understanding there ??
hehe wish i could answer that question - any chance of you sharing the working code?
...isn't it nice, sugar and spice...
...luring disco dollies to a life of vice...
Shito
Posts: 21
Joined: Wed May 11, 2005 1:38 am

Post by Shito »

Well, pretty much what I posted up here, with

Code: Select all

struct Vertex
&#123;
	float u, v;
	unsigned int color;
	float x, y, z;
&#125;;
as my vertex structure, and

Code: Select all

static unsigned int __attribute__&#40;&#40;aligned&#40;32&#41;&#41;&#41; tiles01_image&#91;&#93; = 
&#123; ...
as my image.

Might get working on a little game from here, be sure I'll make the sources available if I ever get to something. ^^
Post Reply