problem with sceGumUpdateMatrix

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

Moderators: cheriff, TyRaNiD

Post Reply
bobbywhisky
Posts: 1
Joined: Mon Jun 09, 2008 12:58 pm

problem with sceGumUpdateMatrix

Post by bobbywhisky »

Hi all,

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&#40; "Lesson10", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40; THREAD_ATTR_USER &#41;;

int 	fps = 0;			//	For calculating fps
char 	fpsDisplay&#91; 20 &#93;;
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&#91; 5 &#93; =
&#123;
	GU_COLOR&#40; 1.0f, 0.0f, 0.0f, 0.0f &#41;,
	GU_COLOR&#40; 1.0f, 0.5f, 0.0f, 0.0f &#41;,
	GU_COLOR&#40; 1.0f, 1.0f, 0.0f, 0.0f &#41;,
	GU_COLOR&#40; 0.0f, 1.0f, 0.0f, 0.0f &#41;,
	GU_COLOR&#40; 0.0f, 1.0f, 1.0f, 0.0f &#41;
&#125;;

static unsigned int topColor&#91; 5 &#93; =
&#123;
	GU_COLOR&#40; 0.5f, 0.0f, 0.0f, 0.0f &#41;,
	GU_COLOR&#40; 0.5f, 0.25f, 0.0f, 0.0f &#41;,
	GU_COLOR&#40; 0.5f, 0.5f, 0.0f, 0.0f &#41;,
	GU_COLOR&#40; 0.0f, 0.5f, 0.0f, 0.0f &#41;,
	GU_COLOR&#40; 0.0f, 0.5f, 0.5f, 0.0f &#41;
&#125;;

CTGATexture	texture;		//	Texture storage

Vertex __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; top&#91;3*2&#93; = 
&#123;
	&#123; 0, 1, 0.0f, 1.0f, 0.0f,-1.0f, 1.0f,-1.0f &#125;,	// Top
	&#123; 1, 1, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f,-1.0f &#125;,
	&#123; 0, 0, 0.0f, 1.0f, 0.0f,-1.0f, 1.0f, 1.0f &#125;,
 
	&#123; 0, 0, 0.0f, 1.0f, 0.0f,-1.0f, 1.0f, 1.0f &#125;,
	&#123; 1, 1, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f,-1.0f &#125;,
	&#123; 1, 0, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f &#125;
&#125;;
 
Vertex __attribute__&#40;&#40;aligned&#40;16&#41;&#41;&#41; box&#91;3*10&#93; = 
&#123;
	&#123; 0, 1, 0.0f,-1.0f, 0.0f,-1.0f,-1.0f, 1.0f &#125;,	// Bottom
	&#123; 1, 1, 0.0f,-1.0f, 0.0f, 1.0f,-1.0f, 1.0f &#125;,
	&#123; 0, 0, 0.0f,-1.0f, 0.0f,-1.0f,-1.0f,-1.0f &#125;,
 
	&#123; 0, 0, 0.0f,-1.0f, 0.0f,-1.0f,-1.0f,-1.0f &#125;,
	&#123; 1, 1, 0.0f,-1.0f, 0.0f, 1.0f,-1.0f, 1.0f &#125;,
	&#123; 1, 0, 0.0f,-1.0f, 0.0f, 1.0f,-1.0f,-1.0f &#125;,
 
	&#123; 0, 1, 0.0f, 0.0f, 1.0f,-1.0f, 1.0f, 1.0f &#125;,	// Front
	&#123; 1, 1, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f &#125;,
	&#123; 0, 0, 0.0f, 0.0f, 1.0f,-1.0f,-1.0f, 1.0f &#125;,
 
	&#123; 0, 0, 0.0f, 0.0f, 1.0f,-1.0f,-1.0f, 1.0f &#125;,
	&#123; 1, 1, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f &#125;,
	&#123; 1, 0, 0.0f, 0.0f, 1.0f, 1.0f,-1.0f, 1.0f &#125;,
 
	&#123; 0, 1, 0.0f, 0.0f,-1.0f,-1.0f,-1.0f,-1.0f &#125;,	// Back
	&#123; 1, 1, 0.0f, 0.0f,-1.0f, 1.0f,-1.0f,-1.0f &#125;,
	&#123; 0, 0, 0.0f, 0.0f,-1.0f,-1.0f, 1.0f,-1.0f &#125;,
 
	&#123; 0, 0, 0.0f, 0.0f,-1.0f,-1.0f, 1.0f,-1.0f &#125;,
	&#123; 1, 1, 0.0f, 0.0f,-1.0f, 1.0f,-1.0f,-1.0f &#125;,
	&#123; 1, 0, 0.0f, 0.0f,-1.0f, 1.0f, 1.0f,-1.0f &#125;,
 
	&#123; 0, 1,-1.0f, 0.0f, 0.0f,-1.0f, 1.0f,-1.0f &#125;,	// Left
	&#123; 1, 1,-1.0f, 0.0f, 0.0f,-1.0f, 1.0f, 1.0f &#125;,
	&#123; 0, 0,-1.0f, 0.0f, 0.0f,-1.0f,-1.0f,-1.0f &#125;,
 
	&#123; 0, 0,-1.0f, 0.0f, 0.0f,-1.0f,-1.0f,-1.0f &#125;,
	&#123; 1, 1,-1.0f, 0.0f, 0.0f,-1.0f, 1.0f, 1.0f &#125;,
	&#123; 1, 0,-1.0f, 0.0f, 0.0f,-1.0f,-1.0f, 1.0f &#125;,
 
	&#123; 0, 1, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f &#125;,	// Right
	&#123; 1, 1, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,-1.0f &#125;,
	&#123; 0, 0, 1.0f, 0.0f, 0.0f, 1.0f,-1.0f, 1.0f &#125;,
 
	&#123; 0, 0, 1.0f, 0.0f, 0.0f, 1.0f,-1.0f, 1.0f &#125;,
	&#123; 1, 1, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,-1.0f &#125;,
	&#123; 1, 0, 1.0f, 0.0f, 0.0f, 1.0f,-1.0f,-1.0f &#125;
 
