• 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
How do I draw to fullscreen on a secondary monitor?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How do I draw to fullscreen on a secondary monitor?


  • Subject: How do I draw to fullscreen on a secondary monitor?
  • From: Karan Lyons <email@hidden>
  • Date: Tue, 12 Jun 2007 16:35:25 -0400

Hi all,
I really don't know much about coding applications for Mac OSX, so I sincerely apologize if this is a stupid question, but I've been trying to figure this out for a week and have no idea how to do it.
What I'm trying to do is run a quartz composition in fullscreen on an attached secondary monitor. I've gotten as far as running the quartz composition in fullscreen on my primary monitor (I just modified the Player example in the examples folder). However, I have no idea how to find and then capture the secondary display. I know it's possible, I just don't understand enough to figure it out. I think that it has something to do with using CGGetOnlineDisplayList
and then finding the second display, but that's all I know.
I've attached my code below. If anyone could help me out it would be greatly appreciated. Thank you so much for your time!


Namaste,
Karan Lyons


CODE FOLLOWS BELOW:

#import <Cocoa/Cocoa.h>
#import <Quartz/Quartz.h>

#define kRendererEventMask (NSLeftMouseDownMask | NSLeftMouseDraggedMask | NSLeftMouseUpMask | NSRightMouseDownMask | NSRightMouseDraggedMask | NSRightMouseUpMask | NSOtherMouseDownMask | NSOtherMouseUpMask | NSOtherMouseDraggedMask | NSKeyDownMask | NSKeyUpMask | NSFlagsChangedMask | NSScrollWheelMask | NSTabletPointMask | NSTabletProximityMask)
#define kRendererFPS 100.0


@interface AssemblyPreshow : NSApplication
{
	NSOpenGLContext*			_openGLContext;
	QCRenderer*					_renderer;
	NSTimer*					_renderTimer;
	NSTimeInterval				_startTime;
	NSSize						_screenSize;
}
@end

@implementation AssemblyPreshow
NSString * const qtzFile = @"../../AssemblyPreshow.qtz";

- (id) init
{
	//We need to be our own delegate
	if(self = [super init])
	[self setDelegate:self];

	return self;
}

- (void) applicationDidFinishLaunching:(NSNotification*)aNotification
{
long value = 1;
NSOpenGLPixelFormatAttribute attributes[] = {
NSOpenGLPFAFullScreen,
NSOpenGLPFAScreenMask, CGDisplayIDToOpenGLDisplayMask (kCGDirectMainDisplay),
NSOpenGLPFANoRecovery,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAAccelerated,
NSOpenGLPFADepthSize, 24,
(NSOpenGLPixelFormatAttribute) 0
};
NSOpenGLPixelFormat* format = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] autorelease];

//Capture the main screen and cache its dimensions
CGDisplayCapture(kCGDirectMainDisplay);
CGDisplayHideCursor(kCGDirectMainDisplay);
_screenSize.width = CGDisplayPixelsWide(kCGDirectMainDisplay);
_screenSize.height = CGDisplayPixelsHigh(kCGDirectMainDisplay);

//Create the fullscreen OpenGL context on the main screen (double- buffered with color and depth buffers)
_openGLContext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:nil];
if(_openGLContext == nil) {
NSLog(@"Cannot create OpenGL context");
[NSApp terminate:nil];
}
[_openGLContext setFullScreen];
[_openGLContext setValues:&value forParameter:kCGLCPSwapInterval];

//Create the QuartzComposer Renderer with that OpenGL context and the specified composition file
_renderer = [[QCRenderer alloc] initWithOpenGLContext:_openGLContext pixelFormat:format file:qtzFile];
if(_renderer == nil) {
NSLog(@"Cannot create QCRenderer");
[NSApp terminate:nil];
}

//Create a timer which will regularly call our rendering method
_renderTimer = [[NSTimer scheduledTimerWithTimeInterval:(1.0 / (NSTimeInterval)kRendererFPS) target:self selector:@selector (_render:) userInfo:nil repeats:YES] retain];
if(_renderTimer == nil) {
NSLog(@"Cannot create NSTimer");
[NSApp terminate:nil];
}
}


- (void) renderWithEvent:(NSEvent*)event
{
NSTimeInterval time = [NSDate timeIntervalSinceReferenceDate];
NSPoint mouseLocation;
NSMutableDictionary* arguments;

//Let's compute our local time
if(_startTime == 0) {
_startTime = time;
time = 0;
}
else
time -= _startTime;

//We setup the arguments to pass to the composition (normalized mouse coordinates and an optional event)
mouseLocation = [NSEvent mouseLocation];
mouseLocation.x /= _screenSize.width;
mouseLocation.y /= _screenSize.height;
arguments = [NSMutableDictionary dictionaryWithObject:[NSValue valueWithPoint:mouseLocation] forKey:QCRendererMouseLocationKey];
if(event)
[arguments setObject:event forKey:QCRendererEventKey];

//Render a frame
if(![_renderer renderAtTime:time arguments:arguments])
NSLog(@"Rendering failed at time %.3fs", time);

//Flush the OpenGL context to display the frame on screen
[_openGLContext flushBuffer];
}


- (void) _render:(NSTimer*)timer
{
	//Simply call our rendering method, passing no event to the composition
	[self renderWithEvent:nil];
}

- (void) sendEvent:(NSEvent*)event
{
//If the user pressed the [Esc] key, we need to exit
if(([event type] == NSKeyDown) && ([event keyCode] == 0x35))
[NSApp terminate:nil];

//If the renderer is active and we have a meaningful event, render immediately passing that event to the composition
if(_renderer && (NSEventMaskFromType([event type]) & kRendererEventMask))
[self renderWithEvent:event];
else
[super sendEvent:event];
}


- (void) applicationWillTerminate:(NSNotification*)aNotification
{
	//Stop the timer
	[_renderTimer invalidate];
	[_renderTimer release];

	//Destroy the renderer
	[_renderer release];

	//Destroy the OpenGL context
	[_openGLContext clearDrawable];
	[_openGLContext release];

	//Release main screen
	if(CGDisplayIsCaptured(kCGDirectMainDisplay)) {
		CGDisplayShowCursor(kCGDirectMainDisplay);
		CGDisplayRelease(kCGDirectMainDisplay);
	}

	//Release path
	[qtzFile release];
}

@end

int main(int argc, const char *argv[])
{
    return NSApplicationMain(argc, argv);
}

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: How do I draw to fullscreen on a secondary monitor?
      • From: arri <email@hidden>
  • Prev by Date: Re: how NOT to drag metal window by nsview
  • Next by Date: Re: How do I draw to fullscreen on a secondary monitor?
  • Previous by thread: Re: how NOT to drag metal window by nsview
  • Next by thread: Re: How do I draw to fullscreen on a secondary monitor?
  • Index(es):
    • Date
    • Thread