Exemplo n.º 1
0
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();
 	
	sceGuClearColor( GU_COLOR( 0.0f, 0.0f, 0.0f, 1.0f ) ); 
	sceGuClearDepth(0);	
}
Exemplo n.º 2
0
void drawTorus( int val )
{
    // setup a light

    ScePspFVector3 dir = { 0, 0, 1 };
    sceGuLight(0,GU_DIRECTIONAL,GU_DIFFUSE,&dir);
    sceGuLightColor(0,GU_DIFFUSE,0x00ff4040 );
    sceGuLightAtt(0,1.0f,0.0f,0.0f);
    sceGuAmbient(0x00202020);

    // setup texture
    sceGuDisable(GU_TEXTURE_2D);
    sceGuEnable(GU_LIGHTING);
    sceGuEnable(GU_LIGHT0);

    // setup matrices for torus

    sceGumMatrixMode(GU_PROJECTION);
    sceGumLoadIdentity();
    sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);

    sceGumMatrixMode(GU_VIEW);
    {
        ScePspFVector3 pos = {0.0f,0.0f,-2.5f};

        sceGumLoadIdentity();
        sceGumTranslate(&pos);
    }

    sceGumMatrixMode(GU_MODEL);
    {
        ScePspFVector3 rot = {val * 0.79f * (GU_PI/180.0f), val * 0.98f * (GU_PI/180.0f), val * 1.32f * (GU_PI/180.0f)};

        sceGumLoadIdentity();
        sceGumRotateXYZ(&rot);
    }

    // draw torus

    sceGuColor(0xffffff);
    sceGumDrawArray(GU_TRIANGLES,GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_INDEX_16BIT|GU_TRANSFORM_3D,sizeof(torus_indices)/sizeof(unsigned short),torus_indices,torus_vertices);


    // restore state

    sceGuDisable(GU_LIGHTING);
    sceGuDisable(GU_LIGHT0);
    sceGuEnable(GU_TEXTURE_2D);
}
Exemplo n.º 3
0
void ya2d_drawRotateTexture(ya2d_Texture *texp, int x, int y, float angle)
{
        if(!texp->data) return;

		sceGuEnable(GU_TEXTURE_2D);

		sceGuTexMode(texp->texPSM, 0, 0, texp->isSwizzled);
		sceGuTexFunc(GU_TFX_REPLACE, texp->hasAlpha ? GU_TCC_RGBA : GU_TCC_RGB);
		
        ya2d_setTexture(texp);
			
		sceGumPushMatrix(); 
		sceGumLoadIdentity();
		{
			ScePspFVector3 pos = {x + (float)texp->centerX, y + (float)texp->centerY, 0.0f};
			sceGumTranslate(&pos);
			sceGumRotateZ(angle);
		}

		ya2d_FloatTextureVertex *vertices = (ya2d_FloatTextureVertex *)sceGuGetMemory(4 * sizeof(ya2d_FloatTextureVertex));
		
		vertices[0] = (ya2d_FloatTextureVertex){0.0f, 0.0f, (float)-texp->centerX, (float)-texp->centerY, 0.0f};
        vertices[1] = (ya2d_FloatTextureVertex){0.0f, 1.0f, (float)-texp->centerX, (float)texp->centerY, 0.0f};
        vertices[2] = (ya2d_FloatTextureVertex){1.0f, 0.0f, (float)texp->centerX, (float)-texp->centerY, 0.0f};
        vertices[3] = (ya2d_FloatTextureVertex){1.0f, 1.0f, (float)texp->centerX, (float)texp->centerY, 0.0f};
        
		sceGumDrawArray(GU_TRIANGLE_STRIP, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D, 4, 0, vertices);
        
        sceKernelDcacheWritebackRange(vertices, 4 * sizeof(ya2d_FloatTextureVertex));
        sceGumPopMatrix(); 
}
Exemplo n.º 4
0
void StopRendering()
{
	sceGumLoadIdentity();
	sceGuFinish();
	sceGuSync(SCEGU_SYNC_FINISH, SCEGU_SYNC_WAIT);
	//printf("FrontEnd::StopRendering\n");
}
Exemplo n.º 5
0
void drawCube( Texture* texture, int val )
{
    // setup matrices for cube

    sceGumMatrixMode(GU_PROJECTION);
    sceGumLoadIdentity();
    sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);

    sceGumMatrixMode(GU_VIEW);
    {
        ScePspFVector3 pos = {0.0f,0.0f,-2.5f};

        sceGumLoadIdentity();
        sceGumTranslate(&pos);
    }

    sceGumMatrixMode(GU_MODEL);
    {
        ScePspFVector3 rot = {val * 0.263f * (GU_PI/180.0f), val * 0.32f * (GU_PI/180.0f), val * 0.44f * (GU_PI/180.0f)};

        sceGumLoadIdentity();
        sceGumRotateXYZ(&rot);
    }

    // setup texture

    sceGuTexMode(texture->format,0,0,0);
    sceGuTexImage(texture->mipmap,texture->width,texture->height,texture->stride,texture->data);
    sceGuTexFunc(GU_TFX_ADD,GU_TCC_RGB);
    sceGuTexFilter(GU_LINEAR,GU_LINEAR);
    sceGuTexScale(1.0f,1.0f);
    sceGuTexOffset(0.0f,0.0f);
    sceGuAmbientColor(0xffffffff);

    sceGuEnable(GU_TEXTURE_2D);

    // draw cube

    sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,12*3,0,cube_vertices);

    sceGuDisable(GU_TEXTURE_2D);
}
Exemplo n.º 6
0
void Red3dSetupScreen()
{
	sceGuDisplay(GU_TRUE);
	sceGuStart(GU_DIRECT,list);

	sceGuClearColor(GRAY);
	sceGuClearDepth(0);
	sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
	
	sceGumMatrixMode(GU_VIEW);
	sceGumLoadIdentity();
	{
		sceGumTranslate(&CameraPosition);
		sceGumRotateXYZ(&CameraRotation);
	}
	
	sceGumMatrixMode(GU_PROJECTION);
	sceGumLoadIdentity();
	sceGumPerspective(25.0f,16.0f/9.0f,0.5f,1000.0f);
}
Exemplo n.º 7
0
void DrawScene( void )
{
	sceGuStart( GU_DIRECT, sceneList );

	sceGuViewport( 2048, 2048, SCR_WIDTH, SCR_HEIGHT);	

	sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
	sceGumMatrixMode(GU_MODEL);		
	sceGumLoadIdentity();	// Reset the Matrix

	myScene->render();	// Render the scene
	
	sceGuFinish();
	sceGuSync(0,0);
}
/**
  * Created 24/02/2011
  * Finishes rendering
  */