&#125;;

//	Main fucntion
/******************************************************************************/
int main&#40; int argc, char **argv &#41;
&#123;
	fbp0 	= 0;
	dList 	= malloc&#40; 1536 &#41;;
	boxList = malloc&#40; 256 &#41;;
	topList = malloc&#40; 64 &#41;;
	sprintf&#40; fpsDisplay, "FPS&#58; calculating"	&#41;;
	
	sceRtcGetCurrentTick&#40; &fpsTickLast &#41;;
	tickResolution = sceRtcGetTickResolution&#40;&#41;;
	
	CTimer timer;
	SceCtrlData	pad;
	
	SetupCallbacks&#40;&#41;;
	pspDebugScreenInit&#40;&#41;;
	
	pspDebugScreenPrintf&#40; fpsDisplay &#41;;

	if&#40; !texture.LoadTGA&#40; "Cube.tga" &#41; &#41;
	&#123;
		sceKernelExitGame&#40;&#41;;	
	&#125;
	texture.Swizzle&#40;&#41;;
	
	//	Starting Gu
	InitGU&#40;&#41;;
	SetupProjection&#40;&#41;;
	
	//	Construction of the display list
	BuildLists&#40;&#41;;
	
	//	Main loop
	while&#40; !exiting &#41;
	&#123;
		sceCtrlPeekBufferPositive&#40; &pad, 1&#41;;
		if&#40; pad.Buttons & PSP_CTRL_UP &#41;
		&#123;
			xRot -= 1.0f * dt;	
		&#125;
		if&#40; pad.Buttons & PSP_CTRL_DOWN &#41;
		&#123;
			xRot += 1.0f * dt;
		&#125;
		if&#40; pad.Buttons & PSP_CTRL_LEFT &#41;
		&#123;
			yRot -= 1.0f * dt;
		&#125;
		if&#40; pad.Buttons & PSP_CTRL_RIGHT &#41;
		&#123;
			yRot += 1.0f * dt;
		&#125;
		
		dt = timer.GetDeltaTime&#40;&#41;;
		DrawScene&#40;&#41;;
		FPS&#40;&#41;;
		
		fbp0 = sceGuSwapBuffers&#40;&#41;;
	&#125;
	
	//	Kill Graphic System
	sceGuTerm&#40;&#41;;
	
	//	Free Memory
	free&#40; dList &#41;;
	free&#40; boxList &#41;;
	free&#40; topList &#41;;
	
	//	Quit Application
	sceKernelExitGame&#40;&#41;;
	
	//	Never Get Here
	return 0;
