 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Shito
Joined: 11 May 2005 Posts: 21
|
Posted: Tue Jul 19, 2005 5:51 am Post subject: 32 bits texturing problem !! |
|
|
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: | #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: | 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: | 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: | 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 (i=0; i<tmap->width; i++)
for (j=0; j<tmap->height; j++)
{
int tile = tmap->tilemap[i+j*tmap->width] ;
int tilex = (tile-1)%tmap->tiles_width ;
int tiley = (tile-1)/tmap->tiles_width ;
if (tile < 0)
{
// Animated Tile
int atile = -tile-1 ;
if (atile < tmap->anims_number)
{
atile = tmap->animated_tiles[atile].frames[tmap->animated_tiles[atile].curr_frame] ;
tilex = (atile-1)%tmap->tiles_width ;
tiley = (atile-1)/tmap->tiles_width ;
vertices[index<<1].u = tilex*tmap->frame_width; vertices[index<<1].v = tiley*tmap->frame_height;
vertices[index<<1].x = SCREENWIDTH-(tmap->y>>16)-j*tmap->frame_width; vertices[index<<1].y = (tmap->x>>16)+i*tmap->frame_height; vertices[index<<1].z = 0;
vertices[(index<<1)+1].u = vertices[index<<1].u+tmap->frame_width; vertices[(index<<1)+1].v = vertices[index<<1].v+tmap->frame_height;
vertices[(index<<1)+1].x = vertices[index<<1].x-tmap->frame_height; vertices[(index<<1)+1].y = vertices[index<<1].y+tmap->frame_width; vertices[(index<<1)+1].z = 0;
index++ ;
nbprim++ ;
}
}
else if (tile != 0)
{
vertices[index<<1].u = tilex*tmap->frame_width; vertices[index<<1].v = tiley*tmap->frame_height;
vertices[index<<1].x = SCREENWIDTH-(tmap->y>>16)-j*tmap->frame_width; vertices[index<<1].y = (tmap->x>>16)+i*tmap->frame_height; vertices[index<<1].z = 0;
vertices[(index<<1)+1].u = vertices[index<<1].u+tmap->frame_width; vertices[(index<<1)+1].v = vertices[index<<1].v+tmap->frame_height;
vertices[(index<<1)+1].x = vertices[index<<1].x-tmap->frame_height; vertices[(index<<1)+1].y = vertices[index<<1].y+tmap->frame_width; vertices[(index<<1)+1].z = 0;
index++ ;
nbprim++ ;
}
}
sceGuDrawArray(GU_SPRITES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_2D,2 * nbprim,0,vertices);
} |
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 ?? ^^ |
|
| Back to top |
|
 |
Shito
Joined: 11 May 2005 Posts: 21
|
Posted: Tue Jul 19, 2005 6:40 am Post subject: |
|
|
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. :/ |
|
| Back to top |
|
 |
Shito
Joined: 11 May 2005 Posts: 21
|
Posted: Tue Jul 19, 2005 6:57 am Post subject: |
|
|
(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 ?? |
|
| Back to top |
|
 |
sexdwarf
Joined: 14 Jul 2005 Posts: 34
|
Posted: Tue Jul 19, 2005 7:01 am Post subject: |
|
|
| 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... |
|
| Back to top |
|
 |
Shito
Joined: 11 May 2005 Posts: 21
|
Posted: Tue Jul 19, 2005 7:23 am Post subject: |
|
|
Well, pretty much what I posted up here, with
| Code: | struct Vertex
{
float u, v;
unsigned int color;
float x, y, z;
}; |
as my vertex structure, and
| Code: | static unsigned int __attribute__((aligned(32))) tiles01_image[] =
{ ... |
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. ^^ |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|