• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
what kind of pictures am i allowed to draw onto NSOpenGLView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

what kind of pictures am i allowed to draw onto NSOpenGLView?


  • Subject: what kind of pictures am i allowed to draw onto NSOpenGLView?
  • From: eveningnick eveningnick <email@hidden>
  • Date: Sun, 01 May 2011 18:10:51 +0300

Hi

I am trying to find a way to display a set of images serially on
window. As far as i understood reading Apple programming guides (Core
image, OpenGL) and samples,  NSOpenGLView is the optimal choice for
the task, since it offers asynchrony and delegates anything possible
to the GPU.

According to the samples, to render some picture onto NSOpenGLView, i
need to subclass it, and do all the painting job into -drawRect
method. All the job - is calling CIContext's -drawImage method.
Previously i have to have a CIImage object, that contains an image.
The problem is that almost nothing i rendered. Almost - because
sometimes i get some "artifacts" for certain JPEG image files, but
most often i get a blank black view. It seems, like only special kind
of CIImage objects can be rendered.

An ordinary NSView's subclass does the same job perfectly. But i also
need to play a movie and display it in a view, and according to
samples NSOpenGLView is the preferred way.

Could you give me an advice what am i doing wrong?
Thanks!

Here's the implementation of my NSOpenGLView's subclass:

@implementation RenderingView
CIContext *ciContext;

-(void)awakeFromNib {
	NSLog(@"init");
	[super awakeFromNib];
	CGColorSpaceRef displayColorSpace = CGColorSpaceCreateDeviceRGB();
	ciContext = [[CIContext contextWithCGLContext:[[self openGLContext]
CGLContextObj]
									  pixelFormat:[[self pixelFormat] CGLPixelFormatObj]
										  options:[NSDictionary dictionaryWithObjectsAndKeys:
												   displayColorSpace, kCIContextOutputColorSpace,
												   displayColorSpace, kCIContextWorkingColorSpace, nil] ] retain];
	CGColorSpaceRelease(displayColorSpace);
}

-(void)drawRect:(NSRect)dirtyRect {
	NSLog(@"-drawRect");
	[[self openGLContext] makeCurrentContext];
	glClearColor(0,0,0,0);
	glClear(GL_COLOR_BUFFER_BIT);

	CIImage *ciImage = [CIImage imageWithContentsOfURL:[NSURL
fileURLWithPath:@"/Users/testuser/Downloads/x_80722192.jpg"]];
	if(!ciImage)
		NSLog(@"ciImage loading error");
	NSRect viewFrame = [self frame];
	CGRect imageFrame = [ciImage extent];

	[ciContext drawImage:ciImage
				 inRect:CGRectMake(10, 10, 100, 100)
	// inRect:CGRectMake(0, 0, viewFrame.size.width, viewFrame.size.height)
				// atPoint:CGPointMake((int)((viewFrame.size.width -
imageFrame.size.width)*0.5), (int)((viewFrame.size.height -
imageFrame.size.height)*0.5))
				fromRect:/*imageFrame*/CGRectMake(10, 10, 100, 100)];
	glBegin(GL_LINES);
	glVertex2f(-0.5,-0.5);
	glVertex2f(0.5,0.5);
	glEnd();
	glFlush();
}

-(void)dealloc {
	[ciContext release];
}
@end
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: what kind of pictures am i allowed to draw onto NSOpenGLView?
      • From: Kyle Sluder <email@hidden>
  • Next by Date: Re: what kind of pictures am i allowed to draw onto NSOpenGLView?
  • Next by thread: Re: what kind of pictures am i allowed to draw onto NSOpenGLView?
  • Index(es):
    • Date
    • Thread