&#125;

//	Calculating the frame rendered per second
void FPS&#40; void &#41;
&#123;
	fps++;
	sceRtcGetCurrentTick&#40; &fpsTickNow &#41;;
	if&#40; &#40; &#40; fpsTickNow - fpsTickLast &#41; / &#40; &#40; float &#41;tickResolution &#41; &#41; >= 1.0f &#41;
	&#123;
		fpsTickLast = fpsTickNow;
		sprintf&#40; fpsDisplay, "FPS&#58; %i", &#40; int &#41;fps &#41;;
		fps = 0;
	&#125;
	pspDebugScreenSetOffset&#40; &#40; int &#41;fbp0 &#41;;
	pspDebugScreenSetXY&#40; 0, 0 &#41;;
	pspDebugScreenPrintf&#40; fpsDisplay &#41;;
&#125;

//	Initialisation of the Graphic System
void InitGU&#40; void &#41;
&#123;
	//	Init GU
	sceGuInit&#40;&#41;;
	sceGuStart&#40; GU_DIRECT, dList &#41;;
	
	//	Set Buffers
	sceGuDrawBuffer&#40; GU_PSM_8888, fbp0, BUF_WIDTH &#41;;
	sceGuDispBuffer&#40; SCR_WIDTH, SCR_HEIGHT, &#40; void* &#41;0x88000, BUF_WIDTH &#41;;
	sceGuDepthBuffer&#40; &#40; void* &#41;0x110000, BUF_WIDTH &#41;;
	
	sceGuOffset&#40; 2048 - &#40; SCR_WIDTH / 2 &#41;, 2048 - &#40; SCR_HEIGHT / 2 &#41; &#41;;
	sceGuViewport&#40; 2048, 2048, SCR_WIDTH, SCR_HEIGHT &#41;;
	sceGuDepthRange&#40; 65535, 0 &#41;;
	
	//	Set Render States
	sceGuScissor&#40; 0, 0, SCR_WIDTH, SCR_HEIGHT &#41;;
	sceGuEnable&#40; GU_SCISSOR_TEST &#41;;
	sceGuDepthFunc&#40; GU_GEQUAL &#41;;
	sceGuEnable&#40; GU_DEPTH_TEST &#41;;
	sceGuFrontFace&#40; GU_CW &#41;;
	sceGuEnable&#40; GU_CULL_FACE &#41;;	
	sceGuShadeModel&#40; GU_SMOOTH &#41;;
	sceGuEnable&#40; GU_CLIP_PLANES &#41;;
	sceGuEnable&#40; GU_TEXTURE_2D &#41;;
	sceGuEnable&#40; GU_LIGHTING &#41;;
	sceGuEnable&#40; GU_LIGHT0 &#41;;
	
	//	Setup Texture
	//	32-bit image, if we swizzled the texture will return true, otherwise false
	sceGuTexMode&#40; GU_PSM_8888, 0, 0, texture.Swizzled&#40;&#41; &#41;;
	sceGuTexFunc&#40; GU_TFX_MODULATE, GU_TCC_RGB &#41;;
	sceGuTexFilter&#40; GU_LINEAR_MIPMAP_LINEAR, GU_LINEAR_MIPMAP_LINEAR &#41;;
	sceGuTexScale&#40; 1.0f, 1.0f &#41;;
	sceGuTexOffset&#40; 0.0f, 0.0f &#41;;
	
	//	Light Property
	ScePspFVector3 lightPosition = &#123; 0.0f, 0.0f, 2.0f &#125;;
	sceGuLight&#40; 0, GU_POINTLIGHT, GU_AMBIENT_AND_DIFFUSE, &lightPosition &#41;;
	sceGuLightColor&#40; 0, GU_AMBIENT, GU_COLOR&#40; 0.25f, 0.25f, 0.25f, 1.0f &#41; &#41;;
	sceGuLightColor&#40; 0, GU_DIFFUSE, GU_COLOR&#40; 1.0f, 1.0f, 1.0f, 1.0f &#41; &#41;;
	
	sceGuFinish&#40;&#41;;
	sceGuSync&#40; 0, 0 &#41;;
	
	sceDisplayWaitVblankStart&#40;&#41;;
	sceGuDisplay&#40; GU_TRUE &#41;;
