Beispiel #1
0
};

static float aspectWidth;
static float aspectHeight;

// Transposition values - all rendering can be transposed (moved on screen) by these
static float transX = 0;
static float transY = 0;

const u64 gColWhite = GS_SETREG_RGBA(0xFF,0xFF,0xFF,0x00);
const u64 gColBlack = GS_SETREG_RGBA(0x00,0x00,0x00,0x00);
const u64 gColDarker = GS_SETREG_RGBA(0x00,0x00,0x00,0x60);
const u64 gColFocus = GS_SETREG_RGBA(0xFF,0xFF,0xFF,0x50);

const u64 gDefaultCol = GS_SETREG_RGBA(0x80,0x80,0x80,0x80);
const u64 gDefaultAlpha = GS_SETREG_ALPHA(0,1,0,1,0);

static float shiftYVal;
static float (*shiftY)(float posY);

static float shiftYFunc(float posY) {
	return (int) (shiftYVal * posY);
}

static float identityFunc(float posY) {
	return posY;
}

static void rmAppendUploadedTextures(GSTEXTURE *txt) {
	struct rm_texture_list_t *entry = (struct rm_texture_list_t *)malloc(sizeof(struct rm_texture_list_t));
	entry->clut = NULL;
Beispiel #2
0
int main(void)
{
	GSGLOBAL *gsGlobal = gsKit_init_global();
//GS_MODE_VGA_640_60
#ifdef HAVE_LIBTIFF
	GSTEXTURE Sprite;
    u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);
#endif
	u64 White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00);
    u64 Red = GS_SETREG_RGBAQ(0xFF,0x00,0x00,0x00,0x00);
    u64 Green = GS_SETREG_RGBAQ(0x00,0xFF,0x00,0x00,0x00);
	u64 Blue = GS_SETREG_RGBAQ(0x00,0x00,0xFF,0x00,0x00);
	u64 BlueTrans = GS_SETREG_RGBAQ(0x00,0x00,0xFF,0x40,0x00);


        float x = 10;
        float y = 10;
        float width = 150;
        float height = 150;

	float VHeight = gsGlobal->Height;

	gsGlobal->PSM = GS_PSM_CT24;
	gsGlobal->PSMZ = GS_PSMZ_16S;
//	gsGlobal->DoubleBuffering = GS_SETTING_OFF;
//	gsGlobal->ZBuffering = GS_SETTING_OFF;

	dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
		    D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);

	// Initialize the DMAC
	dmaKit_chan_init(DMA_CHANNEL_GIF);
	dmaKit_chan_init(DMA_CHANNEL_FROMSPR);
	dmaKit_chan_init(DMA_CHANNEL_TOSPR);

	gsGlobal->PrimAlphaEnable = GS_SETTING_ON;

	gsKit_init_screen(gsGlobal);
#ifdef HAVE_LIBTIFF
	if(gsKit_texture_tiff(gsGlobal, &Sprite, "host:alpha.tiff") < 0)
	{
		printf("Loading Failed!\n");
	}
#endif
	gsKit_mode_switch(gsGlobal, GS_PERSISTENT);

	while(1)
	{
                if( y <= 10  && (x + width) < (gsGlobal->Width - 10))
                        x+=10;
                else if( (y + height)  <  (VHeight - 10) && (x + width) >= (gsGlobal->Width - 10) )
                        y+=10;
                else if( (y + height) >=  (VHeight - 10) && x > 10 )
                        x-=10;
                else if( y > 10 && x <= 10 )
                        y-=10;

		gsKit_clear(gsGlobal, White);

		gsKit_prim_quad_gouraud(gsGlobal, 250.0f, 50.0f, 250.0f, 400.0f,
						  400.0f, 50.0f, 400.0f, 400.0f,
						  1, Red, Green, Blue, White);

		gsKit_prim_sprite(gsGlobal, x, y, x + width, y + height, 2, BlueTrans);

		gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0,1,0,1,0), 0);
		gsKit_set_test(gsGlobal, GS_ATEST_OFF);
#ifdef HAVE_LIBTIFF
		gsKit_prim_sprite_texture(gsGlobal, &Sprite,	310.0f,  // X1
								50.0f,  // Y2
								0.0f,  // U1
								0.0f,  // V1
								Sprite.Width + 310.0f, // X2
								Sprite.Height +  50.0f, // Y2
								Sprite.Width, // U2
								Sprite.Height, // V2
								3,
								TexCol);