void FrontEnd::StopRendering(void)
{
#ifdef PC
	_pd3dDevice->EndScene();
	_pd3dDevice->Present( NULL, NULL, NULL, NULL );
#else
	sceGumLoadIdentity();
	sceGuFinish();
	sceGuSync(SCEGU_SYNC_FINISH, SCEGU_SYNC_WAIT);
	sceGuDebugFlush();
	sceDisplayWaitVblankStart();
	//sceGumPopMatrix();
	//printf("FrontEnd::StopRendering\n");
#endif
}
Exemplo n.º 9
0
void DrawScene( void )
{
#warning Try taking out this display list at some point
	sceGuStart( GU_DIRECT, sceneList );

	sceGuViewport( 2048, 2048, SCR_WIDTH, SCR_HEIGHT);	

	sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
	sceGumMatrixMode(GU_MODEL);		
	sceGumLoadIdentity();	// Reset the Matrix

	myScene.render();	// Render the scene
	
	sceGuFinish();
	sceGuSync(0,0);
}
Exemplo n.º 10
0
void StartUpDisplay()
{
	//ScePspFVector3	vec;

	_rotationSpeed = 1.0f;
	_rotation.x = 0.0f;
	_rotation.y = 0.0f;
	_rotation.z = 0.0f;
	_bgColour = 0;
	_frame = 0;
	_viewMode = 0;
	sceGuInit();
	sceGuStart(SCEGU_IMMEDIATE, (void *)disp_list, sizeof(disp_list));

	sceGuDrawBuffer(SCEGU_PF5551, SCEGU_VRAM_BP_0, SCEGU_VRAM_WIDTH);
	sceGuDispBuffer(SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, SCEGU_VRAM_BP_1,
		SCEGU_VRAM_WIDTH);
	sceGuDepthBuffer(SCEGU_VRAM_BP_2, SCEGU_VRAM_WIDTH);

	sceGuOffset(SCEGU_SCR_OFFSETX, SCEGU_SCR_OFFSETY);
	sceGuViewport(2048, 2048, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT);
	sceGuDepthRange(50000, 10000);

	sceGuDisable(SCEGU_BLEND);

	sceGuScissor(0, 0, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT);
	sceGuEnable(SCEGU_SCISSOR_TEST);

	sceGuDepthFunc(SCEGU_GEQUAL);
	sceGuEnable(SCEGU_DEPTH_TEST);

	sceGuFrontFace(SCEGU_CW);

	sceGuDisable(SCEGU_TEXTURE);
	sceGuShadeModel(SCEGU_SMOOTH);

	sceGuEnable(SCEGU_DITHER);

	//vec.x = 0.0f;
	//vec.y = 0.0f;
	//vec.z = 1.0f;
	//sceGuLightColor(0, SCEGU_DIFFUSE, 0xffffffff);
	//sceGuLight(0, SCEGU_LIGHT_DIRECTION, SCEGU_DIFFUSE, &vec);
	//vec.x = 1.0f;
	//vec.y = 0.0f;
	//vec.z = 0.0f;
	//sceGuLightColor(1, SCEGU_DIFFUSE, 0xff00ffff);
	//sceGuLight(1, SCEGU_LIGHT_DIRECTION, SCEGU_DIFFUSE, &vec);
	//vec.x = -1.0f;
	//vec.y = 0.0f;
	//vec.z = 0.0f;
	//sceGuLightColor(2, SCEGU_DIFFUSE, 0xffff00ff);
	//sceGuLight(2, SCEGU_LIGHT_DIRECTION, SCEGU_DIFFUSE, &vec);
	//sceGuEnable(SCEGU_LIGHT0);
	//sceGuEnable(SCEGU_LIGHT1);
	//sceGuEnable(SCEGU_LIGHT2);
	//sceGuEnable(SCEGU_LIGHTING);

	//sceGuFog(14.50, 25.0, 0x007f00ff);

	//sceGuAmbient(0xcc004cb2);
	sceGuAmbient(0xffffffff);
	sceGuColor(0xff0000ff);

	//sceGuTexMode(SCEGU_PF5551, 1, SCEGU_SINGLE_CLUT, SCEGU_TEXBUF_NORMAL);
	//sceGuTexFilter(SCEGU_LINEAR_MIPMAP_NEAREST, SCEGU_LINEAR);
	//sceGuTexFunc(SCEGU_TEX_MODULATE, SCEGU_RGB);
	//sceGuTexWrap(SCEGU_REPEAT, SCEGU_REPEAT);

	sceGumSetMatrixStack(matrix_stack, 1, 1, 2, 0);
	sceGumMatrixMode(SCEGU_MATRIX_PROJECTION);
	sceGumLoadIdentity();
	sceGumPerspective(SCEGU_RAD(45.0f), SCEGU_SCR_ASPECT,
		1.000000f, 100.000000f);

	sceGumMatrixMode(SCEGU_MATRIX_WORLD);

	sceGuClearDepth(0);
	sceGuClearStencil(0);

	sceGuFinish();
	sceGuSync(SCEGU_SYNC_FINISH, SCEGU_SYNC_WAIT);

	sceGuDisplay(SCEGU_DISPLAY_ON);
}
Exemplo n.º 11
0
int main(int argc, char* argv[])
{
	setupCallbacks();

	int i, j;

	// Load emd mesh from file
	EMD_MESH* mesh = EMD_LoadMeshFromFile("scene.emd");
	int vert_count = EMD_GetVertexCount(mesh);
	int idx_count = 0;

	int elem_count = EMD_GetElementCount(mesh);
	for (i=0; i<elem_count; i++)
	{
		idx_count += EMD_GetIndexCount(mesh, i);
	}

	VERTEX* vert_buf = (VERTEX*)memalign(16, sizeof(VERTEX) * vert_count);
	GW_UINT16* idx_buf = (GW_UINT16*)memalign(16, sizeof(GW_UINT16) * idx_count);

	for (i=0; i<vert_count; i++)
	{
		EMD_GetVertexByIndex(mesh, i, &vert_buf[i].x, &vert_buf[i].y, &vert_buf[i].z);
		EMD_GetTexcoordByIndex(mesh, i, &vert_buf[i].u, &vert_buf[i].v);
		EMD_GetNormalByIndex(mesh, i, &vert_buf[i].nx, &vert_buf[i].ny, &vert_buf[i].nz);
		//vert_buf[i].color = 0xffffffff;
	}

	GW_UINT32 idx_head = 0;
	GW_UINT32* data;
	GW_UINT32 count;

	// Pack 32-bit index into 16-bit buffer
	for (i=0; i<elem_count; i++)
	{
		count = EMD_GetIndexCount(mesh, i);
		data = EMD_GetIndexArray(mesh, i);
		for (j=0; j<count; j++)
		{
			idx_buf[j + idx_head] = (GW_UINT16)data[j];
		}

		idx_head += count;
	}

	EMD_FreeMesh(mesh);


	// flush cache so that no stray data remains

	sceKernelDcacheWritebackAll();

	// setup GU

	void* fbp0 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
	void* fbp1 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
	void* zbp = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_4444);

	pspDebugScreenInit();
	sceGuInit();

	sceGuStart(GU_DIRECT,list);
	sceGuDrawBuffer(GU_PSM_8888,fbp0,BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,fbp1,BUF_WIDTH);
	sceGuDepthBuffer(zbp,BUF_WIDTH);
	sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
	sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
	sceGuDepthRange(65535,0);
	sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuDepthFunc(GU_GEQUAL);
	sceGuEnable(GU_DEPTH_TEST);
	sceGuFrontFace(GU_CCW);
	sceGuShadeModel(GU_SMOOTH);
	sceGuEnable(GU_CULL_FACE);
	//sceGuDisable(GU_TEXTURE_2D);
	sceGuEnable(GU_CLIP_PLANES);
	sceGuEnable(GU_LIGHTING);
	sceGuEnable(GU_LIGHT0);
	sceGuEnable(GU_LIGHT1);
	sceGuFinish();
	sceGuSync(0,0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);

	// run sample

	int val = 0;

	while(running())
	{
		sceGuStart(GU_DIRECT,list);

		// clear screen

		sceGuClearColor(0xff554433);
		sceGuClearDepth(0);
		sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

		
		// setup lights

		ScePspFVector3 light_dir = { 1.0f, 1.0f, 1.0f };

		// GU_DIRECTIONAL
		// GU_POINTLIGHT
		sceGuLight(0, GU_POINTLIGHT, GU_DIFFUSE, &light_dir);
		sceGuLightColor(0, GU_DIFFUSE, 0xffffffff);
		sceGuAmbient(0x00202020);

		light_dir.x = -light_dir.x;
		light_dir.y = -light_dir.y;
		light_dir.z = -light_dir.z;

		sceGuLight(1, GU_DIRECTIONAL, GU_DIFFUSE_AND_SPECULAR, &light_dir);
		sceGuLightColor(1, GU_DIFFUSE, 0xff7f7f7f);
		

		// setup matrices for cube

		sceGumMatrixMode(GU_PROJECTION);
		sceGumLoadIdentity();
		sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);

		sceGumMatrixMode(GU_VIEW);
		sceGumLoadIdentity();

		sceGumMatrixMode(GU_MODEL);
		sceGumLoadIdentity();
		{
			ScePspFVector3 pos = { 0, 0, -5.0f };
			ScePspFVector3 rot = { val * 0.79f * (GU_PI/180.0f), val * 0.98f * (GU_PI/180.0f), val * 1.32f * (GU_PI/180.0f) };
			sceGumTranslate(&pos);
			sceGumRotateXYZ(&rot);
		}

		// setup texture

		//sceGuTexMode(GU_PSM_4444,0,0,0);
		// sceGuTexImage(0,64,64,64,logo_start);
		//sceGuTexFunc(GU_TFX_ADD,GU_TCC_RGB);
		//sceGuTexEnvColor(0xffff00);
		//sceGuTexFilter(GU_LINEAR,GU_LINEAR);
		//sceGuTexScale(1.0f,1.0f);
		//sceGuTexOffset(0.0f,0.0f);
		//sceGuAmbientColor(0xff7f7f7f);

		// draw cube

		sceGuColor(0xffffff);
		sceGumDrawArray(GU_TRIANGLES, GU_TEXTURE_32BITF|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_INDEX_16BIT|GU_TRANSFORM_3D,
				idx_count, idx_buf, vert_buf);
		

		pspDebugScreenSetXY(0, 0);
		pspDebugScreenPrintf("v: %d", vert_count);
		pspDebugScreenSetXY(0, 1);
		pspDebugScreenPrintf("i: %d", idx_count);

		sceGuFinish();
		sceGuSync(0,0);

		sceDisplayWaitVblankStart();
		sceGuSwapBuffers();

		val++;
	}

	sceGuTerm();

	// Release buffers
	free(vert_buf);
	free(idx_buf);

	sceKernelExitGame();
	return 0;
}
Exemplo n.º 12
0
/* 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;
}
Exemplo n.º 13
0
int main(int argc, char* argv[])
{
	setupCallbacks();

	// setup GU

	void* fbp0 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
	void* fbp1 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
	void* zbp = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_4444);

	sceGuInit();

	sceGuStart(GU_DIRECT,list);
	sceGuDrawBuffer(GU_PSM_8888,fbp0,BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,fbp1,BUF_WIDTH);
	sceGuDepthBuffer(zbp,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);
	sceGuDepthFunc(GU_GEQUAL);
	sceGuEnable(GU_DEPTH_TEST);
	sceGuFrontFace(GU_CW);
	sceGuShadeModel(GU_SMOOTH);
//	sceGuEnable(GU_CULL_FACE);
	sceGuEnable(GU_CLIP_PLANES);
	sceGuFinish();
	sceGuSync(0,0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);

	setupSH();
	indicesSH();

	// run sample

	int val = 0;

	while(running())
	{
		sceGuStart(GU_DIRECT,list);

		// clear screen

		sceGuClearColor(0x000000);
		sceGuClearDepth(0);
		sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

		// light settings

		sceGuEnable(GU_LIGHTING);
		sceGuEnable(GU_LIGHT0);
		sceGuEnable(GU_LIGHT1);
		sceGuEnable(GU_LIGHT2);
		sceGuLightMode(1);
		{
			unsigned int i;

			for (i = 0; i < 3; ++i)
			{
				sceGuLight(i,GU_DIRECTIONAL,GU_DIFFUSE_AND_SPECULAR,&lsettings[i].position);
				sceGuLightColor(i,GU_DIFFUSE,lsettings[i].diffuse);
				sceGuLightColor(i,GU_SPECULAR,lsettings[i].specular);
				sceGuLightAtt(i,0.0f,1.0f,0.0f);
			}
			sceGuSpecular(12.0f);
			sceGuAmbient(0x000000);
		}

		// setup matrices

		sceGumMatrixMode(GU_PROJECTION);
		sceGumLoadIdentity();
		sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);

		sceGumMatrixMode(GU_VIEW);
		{
			ScePspFVector3 pos = { 0, 0, -5.0f };

			sceGumLoadIdentity();
			sceGumTranslate(&pos);
		}

		sceGumMatrixMode(GU_MODEL);
		sceGumLoadIdentity();
		{
			ScePspFVector3 rot = { val * 0.79f * (GU_PI/180.0f), val * 0.98f * (GU_PI/180.0f), val * 1.32f * (GU_PI/180.0f) };
			sceGumRotateXYZ(&rot);
		}

		// setup texture

		sceGuAmbientColor(0xffffffff);

		// draw

		renderSH(parametersSH);

		sceGuFinish();
		sceGuSync(0,0);

		sceDisplayWaitVblankStart();
		sceGuSwapBuffers();

		val++;

		if ((val%600) == 0)
		{
			unsigned int i;
			for (i = 0; i < 8; ++i)
				parametersSH[i] = (int)((rand() / ((float)RAND_MAX)) * 6.0f);
		}
	}

	sceGuTerm();

	sceKernelExitGame();
	return 0;
}
void FrontEnd::StartUpDisplay(void)
#endif
{
#ifdef PC
	UNREFERENCED_PARAMETER( hInst );

	// register window class
	WNDCLASSEX wc = 
	{
		sizeof( WNDCLASSEX ), CS_CLASSDC, MainWndProc, 0L, 0L,
		GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
		L"Cross-Platform Development", NULL
	};
	wc.hInstance = hInst;
	_wc = wc;
	if( !RegisterClassEx( &wc ) )
	{
		MessageBox( 0, L"Failed to Register Class", 0, 0 );
		PostQuitMessage( 0 );
	}

	// create the window
	_d3dParameters.BackBufferHeight = 272;
	_d3dParameters.BackBufferWidth = 480;
	HWND hWnd = CreateWindow( L"Cross-Platform Development", L"Cross-Platform Development", WS_OVERLAPPEDWINDOW, 100, 100, 
		_d3dParameters.BackBufferWidth, _d3dParameters.BackBufferHeight, NULL, NULL, wc.hInstance, NULL );

	// check if the hWnd has been created
	if( !hWnd )
	{
		MessageBox( 0, L"Failed to Create Window", 0, 0 );
		PostQuitMessage( 0 );
	}

	/* Create the device */
	if ( NULL == ( _pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
	{
		MessageBox( 0, L"DirectX SDK Version Wrong", 0, 0 );
		PostQuitMessage( 0 );
	}

	// set up the structure used to create the D3DDevice
	int height = _d3dParameters.BackBufferHeight;
	int width = _d3dParameters.BackBufferWidth;
	ZeroMemory( &_d3dParameters, sizeof( _d3dParameters ) );
	_d3dParameters.Windowed = TRUE;
	_d3dParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
	_d3dParameters.BackBufferFormat = D3DFMT_UNKNOWN;
	_d3dParameters.BackBufferHeight = height;
	_d3dParameters.BackBufferWidth = width;
	_d3dParameters.EnableAutoDepthStencil = TRUE;		/* Allow directX to create and manage a z buffer for me */
	_d3dParameters.AutoDepthStencilFormat = D3DFMT_D16;	/* Use the 16bit format */

	// create D3DDevice
	if ( FAILED( _pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_HARDWARE_VERTEXPROCESSING, &_d3dParameters, &_pd3dDevice ) ) )
	{
		if ( FAILED( _pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING, &_d3dParameters, &_pd3dDevice ) ) )
		{
			MessageBox( 0, L"This machine cannot process vertices", 0, 0 );
			PostQuitMessage( 0 );
		}
	}

	// set up some default render modes
	_pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );		/*< Solid fill rendering */
	_pd3dDevice->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_FLAT );		/*< Default shading */
	_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );		/*< Culling off */ 
	_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );				/*< Lighting on */ 
	_pd3dDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_XRGB(255,255,255) );
	_pd3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );			/*< Turn on z buffering */
	_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );			/*< Allow writing to the z buffer */
	_pd3dDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_LESSEQUAL );		/*< Render each pixel if it's less than or equal to an existing pixel */

	ShowWindow( hWnd, UpdateWindow( hWnd ) );

	/* Set up the vertex buffer for rendering */
	Vertex* vertexBuffer = false;
	if( SUCCEEDED( _pd3dDevice->CreateVertexBuffer( 36 * sizeof( D3DFVF_Vertex ), 0, 
		D3DFVF_XYZ, D3DPOOL_DEFAULT, &_vertexBuffer, NULL ) ) )
	{
		if( SUCCEEDED( _vertexBuffer->Lock( 0, 36 * sizeof( D3DFVF_Vertex ), (void**)&vertexBuffer, 0 ) ) )
		{	
			for( DWORD i = 0; i < 36; ++i )
			{
				vertexBuffer[i].x = Cube[i].x;
				vertexBuffer[i].y = Cube[i].y;
				vertexBuffer[i].z = Cube[i].z;
			}

			_vertexBuffer->Unlock();

			/* Apply a material for lighting to work */
			D3DMATERIAL9 material;
			ZeroMemory( &material, sizeof( material ) );
			material.Diffuse.r = material.Ambient.r = 1.0f;
			material.Diffuse.g = material.Ambient.g = 1.0f;
			material.Diffuse.b = material.Ambient.b = 1.0f;
			material.Diffuse.a = material.Ambient.a = 1.0f;

			_pd3dDevice->SetMaterial( &material );
			_pd3dDevice->SetStreamSource( 0, _vertexBuffer, 0, sizeof(D3DFVF_Vertex) );
			_pd3dDevice->SetFVF( D3DFVF_XYZ );
		}
	}
