Graphics

phire edited this page Nov 10, 2010 · 4 revisions

To get graphics working you must specify the following libs in the makefile: -lgcm_sys -lreality -lsysutil

Description about how it all works goes here

To initialize the graphics, do somethings like this:

// Allocate a 1Mb buffer, alligned to a 1Mb boundary to be our shared IO memory with the RSX.
void *host_addr = memalign(1024*1024, 1024*1024);
assert(host_addr != NULL);

// Initilise Reality, which sets up the command buffer and shared IO memory
context = realityInit(0x10000, 1024*1024, host_addr); 
assert(context != NULL);

VideoState state;
assert(videoGetState(0, 0, &state) == 0); // Get the state of the display
assert(state.state == 0); // Make sure display is enabled

// Get the current resolution
assert(videoGetResolution(state.displayMode.resolution, &res) == 0);

pitch = 4 * res.width; // each pixel is 4 bytes

// Configure the buffer format to xRGB
VideoConfiguration vconfig;
memset(&vconfig, 0, sizeof(VideoConfiguration));
vconfig.resolution = state.displayMode.resolution;
vconfig.format = VIDEO_BUFFER_FORMAT_XRGB;
vconfig.pitch = pitch;

assert(videoConfigure(0, &vconfig, NULL, 0) == 0);
assert(videoGetState(0, 0, &state) == 0); 

s32 buffer_size = pitch * res.height; 
printf("buffers will be 0x%x bytes\n", buffer_size);

gcmSetFlipMode(GCM_FLIP_VSYNC); // Wait for VSYNC to flip

// Allocate two buffers for the RSX to draw to the screen (double buffering)
buffer[0] = rsxMemAlign(16, buffer_size);
buffer[1] = rsxMemAlign(16, buffer_size);
assert(buffer[0] != NULL && buffer[1] != NULL);

assert(realityAddressToOffset(buffer[0], &offset[0]) == 0);
assert(realityAddressToOffset(buffer[1], &offset[1]) == 0);
// Setup the display buffers
assert(gcmSetDisplayBuffer(0, offset[0], pitch, res.width, res.height) == 0);
assert(gcmSetDisplayBuffer(1, offset[1], pitch, res.width, res.height) == 0);

gcmResetFlipStatus();

Which gives you two buffers in the RSX's memory which you can draw to and flip onto the screen.