#endif
		gsKit_set_test(gsGlobal, GS_ATEST_ON);
		gsKit_set_primalpha(gsGlobal, GS_BLEND_BACK2FRONT, 0);

		gsKit_sync_flip(gsGlobal);

		gsKit_queue_exec(gsGlobal);

		gsKit_queue_reset(gsGlobal->Per_Queue);
	}

	return 0;
}
Beispiel #3
0
int render(GSGLOBAL *gsGlobal)
{
#ifdef TEX_BG
	u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);
	GSTEXTURE bigtex;
#endif
#ifdef FHD_BG
	GSTEXTURE fhdbg;
#endif
	int i;

	// Matrices to setup the 3D environment and camera
	MATRIX local_world;
	MATRIX local_light;
	MATRIX world_view;
	MATRIX view_screen;
	MATRIX local_screen;

	VECTOR *temp_normals;
	VECTOR *temp_lights;
	color_f_t *temp_colours;
	vertex_f_t *temp_vertices;

	xyz_t   *verts;
	color_t *colors;

	// Allocate calculation space.
	temp_normals  = (VECTOR     *)memalign(128, sizeof(VECTOR)     * vertex_count);
	temp_lights   = (VECTOR     *)memalign(128, sizeof(VECTOR)     * vertex_count);
	temp_colours  = (color_f_t  *)memalign(128, sizeof(color_f_t)  * vertex_count);
	temp_vertices = (vertex_f_t *)memalign(128, sizeof(vertex_f_t) * vertex_count);

	// Allocate register space.
	verts  = (xyz_t   *)memalign(128, sizeof(xyz_t)   * vertex_count);
	colors = (color_t *)memalign(128, sizeof(color_t) * vertex_count);

#ifdef TEX_BG
	bigtex.Filter = GS_FILTER_LINEAR;
	bigtex.Delayed = 0;
	gsKit_texture_jpeg(gsGlobal, &bigtex, "host:bigtex.jpg");
#endif

#ifdef FHD_BG
	fhdbg.Filter = GS_FILTER_LINEAR;
	fhdbg.Delayed = 1;
	fhdbg.Vram = GSKIT_ALLOC_ERROR;
	gsKit_texture_jpeg(gsGlobal, &fhdbg, "host:fhdbg.jpg");
	gsKit_hires_prepare_bg(gsGlobal, &fhdbg);
	gsKit_hires_set_bg(gsGlobal, &fhdbg);
