I'm currently trying to draw a simple HUD over the top of a project I am doing, unfortunatly the images are not drawn correctly. Rather than the images being drawn, a flat pink colored rectangle with correct dimensions are showing up in te correct position. I'm pretty sure it's an initialisation problem but cannot seem to get a good combination.
I have included code for the parts of the project that are involved below, it is all contained within a guStart/Finish block:
The blitting function:
Note: before this function is called depth testing is disabled with "sceGuDisable(GU_DEPTH_TEST);". It is later re-enabled.
void blitTexture2( Texture* source, int x, int y)
{
sceGuTexImage( 0, source->width, source->height, source->width, source->data);
Vertex* vertices = (Vertex*)sceGuGetMemory(2 * sizeof(Vertex));
vertices[0].u = 0.0;
vertices[0].v = 0.0;
vertices[0].x = x;
vertices[0].y = y;
vertices[0].z = 0;
vertices[1].u = 1.0;
vertices[1].v = 1.0;
vertices[1].x = x + source->width;
vertices[1].y = y + source->height;
vertices[1].z = 0;
sceGuDrawArray( GU_SPRITES, GU_TEXTURE_32BITF | GU_TEXTURE_32BITF | GU_TRANSFORM_2D, 2, 0, vertices);
}
The initialisation code:
// Init GU
sceGuInit();
sceGuStart( GU_DIRECT, display_list );
// Allocate Buffers
frame_buffer_0 = vrelptr( valloc(FRAME_BUFFER_SIZE));
frame_buffer_1 = vrelptr( valloc(FRAME_BUFFER_SIZE));
depth_buffer = vrelptr( valloc(FRAME_BUFFER_SIZE / 2));
current_frame_buffer = frame_buffer_0;
// Set Buffers
sceGuDrawBuffer( GU_PSM_8888, frame_buffer_0, LINE_WIDTH );
sceGuDispBuffer( SCREEN_WIDTH, SCREEN_HEIGHT, frame_buffer_1, LINE_WIDTH);
sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
sceGuDepthBuffer( depth_buffer, LINE_WIDTH);
sceGuOffset( 2048 - (SCREEN_WIDTH/2), 2048 - (SCREEN_HEIGHT/2));
sceGuViewport( 2048, 2048, SCREEN_WIDTH, SCREEN_HEIGHT);
sceGuDepthRange(0xc350,0x2710);
// Set Render States
sceGuScissor( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
sceGuEnable( GU_SCISSOR_TEST );
sceGuDepthFunc( GU_GEQUAL );
sceGuAlphaFunc(GU_GREATER, 0, 0xff);
sceGuEnable(GU_ALPHA_TEST);
sceGuEnable( GU_DEPTH_TEST );
sceGuFrontFace( GU_CW );
sceGuEnable( GU_CULL_FACE );
sceGuShadeModel( GU_SMOOTH );
sceGuEnable( GU_CLIP_PLANES );
sceGuEnable( GU_TEXTURE_2D );
// 32-bit textures, assuming all are swizzled
sceGuTexMode( GU_PSM_8888, 0, 0, GU_TRUE);
sceGuTexFunc( GU_TFX_DECAL, GU_TCC_RGB ); // Modulate the color of the image
sceGuTexFilter( GU_LINEAR, GU_LINEAR ); // Linear filtering
sceGuTexScale( 1.0f, 1.0f ); // No scaling
sceGuTexOffset( 0.0f, 0.0f );
sceGuAmbientColor(0xffffffff);
sceGuEnable(GU_BLEND);
sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
gumInit();
sceGuFinish();
sceDisplayWaitVblankStart();
sceGuSync(0,0);
sceGuDisplay(GU_TRUE);
The projection init: (Unsure if this is related)
static void projectionInit()
{
sceGuStart( GU_DIRECT, display_list );
// setup matrices for the triangle
sceGumMatrixMode(GU_PROJECTION);
sceGumLoadIdentity();
sceGumPerspective( 45.0f, 16.0f/9.0f, 0.8f, 100.0f);
sceGumMatrixMode(GU_VIEW);
sceGumLoadIdentity();
sceGuClearColor( GU_COLOR( 0.0f, 0.0f, 0.0f, 1.0f));
sceGuClearDepth(0);
sceGuFinish();
sceGuSync( 0, 0);
}
I haven't got code in place to grab a screenshot but if one is required I set some up and get one.
I have searched the forum and while there has been similair problems, none have been exactly the same.
Thanks.
Jono.