#include <tamtypes.h>PS2 executable file: graph3.elf
#include <dma.h>
#include <stdio.h>
#include <graph.h>
#include <malloc.h>
#include <packet.h>
int main() { int loop0;
PACKET packet;
// Initialize the dma library.
dma_initialize();
// Initialize the graphics library.
graph_initialize();
// Allocate space for the packet.
packet_allocate(&packet, 1024);
// Set the mode.
graph_set_mode(GRAPH_MODE_AUTO, GRAPH_PSM_32, GRAPH_PSM_32);
// Set the display buffer.
graph_set_displaybuffer(0);
// Set the draw buffer.
graph_set_drawbuffer(0);
// Set the zbuffer.
graph_set_zbuffer(graph_get_width() * graph_get_height() * (graph_get_bpp() >> 3));
// Clear the screen.
graph_set_clearbuffer(0, 64, 0);
// Draw 20 squares...
for (loop0=0;loop0<20;loop0++) {
// Wait for the vsync period.
graph_wait_vsync();
// Reset the packet.
packet_reset(&packet);
// Draw another square on the screen.
packet_append_64(&packet, GIF_SET_TAG(4, 1, 0, 0, 0, 1));
packet_append_64(&packet, 0x0E);
packet_append_64(&packet, GIF_SET_PRIM(6, 0, 0, 0, 0, 0, 0, 0, 0));
packet_append_64(&packet, GIF_REG_PRIM);
packet_append_64(&packet, GIF_SET_RGBAQ((loop0 * 10), 0, 255 - (loop0 * 10), 0x80, 0x3F800000));
packet_append_64(&packet, GIF_REG_RGBAQ);
packet_append_64(&packet, GIF_SET_XYZ((1800) << 4, ((loop0 * 10) + 1900) << 4, 0));
packet_append_64(&packet, GIF_REG_XYZ2);
packet_append_64(&packet, GIF_SET_XYZ((1900) << 4, ((loop0 * 10) + 2000) << 4, 0));
packet_append_64(&packet, GIF_REG_XYZ2);
/* packet_append_64(&packet, GIF_SET_XYZ(((loop0 * 20) + 1800) << 4, (1900) << 4, 0));
packet_append_64(&packet, GIF_REG_XYZ2);
packet_append_64(&packet, GIF_SET_XYZ(((loop0 * 20) + 1900) << 4, (2000) << 4, 0));
packet_append_64(&packet, GIF_REG_XYZ2);
*/
// Send off the packet.
packet_send(&packet, DMA_CHANNEL_GIF, DMA_FLAG_NORMAL);
}
// Shut down the graphics library.
graph_shutdown();
// Shut down the dma library.
dma_shutdown();
// End program.
return 0;
}
#include <tamtypes.h>
#include <dma.h>
#include <stdio.h>
#include <graph.h>
#include <malloc.h>
#include <packet.h>
int main() { int loop0;
PACKET packet;
// Initialize the dma library.
dma_initialize();
// Initialize the graphics library.
graph_initialize();
// Allocate space for the packet.
packet_allocate(&packet, 1024);
// Set the mode.
graph_set_mode(GRAPH_MODE_AUTO, GRAPH_PSM_32, GRAPH_PSM_32);
// Set the display buffer.
graph_set_displaybuffer(0);
// Set the draw buffer.
graph_set_drawbuffer(0);
// Set the zbuffer.
graph_set_zbuffer(graph_get_width() * graph_get_height() * (graph_get_bpp() >> 3));
// Clear the screen.
graph_set_clearbuffer(0, 64, 0);
// Draw 20 squares...
for (loop0=0;loop0<20;loop0++) {
// Wait for the vsync period.
graph_wait_vsync();
// Reset the packet.
packet_reset(&packet);
// Draw another square on the screen.
packet_append_64(&packet, GIF_SET_TAG(4, 1, 0, 0, 0, 1));
packet_append_64(&packet, 0x0E);
packet_append_64(&packet, GIF_SET_PRIM(6, 0, 0, 0, 0, 0, 0, 0, 0));
packet_append_64(&packet, GIF_REG_PRIM);
packet_append_64(&packet, GIF_SET_RGBAQ((loop0 * 10), 0, 255 - (loop0 * 10), 0x80, 0x3F800000));
packet_append_64(&packet, GIF_REG_RGBAQ);
packet_append_64(&packet, GIF_SET_XYZ(((loop0 * 20) + 1800) << 4, (1900) << 4, 0));
packet_append_64(&packet, GIF_REG_XYZ2);
packet_append_64(&packet, GIF_SET_XYZ(((loop0 * 20) + 1900) << 4, (2000) << 4, 0));
packet_append_64(&packet, GIF_REG_XYZ2);
// Send off the packet.
packet_send(&packet, DMA_CHANNEL_GIF, DMA_FLAG_NORMAL);
}
// Shut down the graphics library.
graph_shutdown();
// Shut down the dma library.
dma_shutdown();
// End program.
return 0;
}
#include <tamtypes.h>PS2 executable file: graph.elf
#include <dma.h>
#include <stdio.h>
#include <graph.h>
#include <malloc.h>
#include <packet.h>
int main() { int loop0;
PACKET packet;
// Initialize the dma library.
dma_initialize();
// Initialize the graphics library.
graph_initialize();
// Allocate space for the packet.
packet_allocate(&packet, 1024);
// Set the mode.
graph_set_mode(GRAPH_MODE_AUTO, GRAPH_PSM_32, GRAPH_PSM_32);
// Set the display buffer.
graph_set_displaybuffer(0);
// Set the draw buffer.
graph_set_drawbuffer(0);
// Set the zbuffer.
graph_set_zbuffer(graph_get_width() * graph_get_height() * (graph_get_bpp() >> 3));
// Clear the screen.
graph_set_clearbuffer(0, 64, 0);
// Draw 20 squares...
for (loop0=0;loop0<20;loop0++) {
// Wait for the vsync period.
graph_wait_vsync();
// Reset the packet.
packet_reset(&packet);
// Draw another square on the screen.
packet_append_64(&packet, GIF_SET_TAG(4, 1, 0, 0, 0, 1));
packet_append_64(&packet, 0x0E);
packet_append_64(&packet, GIF_SET_PRIM(6, 0, 0, 0, 0, 0, 0, 0, 0));
packet_append_64(&packet, GIF_REG_PRIM);
packet_append_64(&packet, GIF_SET_RGBAQ((loop0 * 10), 0, 255 - (loop0 * 10), 0x80, 0x3F800000));
packet_append_64(&packet, GIF_REG_RGBAQ);
packet_append_64(&packet, GIF_SET_XYZ(((loop0 * 20) + 1800) << 4, ((loop0 * 10) + 1900) << 4, 0));
packet_append_64(&packet, GIF_REG_XYZ2);
packet_append_64(&packet, GIF_SET_XYZ(((loop0 * 20) + 1900) << 4, ((loop0 * 10) + 2000) << 4, 0));
packet_append_64(&packet, GIF_REG_XYZ2);
// Send off the packet.
packet_send(&packet, DMA_CHANNEL_GIF, DMA_FLAG_NORMAL);
}
// Shut down the graphics library.
graph_shutdown();
// Shut down the dma library.
dma_shutdown();
// End program.
return 0;
}
Another source file holding vertices data: mesh_data.c
#include <tamtypes.h>
#include <dma.h>
#include <draw.h>
#include <stdio.h>
#include <graph.h>
#include <malloc.h>
#include <math3d.h>
#include <packet.h>
#include <string.h>
#include "mesh_data.c"
VECTOR object_position = { 0.00f, 0.00f, 0.00f, 1.00f };
VECTOR object_rotation = { 0.00f, 0.00f, 0.00f, 1.00f };
VECTOR camera_position = { 0.00f, 0.00f, 100.00f, 1.00f };
VECTOR camera_rotation = { 0.00f, 0.00f,
0.00f, 1.00f };
//////////////////
// MAIN PROGRAM //
//////////////////
int main(int argc, char **argv) {
MATRIX local_world;
MATRIX world_view;
MATRIX view_screen;
MATRIX local_screen;
VECTOR *temp_vertices;
u64 *xyz;
u64 *rgbaq;
u64 *st;
FILE *infile;
int texture_size;
u8 *texture_data;
// Allocate calculation space.
temp_vertices = memalign(128, sizeof(VECTOR) * vertex_count);
// Allocate register space.
xyz = memalign(128, sizeof(u64) *
vertex_count);
rgbaq = memalign(128, sizeof(u64) * vertex_count);
st = memalign(128, sizeof(u64)
* vertex_count);
// Initialize the draw library.
draw_initialize(GRAPH_MODE_AUTO, GRAPH_PSM_32, GRAPH_PSM_32);
// Create the view_screen matrix.
create_view_screen(view_screen, graph_get_aspect(), -3.00f,
3.00f, -3.00f, 3.00f, 1.00f, 2000.00f);
// Open the texture file.
infile = fopen("host:texture.raw", "r");
// Determine the texture data size.
fseek(infile, 0, SEEK_END); texture_size = ftell(infile);
fseek(infile, 0, SEEK_SET);
// Allocate space for the texture data.
texture_data = memalign(128, texture_size);
// Load the texture data.
fread(texture_data, texture_size, 1, infile);
// Upload the texture to vram.
graph_vram_write(3145728, 256, 256, GRAPH_PSM_24,
texture_data, texture_size);
// Free the texture data space.
free(texture_data);
// Close the texture file.
fclose(infile);
// The main loop...
for (;;) {
// Spin the cube a bit.
object_rotation[0] += 0.008f; while
(object_rotation[0] > 3.14f) { object_rotation[0] -= 6.28f; }
object_rotation[1] += 0.012f; 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 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 vertex values.
calculate_vertices(temp_vertices, vertex_count,
vertices, local_screen);
// Generate the XYZ register values.
draw_generate_xyz(xyz, vertex_count,
temp_vertices);
// Generate the RGBAQ register values.
draw_generate_rgbaq(rgbaq, vertex_count,
temp_vertices, colours);
// Generate the ST register values.
draw_generate_st(st, vertex_count, temp_vertices,
coordinates);
// Wait for vsync.
graph_wait_vsync();
// Swap the buffers.
draw_swap();
// Clear the screen.
draw_clear(0.50f, 0.50f, 0.50f);
// Set texture texture information.
graph_set_texture(3145728, 256, 256, GRAPH_PSM_24);
// Draw the textured triangles.
draw_triangles_textured(points, points_count, xyz,
rgbaq, st);
}
// End program.
return 0;
}
teapot sample with xlink + (fat) PS2 + slingbox + laptop | teapot sample on ps2 emulator PCSX2 |
#include <tamtypes.h>Another source file holding vertices data: mesh_data.c
#include <dma.h>
#include <draw.h>
#include <stdio.h>
#include <graph.h>
#include <malloc.h>
#include <math3d.h>
#include <packet.h>
#include <string.h>
#include "mesh_data.c"
VECTOR object_position = { 0.00f, 0.00f, 0.00f, 1.00f };
VECTOR object_rotation = { 0.00f, 0.00f, 0.00f, 1.00f };
VECTOR camera_position = { 0.00f, 0.00f, 100.00f, 1.00f };
VECTOR camera_rotation = { 0.00f, 0.00f,
0.00f, 1.00f };
int light_count = 4;
VECTOR light_direction[4] = {
{ 0.00f, 0.00f, 0.00f, 1.00f },
{ 1.00f, 0.00f, -1.00f, 1.00f },
{ 0.00f, 1.00f, -1.00f, 1.00f },
{ -1.00f, -1.00f, -1.00f, 1.00f }
};
VECTOR light_colour[4] = {
{ 0.00f, 0.00f, 0.00f, 1.00f },
{ 1.00f, 0.00f, 0.00f, 1.00f },
{ 0.30f, 0.30f, 0.30f, 1.00f },
{ 0.50f, 0.50f, 0.50f, 1.00f }
};
int light_type[4] = {
LIGHT_AMBIENT,
LIGHT_DIRECTIONAL,
LIGHT_DIRECTIONAL,
LIGHT_DIRECTIONAL
};
//////////////////
// MAIN PROGRAM //
//////////////////
int main(int argc, char **argv) {
MATRIX local_world;
MATRIX local_light;
MATRIX world_view;
MATRIX view_screen;
MATRIX local_screen;
VECTOR *temp_normals;
VECTOR *temp_lights;
VECTOR *temp_colours;
VECTOR *temp_vertices;
u64 *xyz;
u64 *rgbaq;
// Allocate calculation space.
temp_normals = memalign(128, sizeof(VECTOR) *
vertex_count);
temp_lights = memalign(128,
sizeof(VECTOR) * vertex_count);
temp_colours = memalign(128, sizeof(VECTOR) *
vertex_count);
temp_vertices = memalign(128, sizeof(VECTOR) * vertex_count);
// Allocate register space.
xyz = memalign(128, sizeof(u64) *
vertex_count);
rgbaq = memalign(128, sizeof(u64) * vertex_count);
// Initialize the draw library.
draw_initialize(GRAPH_MODE_AUTO, GRAPH_PSM_32, GRAPH_PSM_32);
// Create the view_screen matrix.
create_view_screen(view_screen, graph_get_aspect(), -3.00f,
3.00f, -3.00f, 3.00f, 1.00f, 2000.00f);
// The main loop...
for (;;) {
// Spin the teapot a bit.
object_rotation[0] += 0.008f; while
(object_rotation[0] > 3.14f) { object_rotation[0] -= 6.28f; }
object_rotation[1] += 0.112f; 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(temp_colours, vertex_count,
colours, temp_lights);
// Calculate the vertex values.
calculate_vertices(temp_vertices, vertex_count,
vertices, local_screen);
// Generate the XYZ register values.
draw_generate_xyz(xyz, vertex_count,
temp_vertices);
// Generate the RGBAQ register values.
draw_generate_rgbaq(rgbaq, vertex_count,
temp_vertices, temp_colours);
// Wait for vsync.
graph_wait_vsync();
// Swap the buffers.
draw_swap();
// Clear the screen.
draw_clear(0.00f, 0.00f, 0.00f);
// Draw the triangles.
draw_triangles(points, points_count, xyz, rgbaq);
}
// End program.
return 0;
}
#include <tamtypes.h>
#include <dma.h>
#include <draw.h>
#include <stdio.h>
#include <graph.h>
#include <malloc.h>
#include <math3d.h>
#include <packet.h>
#include <string.h>
#include "mesh_data.c"
VECTOR object_position = { 0.00f, 0.00f, 0.00f, 1.00f };
VECTOR object_rotation = { 0.00f, 0.00f, 0.00f, 1.00f };
VECTOR camera_position = { 0.00f, 0.00f, 100.00f, 1.00f };
VECTOR camera_rotation = { 0.00f, 0.00f,
0.00f, 1.00f };
//////////////////
// MAIN PROGRAM //
//////////////////
int main(int argc, char **argv) {
MATRIX local_world;
MATRIX world_view;
MATRIX view_screen;
MATRIX local_screen;
VECTOR *temp_vertices;
u64 *xyz;
u64 *rgbaq;
// Allocate calculation space.
temp_vertices = memalign(128, sizeof(VECTOR) * vertex_count);
// Allocate register space.
xyz = memalign(128, sizeof(u64) *
vertex_count);
rgbaq = memalign(128, sizeof(u64) * vertex_count);
// Initialize the draw library.
draw_initialize(GRAPH_MODE_AUTO, GRAPH_PSM_32, GRAPH_PSM_32);
// Create the view_screen matrix.
create_view_screen(view_screen, graph_get_aspect(), -3.00f,
3.00f, -3.00f, 3.00f, 1.00f, 2000.00f);
// The main loop...
for (;;) {
// Spin the cube a bit.
object_rotation[0] += 0.008f; while
(object_rotation[0] > 3.14f) { object_rotation[0] -= 6.28f; }
object_rotation[1] += 0.012f; 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 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 vertex values.
calculate_vertices(temp_vertices, vertex_count,
vertices, local_screen);
// Generate the XYZ register values.
draw_generate_xyz(xyz, vertex_count,
temp_vertices);
// Generate the RGBAQ register values.
draw_generate_rgbaq(rgbaq, vertex_count,
temp_vertices, colours);
// Wait for vsync.
graph_wait_vsync();
// Swap the buffers.
draw_swap();
// Clear the screen.
draw_clear(0.00f, 0.00f, 0.00f);
// Draw the triangles.
draw_triangles(points, points_count, xyz, rgbaq);
}
// End program.
return 0;
}