#endif

	printf("VRAM used: %dKiB\n", gsGlobal->CurrentPointer / 1024);
	printf("VRAM free: %dKiB\n", 4096 - (gsGlobal->CurrentPointer / 1024));

	// Create the view_screen matrix.
	create_view_screen(view_screen, 16.0f/9.0f, -0.20f, 0.20f, -0.20f, 0.20f, 1.00f, 2000.00f);

	if (gsGlobal->ZBuffering == GS_SETTING_ON)
		gsKit_set_test(gsGlobal, GS_ZTEST_ON);

	// A,B,C,D,FIX = 0,1,0,1,0:
	// A = 0 = Cs (Color Source)
	// B = 1 = Cd (Color Destination)
	// C = 0 = As (Alpha Source)
	// D = 1 = Cd (Color Destination)
	// FIX = not used
	//
	// Resulting color = (A-B)*C+D = (Cs-Cd)*As+Cd
	// This will blend the source over the destination
	// Note:
	// - Alpha 0x00 = fully transparent
	// - Alpha 0x80 = fully visible
	gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 128), 0);
	gsGlobal->PrimAlphaEnable = GS_SETTING_OFF;
	gsGlobal->PrimAAEnable = GS_SETTING_ON;

	// The main loop...
	for (;;)
	{
		// Spin the teapot a bit.
		object_rotation[1] += 0.005f; while (object_rotation[1] > 3.14f) { object_rotation[1] -= 6.28f; }

		// Create the local_world matrix.
		create_local_world(local_world, object_position, object_rotation);

		// Create the local_light matrix.
		create_local_light(local_light, object_rotation);

		// Create the world_view matrix.
		create_world_view(world_view, camera_position, camera_rotation);

		// Create the local_screen matrix.
		create_local_screen(local_screen, local_world, world_view, view_screen);

		// Calculate the normal values.
		calculate_normals(temp_normals, vertex_count, normals, local_light);

		// Calculate the lighting values.
		calculate_lights(temp_lights, vertex_count, temp_normals, light_direction, light_colour, light_type, light_count);

		// Calculate the colour values after lighting.
		calculate_colours((VECTOR *)temp_colours, vertex_count, colours, temp_lights);

		// Calculate the vertex values.
		calculate_vertices((VECTOR *)temp_vertices, vertex_count, vertices, local_screen);

		// Convert floating point vertices to fixed point and translate to center of screen.
		draw_convert_xyz(verts, 2048, 2048, 16, vertex_count, temp_vertices);

		// Convert floating point colours to fixed point.
		draw_convert_rgbq(colors, vertex_count, temp_vertices, temp_colours, 0x80);

#ifdef DYNAMIC_DITHERING
		// Dithering:
		// The standard 4x4 dithering matrix creates static noise to eliminate banding.
		// This static noise is a little visible, and can be improved by changing the matrix every frame
		// Keep adding 5 to get the most noisy pattern possible:
		//   0, 5, 2, 7, 4, 1, 6, 3
		for(i = 0; i < 15; i++)
		    gsGlobal->DitherMatrix[i] = (gsGlobal->DitherMatrix[i] + 5) & 7;
		gsKit_set_dither_matrix(gsGlobal);
#endif

#ifdef TEX_BG
		if(bigtex.Vram != GSKIT_ALLOC_ERROR) {
			gsKit_prim_sprite_texture(gsGlobal, &bigtex,
									0.0f,	// X1
									0.0f,	// Y1
									0.0f,	// U1
									0.0f,	// V1
									gsGlobal->Width,	// X2
									gsGlobal->Height,	// Y2
									bigtex.Width,		// U2
									bigtex.Height,		// V2
									2,
									TexCol);
		}
#endif

		for (i = 0; i < points_count; i+=3) {
			float fX=gsGlobal->Width/2;
			float fY=gsGlobal->Height/2;
			gsKit_prim_triangle_gouraud_3d(gsGlobal
				, (temp_vertices[points[i+0]].x + 1.0f) * fX, (temp_vertices[points[i+0]].y + 1.0f) * fY, verts[points[i+0]].z
				, (temp_vertices[points[i+1]].x + 1.0f) * fX, (temp_vertices[points[i+1]].y + 1.0f) * fY, verts[points[i+1]].z
				, (temp_vertices[points[i+2]].x + 1.0f) * fX, (temp_vertices[points[i+2]].y + 1.0f) * fY, verts[points[i+2]].z
				, colors[points[i+0]].rgbaq, colors[points[i+1]].rgbaq, colors[points[i+2]].rgbaq);
		}
#ifdef HIRES_MODE
		gsKit_hires_sync(gsGlobal);
		gsKit_hires_flip(gsGlobal);
#else
		gsKit_queue_exec(gsGlobal);
		gsKit_sync_flip(gsGlobal);
#endif
	}

	free(temp_normals);
	free(temp_lights);
	free(temp_colours);
	free(temp_vertices);
	free(verts);
	free(colors);

	return 0;

}
Beispiel #4
0
int main(void)
{
	GSGLOBAL *gsGlobal = gsKit_init_global();
//GS_MODE_VGA_640_60
	GSTEXTURE Sprite;
	u64 White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00);
#ifdef HAVE_LIBPNG
	u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);
#endif
	gsGlobal->PSM = GS_PSM_CT24;
	gsGlobal->PSMZ = GS_PSMZ_16S;
//	gsGlobal->DoubleBuffering = GS_SETTING_OFF;
//	gsGlobal->ZBuffering = GS_SETTING_OFF;

	dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
		    D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);

	// Initialize the DMAC
	dmaKit_chan_init(DMA_CHANNEL_GIF);

	gsGlobal->PrimAlphaEnable = GS_SETTING_ON;

	gsKit_init_screen(gsGlobal);

	Sprite.Delayed = GS_SETTING_ON;

#ifdef HAVE_LIBPNG
	if(gsKit_texture_png(gsGlobal, &Sprite, "host:texstream.png") < 0)
	{
		printf("Loading Failed!\n");
	}
#endif

	Sprite.Vram = gsKit_vram_alloc(gsGlobal, gsKit_texture_size(Sprite.Width, Sprite.Height, Sprite.PSM), GSKIT_ALLOC_USERBUFFER);

	gsKit_mode_switch(gsGlobal, GS_ONESHOT);

	while(1)
	{
		gsKit_clear(gsGlobal, White);

		gsKit_texture_send_inline(gsGlobal, Sprite.Mem, Sprite.Width, Sprite.Height, Sprite.Vram, Sprite.PSM, Sprite.TBW, GS_CLUT_NONE);

		gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0,1,0,1,0), 0);
		gsKit_set_test(gsGlobal, GS_ATEST_OFF);