#else
	_rotationSpeed = 1.0f;
	_rotation.x = 0.0f;
	_rotation.y = 0.0f;
	_rotation.z = 0.0f;
	_frame = 0;
	_viewMode = -1;
	sceGuInit();
	sceGuStart(SCEGU_IMMEDIATE, (void*)_displist, sizeof(_displist));

	sceGuDrawBuffer(SCEGU_PF5551, SCEGU_VRAM_BP_0, SCEGU_VRAM_WIDTH);
	sceGuDispBuffer(SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, SCEGU_VRAM_BP_1,
		SCEGU_VRAM_WIDTH);
	sceGuDepthBuffer(SCEGU_VRAM_BP_2, SCEGU_VRAM_WIDTH);

	sceGuOffset(SCEGU_SCR_OFFSETX, SCEGU_SCR_OFFSETY);
	sceGuViewport(2048, 2048, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT);
	sceGuDepthRange(50000, 10000);

	sceGuDisable(SCEGU_BLEND);

	sceGuScissor(0, 0, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT);
	sceGuEnable(SCEGU_SCISSOR_TEST);

	sceGuDepthFunc(SCEGU_GEQUAL);
	sceGuEnable(SCEGU_DEPTH_TEST);

	sceGuFrontFace(SCEGU_CW);

	sceGuDisable(SCEGU_TEXTURE);
	sceGuShadeModel(SCEGU_SMOOTH);

	sceGuEnable(SCEGU_DITHER);

	sceGumSetMatrixStack(_matrixStack, 1, 1, 2, 0);
	sceGumMatrixMode(SCEGU_MATRIX_PROJECTION);
	sceGumLoadIdentity();
	sceGumPerspective(DEGSTORADS(45.0f), SCEGU_SCR_ASPECT,
		1.000000f, 100.000000f);

	sceGumMatrixMode(SCEGU_MATRIX_WORLD);

	sceGuClearDepth(0);
	sceGuClearStencil(0);

	sceGuFinish();
	sceGuSync(SCEGU_SYNC_FINISH, SCEGU_SYNC_WAIT);

	sceGuDisplay(SCEGU_DISPLAY_ON);
