Graphics Reference
In-Depth Information
This result bubbles back up the call
stack to the
CAOpenGLLayer
-derived
class,
OpenGLVidGridLayer
's
-canDrawInCGLContext
. If all the chan-
nels are ready to draw,
YES
is returned
and
-drawInCGLContext
is called.
NOTE
Look back at the call to
-drawInCGLContext
in Listing 8-8. It is also greatly simplified as
we have offloaded most of the work to the
VideoChannelController
and
VideoChannel
objects.
When
-drawInCGLContext
is called, we
pass the main rectangle of the window
to the video controller with a call to
[videoController drawAllInRect:bounds]
, where
bounds
is the rectangle, as shown in Listing 8-11.
LISTING 8-11
Implementing drawAllInRect
- (
void
)drawAllInRect:(
NSRect
)rect;
{
GLfloat
minX, minY, maxX, maxY;
minX =
NSMinX
(rect);
minY =
NSMinY
(rect);
maxX =
NSMaxX
(rect);
maxY =
NSMaxY
(rect);
glMatrixMode
(
GL_MODELVIEW
);
glLoadIdentity
();
glMatrixMode
(
GL_PROJECTION
);
glLoadIdentity
();
glOrtho
(minX, maxX, minY, maxY, -1.0, 1.0);
glClearColor
(0.0, 0.0, 0.0, 0.0);
glClear
(
GL_COLOR_BUFFER_BIT
);
int
i = 0;
for
(i=0; i<[
videoChannels count
]; ++i)
{
VideoChannel
*currentChannel = [
videoChannels objectAtIndex
:i];
[currentChannel
drawChannel
];
}
}
If you compare Listing 8-11 with Listing 8-5, you can see some clear similarities. The
OpenGL calls we make here are setup calls to draw the quads properly. When those setup
calls are made, we iterate through the list of
VideoChannel
objects and tell each of them
to draw their current frame instead of doing all the drawing code as we did in Listing 8-5.