#ifdef HAVE_LIBPNG
		gsKit_prim_sprite_texture(gsGlobal, &Sprite,	310.0f,  // X1
								50.0f,  // Y2
								0.0f,  // U1
								0.0f,  // V1
								Sprite.Width + 310.0f, // X2
								Sprite.Height +  50.0f, // Y2
								Sprite.Width, // U2
								Sprite.Height, // V2
								3,
								TexCol);
#endif
		gsKit_set_test(gsGlobal, GS_ATEST_ON);
		gsKit_set_primalpha(gsGlobal, GS_BLEND_BACK2FRONT, 0);

		gsKit_sync_flip(gsGlobal);

		gsKit_queue_exec(gsGlobal);
	}

	return 0;
}
Beispiel #5
0
int main(void)
{
	GSGLOBAL *gsGlobal = gsKit_init_global();

	GSTEXTURE Tex1;
	int x = 0, y = 0;

#ifdef HAVE_LIBPNG
	u64 TexCol = GS_SETREG_RGBAQ(0x80,0x80,0x80,0x80,0x00);
#endif
	u64 White = GS_SETREG_RGBAQ(0xFF,0xFF,0xFF,0x00,0x00);
	u64 BlueTrans = GS_SETREG_RGBAQ(0x00,0x00,0xFF,0x40,0x00);
	u64 Green = GS_SETREG_RGBAQ(0x00,0xFF,0x00,0x00,0x00);

	gsGlobal->PSM = GS_PSM_CT32;
	gsGlobal->PSMZ = GS_PSMZ_16S;
	gsGlobal->ZBuffering = GS_SETTING_ON;

	dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
		    D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);

	// Initialize the DMAC
	dmaKit_chan_init(DMA_CHANNEL_GIF);
	dmaKit_chan_init(DMA_CHANNEL_FROMSPR);
	dmaKit_chan_init(DMA_CHANNEL_TOSPR);
#ifdef HAVE_LIBPNG
	printf("alpha\n");
	gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
#endif
	gsKit_init_screen(gsGlobal);

	float VHeight = gsGlobal->Height;

	gsKit_clear(gsGlobal, White);
#ifdef HAVE_LIBPNG
	gsKit_texture_png(gsGlobal, &Tex1, "host:test.png");
	printf("Texture 1 Height: %i\n",Tex1.Height);
	printf("Texture 1 Width: %i\n",Tex1.Width);

	printf("Texure 1 VRAM Range = 0x%X - 0x%X\n",Tex1.Vram, Tex1.Vram +gsKit_texture_size(Tex1.Width, Tex1.Height, Tex1.PSM) - 1);
#endif
	gsKit_mode_switch(gsGlobal, GS_PERSISTENT);

	while(1)
	{

        	if( y <= 10  && (x + Tex1.Width) < (gsGlobal->Width - 10))
			x+=10;
	        else if( (y + Tex1.Height)  <  (VHeight - 10) && (x + Tex1.Width) >= (gsGlobal->Width - 10) )
	                y+=10;
	        else if( (y + Tex1.Height) >=  (VHeight - 10) && x > 10 )
	                x-=10;
	        else if( y > 10 && x <= 10 )
	                y-=10;

		gsKit_clear(gsGlobal, Green);

		gsKit_prim_sprite(gsGlobal, x, y, x + Tex1.Width, y + Tex1.Height, 1, BlueTrans);
#ifdef HAVE_LIBPNG
		gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0,1,0,1,0), 0);
		gsKit_set_test(gsGlobal, GS_ATEST_OFF);

		gsKit_prim_sprite_texture(gsGlobal, &Tex1,	0.0f,  // X1
							0.0f,  // Y2
							0.0f,  // U1
							0.0f,  // V1
							Tex1.Width, // X2
							Tex1.Height, // Y2
							Tex1.Width, // U2
							Tex1.Height, // V2
							2,
							TexCol);


                gsKit_set_test(gsGlobal, GS_ATEST_ON);
                gsKit_set_primalpha(gsGlobal, GS_BLEND_BACK2FRONT, 0);
#endif
		gsKit_sync_flip(gsGlobal);
		gsKit_queue_exec(gsGlobal);
#ifdef HAVE_LIBPNG
		gsKit_queue_reset(gsGlobal->Per_Queue);
#endif
	}

	return 0;
}