&#125;

//	Setup the projection
void SetupProjection&#40; void &#41;
&#123;
	//	Setup matrices for the triangle
	sceGumMatrixMode&#40; GU_PROJECTION &#41;;
	sceGumLoadIdentity&#40;&#41;;
	sceGumPerspective&#40; 75.0f, 16.0f / 9.0f, 0.5f, 1000.0f &#41;;
	
	sceGumMatrixMode&#40; GU_VIEW &#41;;
	sceGumLoadIdentity&#40;&#41;;
	
	//	Each clear call this color
	sceGuClearColor&#40; GU_COLOR&#40; 0.0f, 0.0f, 0.0f, 1.0f &#41; &#41;;
	sceGuClearDepth&#40; 0 &#41;;
&#125;

//	The Scene to Draw With Star
void DrawScene&#40; void &#41;
&#123;
	sceGuStart&#40; GU_DIRECT, dList &#41;;

	//	Clear Screen
	sceGuClear&#40; GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT &#41;;
	sceGumMatrixMode&#40; GU_MODEL &#41;;
	
	sceGuTexImage&#40; 0, texture.Width&#40;&#41;, texture.Height&#40;&#41;, texture.Width&#40;&#41;,
		texture.Image&#40;&#41; &#41;;
		
	for&#40; int j = 1; j < 6; j++ &#41;
	&#123;
		for&#40; int i = 0; i < j; i++ &#41;
		&#123;
			sceGumLoadIdentity&#40;&#41;;
			
			&#123;
				ScePspFVector3 move = &#123; 1.4f + &#40; float&#40; i &#41; * 2.8f &#41; - &#40; float&#40; j &#41; 
					* 1.4f&#41;, &#40; &#40; 6.0f - float&#40; j &#41; &#41; * 2.4f &#41; - 7.0f, -10.0f &#125;;
					
				ScePspFVector3 rot = &#123; &#40; 45.0f - &#40; 2.0f * j &#41; &#41; * &#40; PI / 180.0f &#41; +
					xRot, &#40; 45.0f &#41; * &#40; PI / 180.0f &#41; + yRot, 0.0f &#125;;
			
				sceGumTranslate&#40; &move &#41;;
				sceGumRotateXYZ&#40; &rot &#41;;
			&#125;
			sceGumUpdateMatrix&#40;&#41;;
			
			sceGuColor&#40; boxColor&#91; j - 1 &#93; &#41;;
			sceGuCallList&#40; boxList &#41;;
			sceGuColor&#40; topColor&#91; j - 1 &#93; &#41;;
			sceGuCallList&#40; topList &#41;;
		&#125;
	&#125;

	sceGuFinish&#40;&#41;;
	sceGuSync&#40; 0, 0 &#41;;
&#125;

void BuildLists&#40; void &#41;
&#123;
	sceGuStart&#40; GU_CALL, boxList &#41;;
	
	sceGumDrawArray&#40; GU_TRIANGLES, GU_TEXTURE_32BITF | GU_NORMAL_32BITF | 
		GU_VERTEX_32BITF | GU_TRANSFORM_3D, 3 * 10, 0, box &#41;;
		
	sceGuFinish&#40;&#41;;
	
	sceGuStart&#40; GU_CALL, topList &#41;;
	
	sceGumDrawArray&#40; GU_TRIANGLES, GU_TEXTURE_32BITF | GU_NORMAL_32BITF | 
		GU_VERTEX_32BITF | GU_TRANSFORM_3D, 3 * 2, 0, top &#41;;
		
	sceGuFinish&#40;&#41;;
&#125;

Thanks!
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

Don't really have the time to read/understand/fix the whole listing...just find a serial cable, connect PSP to PC, open a terminal on PC side and insert pspDebugSioPrint into code every now and then. So, run your program and see from terminal WHEN your app stops working. It could be a good starting point, indeed. However 95% of freezes comes from writing into memory at the wrong address.
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

Give yourself a bigger display list to work with...

Code: Select all

dList    = malloc&#40; 1536 &#41;;
Is tiny.

Remove all the FPS stuff completely from your code. I've had others come to me with problems because of it.
Post Reply