HP SVA V2.0 Parallel Compositing Reference Guide
function, glDrawPixels. Once again, it is important that the program properly describes
the pixels to OpenGL. All the information for doing this is available in the PCchannel
structure returned by pcFrameResultChannel.
The following segment of code retrieves the color channel and properly draws in a window.
PCchannel channel;
err = pcFrameResultChannel(g_ctx, frameId, 0, 0, width, height,
PC_CHANNEL_COLOR, &channel);
if(err != PC_NO_ERROR) reportError(err);
/* Decide the pixel format to use with GL from the channel structure
The code below is just intended to show how to handle the general case */
switch(channel.pixelFormat){
case PC_PF_BGRA8:
format = GL_BGRA; break;
case PC_PF_BGR8:
format = GL_BGR; break;
case PC_PF_RGBA8:
format = GL_RGBA; break;
default:
assert(!"Invalid pixel format - this can't happen");
}
/* Setup the proper alignment for glDrawPixels to work cleanly */
glPixelStorei(GL_UNPACK_ALIGNMENT, channel.alignment);
/* Setup ROW_LENGTH if needed, again needed for glDrawPixels */
if(channel.rowLength != channel.width){
glPixelStorei(GL_UNPACK_ROW_LENGTH, channel.rowLength);
}
else {
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); /* this is also the default */
}
/* Setup the raster position to the bottom left of the window */
glWindowPos2iARB(0,0);
/* Draw the results */
glDisable(GL_DEPTH_TEST);
glDrawPixels(channel.width, channel.height, format, type, channel.address);
The part of this sequence that is most often overlooked is the alignment. OpenGL may default
to buffers where rows are aligned with the memory data on 4 byte boundary or 8 byte
boundary. OpenGL default alignment is 4.
• GLUT Use in an Application
GLUT is a convenient toolkit to use when writing OpenGL applications. It can be used with
the Library; however, certain sequences that work on a single node need to be modified for
a distributed application. Many of the samples included as part of the HP Library Kit use
GLUT.
This tip outlines restrictions on using GLUT and suggests the use of techniques from the
samples.
GLUT lets a program supply a display function, an idle function, reshape function, and a
keyboard function. For a distributed application, GLUT calls the idle function a different
number of times on each node. So you should be careful about using the idle function as a
means of tracking the progression of time.
The samples vary their use of GLUT; however, it is generally based on one host (frequently
the master) getting user input events. This host processes these events. It then communicates
to the remaining hosts any actions they need to take as a result of the input events.
To get input events, a host needs to have a window manager running. By default, SVA job
launch scripts only start the Xserver; they do not start a window manager. In the scripts
1.7 Coding Tips 23