#endif
}
/**
  * Created 24/02/2011
  * Prepares and clears the PSP display for rendering
  */
bool FrontEnd::StartRendering(void)
{
	//printf("FrontEnd::StartRendering\n");
	
	/* Increment the frame */
	++_frame;

	/* Check controls */
	if( _playerInput->IsLShoulderDown() )
	{
		++_viewMode;
		if( _viewMode >= 3 )
		{
			_viewMode = 0;
		}
	}
	else if( _playerInput->IsRShoulderDown() )
	{
		--_viewMode;
		if( _viewMode < 0 )
		{
			_viewMode = 2;
		}
	}
	if( _playerInput->IsDPadLeft() )
	{
		if( _rotationSpeed > 1 )
		{
			--_rotationSpeed;
		}
	}
	else if( _playerInput->IsDPadRight() )
	{
		if( _rotationSpeed < 180 )
		{
			++_rotationSpeed;
		}
	}

	/* Increment the rotation */
	switch( _viewMode )
	{
	case -1:
			break;
		case 0:
			_rotation.x += DEGSTORADS( _rotationSpeed );
			if( _rotation.x > DEGSTORADS( 360.0f ) )
			{
				_rotation.x = 0.0f;
			}
			break;
		case 1:
			_rotation.y += DEGSTORADS( _rotationSpeed );
			if( _rotation.y > DEGSTORADS( 360.0f ) )
			{
				_rotation.y = 0.0f;
			}
			break;
		case 2:
			_rotation.z += DEGSTORADS( _rotationSpeed );
			if( _rotation.z > DEGSTORADS( 360.0f ) )
			{
				_rotation.z = 0.0f;
			}
			break;
	}
	
#ifdef PC
	/* Start the device */
	_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, IntToD3DColor( _bgColour ), 1.0f, 0 );
	_pd3dDevice->BeginScene();

	/* Set up the view matrix */
	D3DXMATRIXA16 view;
	D3DXMatrixTranslation( &view, _view.x, _view.y, 25.0f );
	_pd3dDevice->SetTransform( D3DTS_VIEW, &view );

	/* Set up the projection matrix */
	D3DXMATRIXA16 projection;
	D3DXMatrixPerspectiveFovLH( &projection, DEGSTORADS(45.0f), 1.7647f, 1.0f, 100.0f ); 
	_pd3dDevice->SetTransform( D3DTS_PROJECTION, &projection );

