First, I want to say that I have already read about this problem in the forum. I tried to fix it but with no success.
What I'm trying to do is the lesson11 of pspgu of PSP-PROGRAMMING about display list. I think my app freeze when I try to do sceGumUpdateMatrix because when I comment it, the app run but don't display my polygons. Maybe something is wrong in the BuildLists function but I'm familiar with list in openGL and all seems ok. Please take a look at the source code and give me a feedback, It will be appreciated.
Code: Select all
// Includes
#include "main.h"
#include <malloc.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <pspgu.h>
#include <pspgum.h>
#include <pspctrl.h>
#include "CTimer.h"
#include "TGALoader.h"
// PSP info
PSP_MODULE_INFO( "Lesson10", 0, 1, 1);
PSP_MAIN_THREAD_ATTR( THREAD_ATTR_USER );
int fps = 0; // For calculating fps
char fpsDisplay[ 20 ];
void *dList; // Display List used by sceGUStart
void *boxList; // Storage for the Box display list
void *topList; // Storage for the Top display list
void *fbp0; // Frame buffer
u32 tickResolution;
u64 fpsTickNow;
u64 fpsTickLast;
bool exiting = false;
float xRot = 0.0f;
float yRot = 0.0f;
float dt; // For time based animation
static unsigned int boxColor[ 5 ] =
{
GU_COLOR( 1.0f, 0.0f, 0.0f, 0.0f ),
GU_COLOR( 1.0f, 0.5f, 0.0f, 0.0f ),
GU_COLOR( 1.0f, 1.0f, 0.0f, 0.0f ),
GU_COLOR( 0.0f, 1.0f, 0.0f, 0.0f ),
GU_COLOR( 0.0f, 1.0f, 1.0f, 0.0f )
};
static unsigned int topColor[ 5 ] =
{
GU_COLOR( 0.5f, 0.0f, 0.0f, 0.0f ),
GU_COLOR( 0.5f, 0.25f, 0.0f, 0.0f ),
GU_COLOR( 0.5f, 0.5f, 0.0f, 0.0f ),
GU_COLOR( 0.0f, 0.5f, 0.0f, 0.0f ),
GU_COLOR( 0.0f, 0.5f, 0.5f, 0.0f )
};
CTGATexture texture; // Texture storage
Vertex __attribute__((aligned(16))) top[3*2] =
{
{ 0, 1, 0.0f, 1.0f, 0.0f,-1.0f, 1.0f,-1.0f }, // Top
{ 1, 1, 0.0f, 1.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 0.0f, 0.0f,-1.0f, 1.0f, 1.0f,-1.0f },
{ 0, 1,-1.0f, 0.0f, 0.0f,-1.0f, 1.0f,-1.0f }, // Left
{ 1, 1,-1.0f, 0.0f, 0.0f,-1.0f, 1.0f, 1.0f },
{ 0, 0,-1.0f, 0.0f, 0.0f,-1.0f,-1.0f,-1.0f },
{ 0, 0,-1.0f, 0.0f, 0.0f,-1.0f,-1.0f,-1.0f },
{ 1, 1,-1.0f, 0.0f, 0.0f,-1.0f, 1.0f, 1.0f },
{ 1, 0,-1.0f, 0.0f, 0.0f,-1.0f,-1.0f, 1.0f },
{ 0, 1, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f }, // Right
{ 1, 1, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,-1.0f },
{ 0, 0, 1.0f, 0.0f, 0.0f, 1.0f,-1.0f, 1.0f },
{ 0, 0, 1.0f, 0.0f, 0.0f, 1.0f,-1.0f, 1.0f },
{ 1, 1, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,-1.0f },
{ 1, 0, 1.0f, 0.0f, 0.0f, 1.0f,-1.0f,-1.0f }
};
// Main fucntion
/******************************************************************************/
int main( int argc, char **argv )
{
fbp0 = 0;
dList = malloc( 1536 );
boxList = malloc( 256 );
topList = malloc( 64 );
sprintf( fpsDisplay, "FPS: calculating" );
sceRtcGetCurrentTick( &fpsTickLast );
tickResolution = sceRtcGetTickResolution();
CTimer timer;
SceCtrlData pad;
SetupCallbacks();
pspDebugScreenInit();
pspDebugScreenPrintf( fpsDisplay );
if( !texture.LoadTGA( "Cube.tga" ) )
{
sceKernelExitGame();
}
texture.Swizzle();
// Starting Gu
InitGU();
SetupProjection();
// Construction of the display list
BuildLists();
// Main loop
while( !exiting )
{
sceCtrlPeekBufferPositive( &pad, 1);
if( pad.Buttons & PSP_CTRL_UP )
{
xRot -= 1.0f * dt;
}
if( pad.Buttons & PSP_CTRL_DOWN )
{
xRot += 1.0f * dt;
}
if( pad.Buttons & PSP_CTRL_LEFT )
{
yRot -= 1.0f * dt;
}
if( pad.Buttons & PSP_CTRL_RIGHT )
{
yRot += 1.0f * dt;
}
dt = timer.GetDeltaTime();
DrawScene();
FPS();
fbp0 = sceGuSwapBuffers();
}
// Kill Graphic System
sceGuTerm();
// Free Memory
free( dList );
free( boxList );
free( topList );
// Quit Application
sceKernelExitGame();
// Never Get Here
return 0;
}
// Calculating the frame rendered per second
void FPS( void )
{
fps++;
sceRtcGetCurrentTick( &fpsTickNow );
if( ( ( fpsTickNow - fpsTickLast ) / ( ( float )tickResolution ) ) >= 1.0f )
{
fpsTickLast = fpsTickNow;
sprintf( fpsDisplay, "FPS: %i", ( int )fps );
fps = 0;
}
pspDebugScreenSetOffset( ( int )fbp0 );
pspDebugScreenSetXY( 0, 0 );
pspDebugScreenPrintf( fpsDisplay );
}
// Initialisation of the Graphic System
void InitGU( void )
{
// Init GU
sceGuInit();
sceGuStart( GU_DIRECT, dList );
// Set Buffers
sceGuDrawBuffer( GU_PSM_8888, fbp0, BUF_WIDTH );
sceGuDispBuffer( SCR_WIDTH, SCR_HEIGHT, ( void* )0x88000, BUF_WIDTH );
sceGuDepthBuffer( ( void* )0x110000, BUF_WIDTH );
sceGuOffset( 2048 - ( SCR_WIDTH / 2 ), 2048 - ( SCR_HEIGHT / 2 ) );
sceGuViewport( 2048, 2048, SCR_WIDTH, SCR_HEIGHT );
sceGuDepthRange( 65535, 0 );
// Set Render States
sceGuScissor( 0, 0, SCR_WIDTH, SCR_HEIGHT );
sceGuEnable( GU_SCISSOR_TEST );
sceGuDepthFunc( GU_GEQUAL );
sceGuEnable( GU_DEPTH_TEST );
sceGuFrontFace( GU_CW );
sceGuEnable( GU_CULL_FACE );
sceGuShadeModel( GU_SMOOTH );
sceGuEnable( GU_CLIP_PLANES );
sceGuEnable( GU_TEXTURE_2D );
sceGuEnable( GU_LIGHTING );
sceGuEnable( GU_LIGHT0 );
// Setup Texture
// 32-bit image, if we swizzled the texture will return true, otherwise false
sceGuTexMode( GU_PSM_8888, 0, 0, texture.Swizzled() );
sceGuTexFunc( GU_TFX_MODULATE, GU_TCC_RGB );
sceGuTexFilter( GU_LINEAR_MIPMAP_LINEAR, GU_LINEAR_MIPMAP_LINEAR );
sceGuTexScale( 1.0f, 1.0f );
sceGuTexOffset( 0.0f, 0.0f );
// Light Property
ScePspFVector3 lightPosition = { 0.0f, 0.0f, 2.0f };
sceGuLight( 0, GU_POINTLIGHT, GU_AMBIENT_AND_DIFFUSE, &lightPosition );
sceGuLightColor( 0, GU_AMBIENT, GU_COLOR( 0.25f, 0.25f, 0.25f, 1.0f ) );
sceGuLightColor( 0, GU_DIFFUSE, GU_COLOR( 1.0f, 1.0f, 1.0f, 1.0f ) );
sceGuFinish();
sceGuSync( 0, 0 );
sceDisplayWaitVblankStart();
sceGuDisplay( GU_TRUE );
}
// Setup the projection
void SetupProjection( void )
{
// Setup matrices for the triangle
sceGumMatrixMode( GU_PROJECTION );
sceGumLoadIdentity();
sceGumPerspective( 75.0f, 16.0f / 9.0f, 0.5f, 1000.0f );
sceGumMatrixMode( GU_VIEW );
sceGumLoadIdentity();
// Each clear call this color
sceGuClearColor( GU_COLOR( 0.0f, 0.0f, 0.0f, 1.0f ) );
sceGuClearDepth( 0 );
}
// The Scene to Draw With Star
void DrawScene( void )
{
sceGuStart( GU_DIRECT, dList );
// Clear Screen
sceGuClear( GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT );
sceGumMatrixMode( GU_MODEL );
sceGuTexImage( 0, texture.Width(), texture.Height(), texture.Width(),
texture.Image() );
for( int j = 1; j < 6; j++ )
{
for( int i = 0; i < j; i++ )
{
sceGumLoadIdentity();
{
ScePspFVector3 move = { 1.4f + ( float( i ) * 2.8f ) - ( float( j )
* 1.4f), ( ( 6.0f - float( j ) ) * 2.4f ) - 7.0f, -10.0f };
ScePspFVector3 rot = { ( 45.0f - ( 2.0f * j ) ) * ( PI / 180.0f ) +
xRot, ( 45.0f ) * ( PI / 180.0f ) + yRot, 0.0f };
sceGumTranslate( &move );
sceGumRotateXYZ( &rot );
}
sceGumUpdateMatrix();
sceGuColor( boxColor[ j - 1 ] );
sceGuCallList( boxList );
sceGuColor( topColor[ j - 1 ] );
sceGuCallList( topList );
}
}
sceGuFinish();
sceGuSync( 0, 0 );
}
void BuildLists( void )
{
sceGuStart( GU_CALL, boxList );
sceGumDrawArray( GU_TRIANGLES, GU_TEXTURE_32BITF | GU_NORMAL_32BITF |
GU_VERTEX_32BITF | GU_TRANSFORM_3D, 3 * 10, 0, box );
sceGuFinish();
sceGuStart( GU_CALL, topList );
sceGumDrawArray( GU_TRIANGLES, GU_TEXTURE_32BITF | GU_NORMAL_32BITF |
GU_VERTEX_32BITF | GU_TRANSFORM_3D, 3 * 2, 0, top );
sceGuFinish();
}