/* Simple thread */ int main(int argc, char **argv) { SetupCallbacks(); triLogInit(); triInit( GU_PSM_8888, 1 ); tri3dInit(); triInputInit(); // FIXME: This is not the right way to do as it will cause the particle manager to try and free pointers from inside the array partSys = triMalloc( sizeof(triParticleSystem)*4 ); partEm = triMalloc( sizeof(triParticleEmitter)*4 ); triS32 PsID0 = triParticleManagerLoadScript( "watersprinkle.txt" ); triParticleSystemConstructor( &partSys[0] ); triParticleSystemConstructor( &partSys[1] ); triParticleSystemConstructor( &partSys[2] ); partSys[0].render = renderParticle; partSys[2].renderMode = GU_TRIANGLES; partSys[2].blendMode = TRI_BLEND_MODE_ALPHA; //triParticleSystemConstructor( &partSys[3] ); //partSys[3].renderMode = GU_TRIANGLES; triParticleEmitterConstructor( &partEm[0], TRI_EMITTER_SPRINKLE ); triParticleEmitterConstructor( &partEm[1], TRI_EMITTER_FIRE ); triParticleEmitterConstructor( &partEm[2], TRI_EMITTER_SMOKE ); //triParticleEmitterConstructor( &partEm[3], TRI_EMITTER_EXPLOSION ); partEm[0].pos.z = -10.0f; partEm[0].pos.x = -5.0f; partEm[0].velRand.w = 1.f; partEm[0].max = 64; partEm[1].pos.z = -10.0f; partEm[1].pos.x = 5.0f; partEm[1].vel.y += 1.5f; partEm[1].binding = 0.0f; // particles are bound to the emitter partEm[1].loosen = 0.85f; // particles loosen from the emitter with age partEm[1].life = 0.8f; partEm[1].growth = -0.7f/partEm[1].life; partEm[1].max = 512; partEm[1].rate = partEm[1].max/(partEm[1].life*1.2); partEm[1].lastpos = partEm[1].pos; partEm[1].vortexRange = 0.6f; partEm[1].vortexDirRand = 2.5f; partEm[2].pos.z -= 3.0; partEm[2].pos.x += 2.0; partEm[2].maxVortex = 16; partEm[2].rateVortex = 2; partEm[2].max = 256; partEm[2].life = 10.f; partEm[2].lifetime = 0; partEm[2].vortexDir = 0.f; partEm[2].vortexDirRand = 1.2f; partEm[2].vortexRange = 0.5f; partEm[2].rate = partEm[2].max/(partEm[2].life); //partEm[3].pos.z -= 5.0; partSys[1].textureID = triTextureLoad( "sprite.tga" ); partSys[2].textureID = triTextureLoad( "smoke32.tga" ); //triParticleManagerAdd( &partSys[0], &partEm[0] ); triParticleManagerAdd( &partSys[1], &partEm[1] ); triParticleManagerAdd( &partSys[2], &partEm[2] ); //triParticleManagerAdd( &partSys[3], &partEm[3] ); cam = triCameraCreate( 0.0f, 0.0f, -10.0f ); // Do additional setup in immediate mode triBegin(); tri3dPerspective( 45.0f ); sceGuFrontFace(GU_CW); triClear( 0x330000 ); triEnable(TRI_VBLANK); triEnd(); //triSync(); triTimer* frametimer = triTimerCreate(); triTimer* demotimer = triTimerCreate(); triS32 vblank = 0; #define SPEED 0.05f while (isrunning) { triBegin(); tri3dClear( 1,0,1 ); triInputUpdate (); if (triInputHeld (PSP_CTRL_UP)) { triCameraRotate( cam, SCE_DEG_TO_RAD(3.2f), &triXAxis ); } if (triInputHeld (PSP_CTRL_DOWN)) { triCameraRotate( cam, SCE_DEG_TO_RAD(-3.2f), &triXAxis ); } if (triInputHeld (PSP_CTRL_LEFT)) { triCameraRotate( cam, SCE_DEG_TO_RAD(3.2f), &triYAxis ); } if (triInputHeld (PSP_CTRL_RIGHT)) { triCameraRotate( cam, SCE_DEG_TO_RAD(-3.2f), &triYAxis ); } if (triInputHeld (PSP_CTRL_LTRIGGER)) { triCameraMove( cam, 0.0f, 0.0f, SPEED ); } if (triInputHeld (PSP_CTRL_RTRIGGER)) { triCameraMove( cam, 0.0f, 0.0f, -SPEED ); } if (triInputPressed (PSP_CTRL_SELECT)) { vblank ^= 1; if (vblank) triEnable(TRI_VBLANK); else triDisable(TRI_VBLANK); } triCameraUpdateMatrix( cam ); sceGumMatrixMode (GU_MODEL); sceGumLoadIdentity (); triTimerUpdate(frametimer); triParticleManagerUpdateRender( cam, triTimerGetDeltaTime(frametimer) ); partEm[1].pos.z = sinf( 30*triTimerPeekDeltaTime(demotimer)*SCE_PI/180.0f )*5.0f - 10.0f; partEm[1].pos.x = cosf( 30*triTimerPeekDeltaTime(demotimer)*SCE_PI/180.0f )*5.0f; triFontActivate(0); triFontPrintf( 0, 0, 0xFFFFFFFF, "CAM: dir <%.3f, %.3f, %.3f> pos <%.3f, %.3f, %.3f>\n", cam->dir.x, cam->dir.y, cam->dir.z, cam->pos.x, cam->pos.y, cam->pos.z); triFontPrintf( 0,10, 0xFFFFFFFF, "FPS: %.2f - CPU: %.0f GPU: %.0f\n", triFps(), triCPULoad(), triGPULoad()); /*if (partEm[3].age>=partEm[3].lifetime && (rand()%100<5)) { triParticleEmitterConstructor( &partEm[3], TRI_EMITTER_EXPLOSION ); partEm[3].pos.x = 3.0f * (rand()%65537 - 32768)/32768.0f; partEm[3].pos.y = 3.0f * (rand()%65537 - 32768)/32768.0f; partEm[3].pos.z = -15.0f + 3.0f * (rand()%65537 - 32768)/32768.0f; }*/ triEnd(); triSwapbuffers(); } triTextureUnload( partSys[1].textureID ); triTextureUnload( partSys[2].textureID ); triParticleManagerDestroy(); triFree( partSys ); triFree( partEm ); triTimerFree(frametimer); triTimerFree(demotimer); triFree( cam ); triInputShutdown(); triClose(); tri3dClose(); triMemoryShutdown(); sceKernelExitGame(); return 0; }
/* Simple thread */ int main(int argc, char **argv) { SetupCallbacks(); triLogInit(); triInit( GU_PSM_8888, 1 ); //triEnable( TRI_VBLANK ); // Colors enum colors { RED = 0xFF0000FF, GREEN = 0xFF00FF00, BLUE = 0xFFFF0000, WHITE = 0xFFFFFFFF }; // Init font library triFontInit(); // Make Debug font mono spaced at width 7 triFontSetMono( 0, 7 ); // Load first font, 12 point, 128x128 texture, in VRAM triFont *verdana12 = triFontLoad("./verdana.ttf", 12, TRI_FONT_SIZE_POINTS, 128, TRI_FONT_VRAM); //triFont *verdana12 = triFontLoadTRF("./verdana12.trf"); // Load second font, 20 pixels, 128x128 texture, in VRAM triFont *impact20 = triFontLoad("./impact.ttf", 20, TRI_FONT_SIZE_PIXELS, 128, TRI_FONT_VRAM); // Make sure the fonts are loaded if(!verdana12 || !impact20) sceKernelExitGame(); //triFontSaveTRF( verdana12, "verdana12.trf" ); while (isrunning) { triClear( 0 ); // Activate our first font triFontActivate(verdana12); // Draw our character set using the first font triFontPrint(160, 40, RED, " .,!?:;0123456789"); triFontPrint(160, 60, GREEN, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); triFontPrint(160, 80, BLUE, "abcdefghijklmnopqrstuvwxyz"); triFontPrint(160, 100, WHITE, "@#$%^&*+-()[]{}<>/\\|~`\"\n\ttabs and \tline breaks\n\tare \t\t\tsupported now!"); // Activate our second font triFontActivate(impact20); // Draw our character set using the second font triFontPrint(160, 150, RED, " .,!?:;0123456789"); triFontPrint(160, 170, GREEN, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); triFontPrint(160, 190, BLUE, "abcdefghijklmnopqrstuvwxyz"); triFontPrint(160, 210, WHITE, "@#$%^&*+-()[]{}<>/\\|~`\"\n\ttabs and \tline breaks\n\tare \t\t\t\tsupported now!"); // Activate the internal debug font triFontActivate(0); triFontPrintf(2, 2, WHITE, "FPS: %.2f - FPS Max: %.2f - FPS Min: %.2f", triFps(), triFpsMax(), triFpsMin()); triDrawRectOutline( 4, 39 152, 212, WHITE ); triFontPrintAlign( 5, 40, 150, 210, WHITE, TRI_FONT_ALIGN_JUSTIFY, "This is some\njustified text.\nJustification!"); triFontPrintAlign( 5, 40, 150, 210, WHITE, TRI_FONT_ALIGN_BOTTOM|TRI_FONT_ALIGN_RIGHT, "This is bottom\nand right aligned."); triSwapbuffers(); } // Unload our first font triFontUnload(verdana12); // Unload our second font triFontUnload(impact20); // Shutdown font library triFontShutdown(); triClose(); triMemoryShutdown(); triLogShutdown(); sceKernelExitGame(); return 0; }
char *SonyOSK(int len, const char *_desc, const char *inittext, triImage* img) { unsigned short intext[MAX_TEXT_LENGTH]; unsigned short outtext[MAX_TEXT_LENGTH]; unsigned short desc[MAX_TEXT_LENGTH]; memset(intext, 0, MAX_TEXT_LENGTH * sizeof(unsigned short)); memset(outtext, 0, MAX_TEXT_LENGTH * sizeof(unsigned short)); memset(desc, 0, MAX_TEXT_LENGTH * sizeof(unsigned short)); int i; int txt_len = strlen(_desc); for(i=0;i<txt_len;i++) { desc[i] = _desc[i]; } desc[txt_len] = 0; txt_len = strlen(inittext); for(i=0;i<txt_len;i++) { intext[i] = inittext[i]; } intext[txt_len] = 0; SceUtilityOskData data; memset(&data, 0, sizeof(SceUtilityOskData)); data.language = PSP_UTILITY_OSK_LANGUAGE_DEFAULT; // Use system default for text input data.lines = 1; data.unk_24 = 1; data.inputtype = PSP_UTILITY_OSK_INPUTTYPE_ALL; // Allow all input types data.desc = desc; data.intext = intext; data.outtextlength = MAX_TEXT_LENGTH; data.outtextlimit = len; data.outtext = outtext; SceUtilityOskParams params; memset(¶ms, 0, sizeof(params)); params.base.size = sizeof(params); sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_LANGUAGE, ¶ms.base.language); //sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN, ¶ms.base.buttonSwap); params.base.buttonSwap = 1; params.base.graphicsThread = 17; params.base.accessThread = 19; params.base.fontThread = 18; params.base.soundThread = 16; params.datacount = 1; params.data = &data; sceUtilityOskInitStart(¶ms); int done = 0; while(!done) { triClear( 0 ); if(img) triDrawImage2( 0.f, 0.f, img ); sceGuFinish(); sceGuSync(0,0); int stat = sceUtilityOskGetStatus(); switch(stat) { case PSP_UTILITY_DIALOG_INIT: break; case PSP_UTILITY_DIALOG_VISIBLE: sceUtilityOskUpdate(1); break; case PSP_UTILITY_DIALOG_QUIT: sceUtilityOskShutdownStart(); break; case PSP_UTILITY_DIALOG_FINISHED: break; case PSP_UTILITY_DIALOG_NONE: done = 1; default : break; } triSwapbuffers(); } int j; char buf[sizeof(unsigned)]; char *ret = new char[len+1]; memset(ret, 0, len+1); for(j = 0; data.outtext[j]; j++) { unsigned c = data.outtext[j]; if(32 <= c && c <= 127) // print ascii only { sprintf(buf, "%c", data.outtext[j]); strcat(ret, buf); } } ret[j] = 0; triLogPrint("ret: %s (%d)\n", ret, strlen(ret)); return ret; }