#else
	/* Set up the starting matrices */
	//sceGumPushMatrix();
	ScePspFVector3 view;
	view.x = _view.x;
	view.y = _view.y;
	view.z = _view.z;
	sceGumLoadIdentity();
	sceGumTranslate( &view );
	//BlockUntilFrameReady();	/*< Blocks the program until the frame is ready */
	
	/* Preps the display for rendering */
	sceGuSwapBuffers();
	sceGuStart(SCEGU_IMMEDIATE, (void*)_displist, sizeof(_displist));
	sceGuClearColor(_bgColour);
	sceGuClear(SCEGU_CLEAR_ALL);
#endif

	return true;
}
Exemplo n.º 16
0
int main(int argc, char* argv[])
{
	unsigned int i,j;

	pspDebugScreenInit();
	SetupCallbacks();

#ifdef ENABLE_PROFILER
	// Enable profiling 
	pspDebugProfilerClear();
	pspDebugProfilerEnable();
#endif

	// initialize global context
	g_context.iterationCount = NUM_VERTEX_BUFFERS * NUM_ITERATIONS;
	g_context.t = 0;
	g_context.sint = 0;

	// initialize torus
	for (i = 0; i < NUM_SLICES; ++i)
	{
		for (j = 0; j < NUM_ROWS; ++j)
		{
			float s = i + 0.5f, t = j;
			float x,y,z;

			x = (RING_SIZE + RING_RADIUS * cosf(s * ((GU_PI*2)/NUM_SLICES))) * cosf(t * ((GU_PI*2)/NUM_ROWS));
			y = (RING_SIZE + RING_RADIUS * cosf(s * ((GU_PI*2)/NUM_SLICES))) * sinf(t * ((GU_PI*2)/NUM_ROWS));
			z = RING_RADIUS * sinf(s * ((GU_PI*2)/NUM_SLICES));

			torus_vertices[j + i * NUM_ROWS].x = x;
			torus_vertices[j + i * NUM_ROWS].y = y;
			torus_vertices[j + i * NUM_ROWS].z = z;
		}
	}

	// initialize torus modifiers

	for (j = 0; j < NUM_ROWS; ++j)
	{
		float t = j;
		torus_modifiers[j].x = 0;
		torus_modifiers[j].y = 0;
		torus_modifiers[j].z = 0.3*cosf( t * 8.0f *((GU_PI*2)/NUM_ROWS) );
	}

	// init GU and set callbacks
	sceGuInit();

	// 0x01 - user callback
	// 0x04 - 'rendering finished' callback
	sceGuSetCallback(1, &mySignalHandler);
	sceGuSetCallback(4, &myFinishHandler);

	// setup GU
	sceGuStart(GU_DIRECT,list);
	sceGuDrawBuffer(GU_PSM_8888,(void*)0,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(0xc350,0x2710);
	sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuAlphaFunc(GU_GREATER,0,0xff);
	sceGuEnable(GU_ALPHA_TEST);
	sceGuDepthFunc(GU_GEQUAL);
	sceGuEnable(GU_DEPTH_TEST);
	sceGuFrontFace(GU_CW);
	sceGuShadeModel(GU_SMOOTH);
	sceGuEnable(GU_CULL_FACE);
	sceGuEnable(GU_TEXTURE_2D);
	sceGuFinish();
	sceGuSync(0,0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);

	// run sample

#ifdef USING_SIGNALS
	sceGuCallMode(1);
#endif

	// generate callable command-list with texture setup
	{
		sceGuStart(GU_CALL, smallList1);

		// setup texture
		sceGuTexMode(GU_PSM_5551,0,0,0);
		sceGuTexImage(0,32,32,32,ball_start); // width, height, buffer width, tbp
		sceGuTexFunc(GU_TFX_MODULATE,GU_TCC_RGBA); // NOTE: this enables reads of the alpha-component from the texture, otherwise blend/test won't work
		sceGuTexFilter(GU_NEAREST,GU_NEAREST);
		sceGuTexWrap(GU_CLAMP,GU_CLAMP);
		sceGuTexScale(1,1);
		sceGuTexOffset(0,0);
		sceGuAmbientColor(0xffffffff);

		sceGuFinish();
		sceGuSync(0,0);
	}

	// generate callable command-list for cube rendering
	{
		sceGuStart(GU_CALL, smallList2);

		// draw cube
		sceGuDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,12*3,0,cubeVertices);

		sceGuFinish();
		sceGuSync(0,0);
	}

	for(;;)
	{
		sceGuStart(GU_DIRECT,list);

		unsigned int i = 0;
		for( ; i < NUM_VERTEX_BUFFERS; i++ )
			g_context.vbuffer[i] = sceGuGetMemory((NUM_SLICES/g_context.iterationCount) * 2 * NUM_ROWS * sizeof(Vertex));
		g_context.vertsRendered = 0;

		// clear screen
		sceGuClearColor(0x00334455);
		sceGuClearDepth(0);
		sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

		// setup matrices
		sceGumMatrixMode(GU_PROJECTION);
		sceGumLoadIdentity();
		sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);

		sceGumMatrixMode(GU_VIEW);
		sceGumLoadIdentity();

		sceGumMatrixMode(GU_MODEL);
		{
			ScePspFVector3 pos = {0.0f,0.0f,-3.5f};
			ScePspFVector3 rot = {g_context.t * 0.3f * (GU_PI/180.0f), g_context.t * 0.7f * (GU_PI/180.0f), g_context.t * 1.3f * (GU_PI/180.0f)};

			sceGumLoadIdentity();
			sceGumTranslate(&pos);
			sceGumRotateXYZ(&rot);
		}

		sceGumStoreMatrix(&g_context.world);

		// call pregenerated command-list to setup texture		
		sceGuCallList(smallList1);

		// start billboard rendering
		render_billboards(0);

		// call pregenerated command-list to render cube
		{
			ScePspFVector3 scale = {0.3f, 0.3f, 0.3f};
			sceGumScale(&scale);
		}

		sceGumUpdateMatrix();
		sceGuCallList(smallList2);	

#ifndef USING_SIGNALS
		// HACK: sceGuFinish() is called inside the signal interupt handler when all rendering job is done
		// this is done in order to stall GPU if it is ahead of CPU
		sceGuFinish();
#endif
		sceGuSync(0,0);

#ifndef ENABLE_FRAMERATE
		// wait for next frame
		sceDisplayWaitVblankStart();
#endif
		sceGuSwapBuffers();

		pspDebugScreenSetXY(0,0);

#ifdef ENABLE_PROFILER
		// Print profile information to the screen
		pspDebugProfilerPrint();
#endif

#ifdef ENABLE_FRAMERATE
		// simple frame rate counter
		static float curr_ms = 1.0f;
		static struct timeval time_slices[16];
		static int t = 0;

		float curr_fps = 1.0f / curr_ms;

		t++;
		
		float vertsPerSec = g_context.vertsRendered*curr_fps;
		float kbPerSec = vertsPerSec * sizeof(Vertex) / 1024.0f;
		gettimeofday(&time_slices[t & 15],0);
		pspDebugScreenPrintf("fps: %d.%03d  ms: %d  vert/s: %dK  MB/s: %d.%03d",(int)curr_fps, ((int)(curr_fps*1000.0f)%1000), (int)(curr_ms*1000.0f),
			(int)(vertsPerSec/1000.0f),
			(int)(kbPerSec/1024.0f), (int)((1000.0f/1024.0f)*((int)kbPerSec%1024)) );

		if (!(t & 15))
		{
			struct timeval last_time = time_slices[0];
			unsigned int i;

			curr_ms = 0;
			for (i = 1; i < 16; ++i)
			{
				struct timeval curr_time = time_slices[i];

				int curr_time_usec = curr_time.tv_usec + curr_time.tv_sec * 1000000;
				int last_time_usec = last_time.tv_usec + last_time.tv_sec * 1000000;

				if( last_time_usec < curr_time_usec )
					curr_ms += (( curr_time_usec - last_time_usec ) * (1.0f/1000000.0f));

				last_time = time_slices[i];
			}
			curr_ms /= 15.0f;
		}
#endif
	}

	sceGuTerm();

	sceKernelExitGame();
	return 0;
}
Exemplo n.º 17
0
int main(int argc, char* argv[]) {
	/* Setup Homebutton Callbacks */
	setupCallbacks();

	sceKernelDcacheWritebackAll();

	// setup GU

	SceCtrlData pad;
    sceCtrlSetSamplingCycle(0);
    sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);

	sceGuInit();

	sceGuStart(GU_DIRECT,list);
	sceGuDrawBuffer(GU_PSM_8888,(void*)0,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(0xc350,0x2710);
	sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuDepthFunc(GU_GEQUAL);
	sceGuEnable(GU_DEPTH_TEST);
	sceGuFrontFace(GU_CCW);
	sceGuColor(0xffffffff);
	sceGuShadeModel(GU_SMOOTH);
//	sceGuEnable(GU_CULL_FACE);
	sceGuEnable(GU_CLIP_PLANES);
	sceGuEnable(GU_TEXTURE_2D);
	sceGuTexMode(GU_PSM_8888, 0, 0, 0);
	sceGuTexImage(0, 16, 16, 16, texture);
	sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
	sceGuTexEnvColor(0xffffff);
	sceGuTexFilter(GU_LINEAR, GU_LINEAR);
	sceGuTexWrap(GU_REPEAT, GU_REPEAT);
	sceGuTexScale(1.0f, 1.0f);
	sceGuTexOffset(0.0f, 0.0f);
	sceGuAmbientColor(0xffffffff);

	sceGuFinish();
	sceGuSync(0,0);
	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);
	
	void* buffer = 0;

	pspDebugScreenInit();

	unsigned int old = 0;
	unsigned int flags = PSP_CTRL_CIRCLE | PSP_CTRL_CROSS;

	int tex = 1;

	while(running()) {
		sceGuStart(GU_DIRECT,list);

		sceGuClearColor(0);
		sceGuClearDepth(0);
		sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);

		sceGumMatrixMode(GU_PROJECTION);
		sceGumLoadIdentity();
		sceGumPerspective(90.0f, 480.0/272.0f, 0.1f, 10.0f);

		sceGumMatrixMode(GU_VIEW);
		sceGumLoadIdentity();
		ScePspFVector3 trans = { 0.0f, 0.0f, -1.8f };
		sceGumTranslate(&trans);
		
		sceGumMatrixMode(GU_MODEL);
		sceGumLoadIdentity();

		sceGumDrawArray(objects[o].prim, objects[o].flags, objects[o].count, 0, objects[o].data);

		sceCtrlReadBufferPositive(&pad, 1);
		if(old != pad.Buttons) {
			if(pad.Buttons & PSP_CTRL_CROSS) {
				o++;
				if(o >= sizeof(objects) / sizeof(Object)) {
					o = 0;
				}
			}
			if(pad.Buttons & PSP_CTRL_CIRCLE) {
				tex = !tex;
				if(tex) {
					sceGuEnable(GU_TEXTURE_2D);
				} else {
					sceGuDisable(GU_TEXTURE_2D);
				}
			}
		}
		old = pad.Buttons;

		sceGuFinish();
		sceGuSync(0,0);

		pspDebugScreenSetOffset((int)buffer);
		pspDebugScreenSetXY(0, 0);
		pspDebugScreenPrintf("Mode: %s (X to change)    Texture: %s (O to change)", objects[o].text, tex ? "on " : "off");

		sceDisplayWaitVblankStart();
		buffer = sceGuSwapBuffers();
	}

	sceGuTerm();

	sceKernelExitGame();
	return 0;
}
Exemplo n.º 18
0
int dxpGraphicsInit()
{
	u32 i;
	//構造体初期化
	if(dxpGraphicsData.init)return 0;

	{//深度バッファの初期化
		dxpGraphicsData.depthbuffer.psm = GU_PSM_4444;
		dxpGraphicsData.depthbuffer.ppalette = NULL;
		dxpGraphicsData.depthbuffer.texdata = NULL;
		dxpGraphicsData.depthbuffer.width = 480;
		dxpGraphicsData.depthbuffer.height = 272;
		dxpGraphicsData.depthbuffer.pitch = 512;
		dxpGraphicsData.depthbuffer.umax = 480;
		dxpGraphicsData.depthbuffer.vmax = 272;
		dxpGraphicsData.depthbuffer.colorkey = 0;
		dxpGraphicsData.depthbuffer.size2_nflag = 0;
		dxpGraphicsData.depthbuffer.swizzledflag = 1;
		dxpGraphicsData.depthbuffer.reloadflag = 1;
		dxpGraphicsData.depthbuffer.alphabit = 0;
		dxpGraphicsData.depthbuffer.refcount = 0;
		dxpGraphicsData.depthbuffer.thisptrptr = NULL;
		if(dxpGraphicsData.usedepth || dxpGraphicsData.usedepth3d)
		{
			dxpGraphicsData.depthbuffer.texvram = valloc(vgetMemorySize(512,272,GU_PSM_4444));
			if(!dxpGraphicsData.depthbuffer.texvram)return -1;
		}else dxpGraphicsData.depthbuffer.texvram = NULL;
	}

	for(i = 0;i < 2;++i)
	{//フレームバッファの初期化
		dxpGraphicsData.displaybuffer[i].psm = dxpGraphicsData.display_psm;
		dxpGraphicsData.displaybuffer[i].ppalette = NULL;
		dxpGraphicsData.displaybuffer[i].texdata = NULL;
		dxpGraphicsData.displaybuffer[i].texvram = valloc(vgetMemorySize(512,272,dxpGraphicsData.display_psm));
		dxpGraphicsData.displaybuffer[i].width = 480;
		dxpGraphicsData.displaybuffer[i].height = 272;
		dxpGraphicsData.displaybuffer[i].pitch = 512;
//		dxpGraphicsData.displaybuffer[i].pitch = 480;//試したら見事に駄目だったw
		dxpGraphicsData.displaybuffer[i].umax = 480;
		dxpGraphicsData.displaybuffer[i].vmax = 272;
		dxpGraphicsData.displaybuffer[i].colorkey = 0;
		dxpGraphicsData.displaybuffer[i].size2_nflag = 0;
		dxpGraphicsData.displaybuffer[i].swizzledflag = 0;
		dxpGraphicsData.displaybuffer[i].reloadflag = 1;
		dxpGraphicsData.displaybuffer[i].alphabit = 0;
		dxpGraphicsData.displaybuffer[i].refcount = 0;
	}
	if(!dxpGraphicsData.displaybuffer[0].texvram || !dxpGraphicsData.displaybuffer[1].texvram)
	{
		vfree(dxpGraphicsData.displaybuffer[0].texvram);
		vfree(dxpGraphicsData.displaybuffer[1].texvram);
		vfree(dxpGraphicsData.depthbuffer.texvram);
		return -1;
	}
	dxpGraphicsData.displaybuffer_back = &dxpGraphicsData.displaybuffer[0];
	dxpGraphicsData.rendertarget = dxpGraphicsData.displaybuffer_back;
	dxpGraphicsData.texture = NULL;
	dxpGraphicsData.clear_color_value = 0;
	dxpGraphicsData.clear_depth_value = 0;
	dxpGraphicsData.clear_stencil_value = 0;
	dxpGraphicsData.gustarted = 0;
	dxpGraphicsData.clear_depth = 0;
	dxpGraphicsData.clear_stencil = 0;
	dxpGraphicsData.bilinear_enable = 0;
	dxpGraphicsData.create_vram_graph = 1;
	dxpGraphicsData.create_swizzled_graph = 1;
	dxpGraphicsData.colorkey = 0;

	dxpGraphicsData.blendmode = DX_BLENDMODE_NOBLEND;
	dxpGraphicsData.drawstate = DXP_DRAWSTATE_EITHER;
	dxpGraphicsData.flag = 0xffffffff;
	dxpGraphicsData.forceupdate = 1;
	dxpGraphicsData.z_2d = 0;
	dxpGraphicsData.color = 0xffffffff;
	//dxpGraphicsData.usedepth = 0;
	//dxpGraphicsData.usedepth3d = 0;
	dxpGraphicsData.writedepth = 0;
	dxpGraphicsData.writedepth3d = 0;

	dxpGraphicsData.fog_color = 0xffffffff;
	dxpGraphicsData.fog_near = 10.0f;
	dxpGraphicsData.fog_far = 100.0f;

	dxpGraphicsData.intrafont_scissor[0] = 0;
	dxpGraphicsData.intrafont_scissor[1] = 0;
	dxpGraphicsData.intrafont_scissor[2] = 480;
	dxpGraphicsData.intrafont_scissor[3] = 272;

	dxpGraphicsData.depthfunc = GU_GEQUAL;

	for(i = 0;i < DXP_BUILDOPTION_TEXTURE_MAXNUM;++i)dxpGraphicsData.texarray[i] = NULL;
	for(i = 0;i < DXP_BUILDOPTION_GHANDLE_MAXNUM;++i)dxpGraphicsData.grapharray[i] = NULL;
	//GEのセットアップ
	sceGuInit();
	GUSTART
		
	sceGuDrawBuffer(dxpGraphicsData.display_psm,vGuPointer(dxpGraphicsData.displaybuffer[0].texvram),dxpGraphicsData.displaybuffer[0].pitch);
	sceGuDispBuffer(480,272,vGuPointer(dxpGraphicsData.displaybuffer[1].texvram),dxpGraphicsData.displaybuffer[1].pitch);

	sceGuOffset(2048 - (480/2),2048 - (272/2));
	sceGuViewport(2048,2048,480,272);
	sceGuScissor(
		dxpGraphicsData.intrafont_scissor[0],
		dxpGraphicsData.intrafont_scissor[1],
		dxpGraphicsData.intrafont_scissor[2],
		dxpGraphicsData.intrafont_scissor[3]
	);
	sceGuClearDepth(0);
	sceGuDepthRange(65535,0);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuFrontFace(GU_CW);
	sceGuShadeModel(GU_FLAT);
	sceGuTexScale(1.0f,1.0f);
	sceGuTexOffset(0.0f,0.0f);
	sceGuTexFilter(GU_NEAREST,GU_NEAREST);
	sceGuTexWrap(GU_CLAMP,GU_CLAMP);
	/*
		memo
		カメラ位置(画面横幅/2,画面縦幅/2,画面縦幅/(2 * tan(fovy)))
		注視点位置(画面横幅/2,画面縦幅/2,1)
		上    (0,1,0)
	*/
#ifndef DXP_BUILDOPTION_NO3D
	VECTOR v[3] = {{240,136,-235.5589f},{240,136,0},{0,1,0}};
	SetCameraPositionAndTargetAndUpVec(v[0],v[1],v[2]);

	sceGumMatrixMode(GU_MODEL);
	sceGumLoadIdentity();

	dxpGraphicsData.camera.aspect = 480.0f / 272.0f;
	dxpGraphicsData.camera.near = 0.5f;
	dxpGraphicsData.camera.far = 1000.0f;
	dxpGraphicsData.camera.fov = 60;
	dxpGraphics3dUpdateProjectionMatrix();
#endif

	GUFINISH;
	sceDisplayWaitVblankStart();
	GUSTART;
	sceGuDisplay(GU_TRUE);
	dxpGraphicsData.init = 1;


	return 0;
}
Exemplo n.º 19
0
//--------------------------------------------------------------------
// Función:    CParticles::Update
// Creador:    Nacho (AMD)
// Fecha:      Wednesday  14/02/2007  19:48:41
//--------------------------------------------------------------------
void CParticles::Update(float dt, CLevel* pTheLevel, CSound* pSoundPlayer)
{	
	CVideo * pVideo = CVideo::GetSingleton();

	m_fAngType3 += (240.0f * dt);
	m_fAngType3 = MAT_NormalizarAngulo360(m_fAngType3);

	CBall* pBall = pTheLevel->GetBall();
	CSmoke* pSmoke = pTheLevel->GetSmoke();

	VECTOR3 vecBallPos = pBall->GetPosition();
	VECTOR2 vecBallVel = pBall->GetVelocity();
	float fBallRadius = pBall->GetRadius();

	sceGuEnable(GU_BLEND);
	sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
	sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);

	ENEMY* pEnemies = pTheLevel->GetEnemies();
	int iNumEnemies = pTheLevel->GetNumEnemies();
	
	///--- TIPO 0: Disparo amarillo
	//////////////////////////////////////////////////////////////////////

	pVideo->EnableTexture(m_pTexture[0]);

	for (int i=0; i<MAX_PARTICLES; i++)
	{
		if (m_pParticleArray[0][i].enable)
		{			
			m_pParticleArray[0][i].timeStamp += dt;

			if (m_pParticleArray[0][i].timeStamp >= 5.0f)
			{
				m_pParticleArray[0][i].enable = false;
				m_pParticleArray[0][i].next = m_iFreeSlot[0];
				m_iFreeSlot[0] = i;

				continue;
			}

			m_pParticleArray[0][i].pos.x += m_pParticleArray[0][i].vel.x * dt;
			m_pParticleArray[0][i].pos.y += m_pParticleArray[0][i].vel.y * dt;


			stCollisionData data;

			data.radius = 1.0f;
			data.x = m_pParticleArray[0][i].pos.x;
			data.y = m_pParticleArray[0][i].pos.y;
			data.velX = m_pParticleArray[0][i].vel.x;
			data.velY = m_pParticleArray[0][i].vel.y;

			if (pTheLevel->TestCollision(&data, false))
			{		
				m_pParticleArray[0][i].pos.x = data.x;
				m_pParticleArray[0][i].pos.y = data.y;
				m_pParticleArray[0][i].vel.x = data.velX;
				m_pParticleArray[0][i].vel.y = data.velY;
			}

			for (int a=0; a<iNumEnemies; a++)
			{
				if (pEnemies[a].active)
				{					
					///--- sierra
					///--- rebota
					if ((pEnemies[a].type == 0) || (pEnemies[a].type == 3))
					{
						VECTOR3 vDis;
						VECTOR3 vTemp = {m_pParticleArray[0][i].pos.x, m_pParticleArray[0][i].pos.y, 4.0f};
						VECTOR3 vTemp2 = {pEnemies[a].posX + 4.0f, pEnemies[a].posY + 4.0f, 4.0f};

						MAT_VectorSubtract(&vDis, &vTemp2, &vTemp);

						float length = MAT_VectorQuadraticLength(&vDis);

						if (length < 6.25f)
						{
							m_pParticleArray[0][i].enable = false;
							m_pParticleArray[0][i].next = m_iFreeSlot[0];
							m_iFreeSlot[0] = i;

							pSmoke->AddExplosion(vTemp2, 20.0f, true);

							pEnemies[a].active = false;

							pSoundPlayer->Play(SOUND_ENE_EXPLO);

							break;
						}
					}
					///--- dirigidos
					///--- rectos
					else if ((pEnemies[a].type == 1) || (pEnemies[a].type == 2))
					{	
						VECTOR3 vTemp = {0};

						if (pEnemies[a].rot==0)
						{
							vTemp.x = pEnemies[a].posX+2.0f;
							vTemp.y = pEnemies[a].posY+4.0f;
						}						
						else if (pEnemies[a].rot==3)
						{
							vTemp.x = pEnemies[a].posX+4.0f;
							vTemp.y = pEnemies[a].posY+2.0f;
						}
						else if (pEnemies[a].rot==2)
						{
							vTemp.x = pEnemies[a].posX+6.0f;
							vTemp.y = pEnemies[a].posY+4.0f;
						}
						else if (pEnemies[a].rot==1)
						{
							vTemp.x = pEnemies[a].posX+4.0f;
							vTemp.y = pEnemies[a].posY+6.0f;						
						}	

						vTemp.z = 4.0f;

						VECTOR3 vDis;
						VECTOR3 vTemp2 = {m_pParticleArray[0][i].pos.x, m_pParticleArray[0][i].pos.y, 4.0f};
						
						MAT_VectorSubtract(&vDis, &vTemp, &vTemp2);

						float disx = vecBallPos.x - m_pParticleArray[0][i].pos.x,;

						float length = MAT_VectorQuadraticLength(&vDis);

						if (length < 6.0f)
						{
							m_pParticleArray[0][i].enable = false;
							m_pParticleArray[0][i].next = m_iFreeSlot[0];
							m_iFreeSlot[0] = i;

							pSmoke->AddExplosion(vTemp, 20.0f, true);

							pEnemies[a].active = false;

							pSoundPlayer->Play(SOUND_ENE_EXPLO);

							int pan = 127;

							if (disx < 0.0f)
							{
								if (disx < -32.0f)
								{
									pan = 255;
								}
								else
								{
									pan = MAT_Clamp(128 + (int)(((-disx) / 32.0f) * 127.0f), 128, 255);									
								}
							}
							else

							{
								if (disx > 32.0f)
								{
									pan = 0;
								}
								else
								{ 
									pan = MAT_Clamp((int)(127.0f - ((disx / 32.0f) * 127.0f)), 0, 127);
								}
							}

							pSoundPlayer->Play(SOUND_ENE_EXPLO, pan);

							break;
						}						
					}				
				}
			}

			if (!m_pParticleArray[0][i].enable)
				continue;

			///--- render

			sceGumMatrixMode(GU_MODEL);
			sceGumLoadIdentity();
			{
				VECTOR3 pos =  { m_pParticleArray[0][i].pos.x -1.0f,
					-(m_pParticleArray[0][i].pos.y + 1.0f), 4.0f };
				VECTOR3 scale = { 2.0f, 2.0f, 2.0f };
				sceGumTranslate(&pos);
				sceGumScale(&scale);			
			}			

			if (m_pParticleArray[0][i].timeStamp >= 4.0f)
			{
				int alpha = (int)MAT_Clampf((5.0f - m_pParticleArray[0][i].timeStamp) * 255.0f, 0.0f, 255.0f);

				sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);

				sceGuAmbientColor(COLOR_ARGB(alpha, 255, 255, 255));

				m_pQuad->Render();

				sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, COLOR_ARGB(alpha, alpha, alpha, alpha), 0xffffffff);

				m_pQuad->Render();

				sceGuAmbientColor(0xffffffff);
			}
			else
			{
				sceGuAmbientColor(0xffffffff);

				m_pQuad->Render();

				sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0xffffffff, 0xffffffff);

				m_pQuad->Render();
			}

			sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);			
		}