I've tried my custom view in a standalone app. and all seems smooth with resizing. Is there anything I need to know regarding using OpenGL inside an FxPlug plugin? I'm writing the plugin for Final Cut Pro.
Any tips or advice would be helpful.
Here's the implementation of my custom view - for now it draws a polygon in the middle of the view:
@implementation CustomView
+ (NSOpenGLPixelFormat *)defaultPixelFormat
{
NSLog(@"%s", __func__);
NSOpenGLPixelFormatAttribute attributes[] =
{
NSOpenGLPFADoubleBuffer,
NSOpenGLPFABackingStore,
NSOpenGLPFADepthSize, 32,
0
};
NSOpenGLPixelFormat *pixelFormat =
[[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]
autorelease];
return pixelFormat;
}
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame
pixelFormat:[[self class] defaultPixelFormat]];
return self;
}
- (id)init
{
self = [super initWithFrame:NSMakeRect(0, 0, 200, 200)
pixelFormat:[[self class] defaultPixelFormat]];
return self;
}
- (void)prepareOpenGL
{
GLint parm = 1;
[[self openGLContext] setValues:&parm forParameter:NSOpenGLCPSwapInterval];
glDisable(GL_DITHER);
glDisable(GL_ALPHA_TEST);
glDisable(GL_BLEND);
glDisable(GL_STENCIL_TEST);
glDisable(GL_FOG);
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glPixelZoom(1.0, 1.0);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
- (void)drawRect:(NSRect)rect
{
NSLog(@"%s", __func__);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0, .5, .5);
glBegin(GL_POLYGON);
glVertex3f(.25, .25, 0);
glVertex3f(.75, .25, 0);
glVertex3f(.75, .75, 0);
glVertex3f(.25, .75, 0);
glEnd();
[[self openGLContext] flushBuffer];
}
- (void)reshape
{
NSLog(@"%s %@", __func__, NSStringFromRect([self bounds]));
NSRect rect = [self bounds];
glViewport(0, 0, rect.size.width, rect.size.height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 1, 0, 1, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
@end