iDevGames Forums
Display capture questions - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Display capture questions (/thread-7071.html)



Display capture questions - Mark Levin - May 22, 2003 09:22 AM

I'm just starting on resolution switching, and I've run into a few issues...
  • Cocoa graphics coordinates are measured from the lower left of rectangles, while CG seems to use the upper left. Therefore, I'm having trouble converting mouse locations obtained from NSEvents to locations on captured displays (it doesn't help that using CG appears to render NSScreen useless). Is there a way to get the absolute mouse position without having to take into account every display attached to the system, or am I limited to CG's mouse delta function?
  • How do I stop resolution switching from resizing windows in background apps on that monitor? I capture the display during the entire time the monitor is in an altered state, but this still happens.



Display capture questions - w_reade - May 22, 2003 01:34 PM

I think you're stuck with mouse deltas, although you can do it by getting the deltaX and deltaY of NSMouseMoved events instead. That said, it would surprise me greatly if the one did anything more than wrap the other.

Um, I dunno. My windows etc. stay fine, even when I unexpectedly terminate without changing back or releasing the display. How are you going about it? You do switch back to the original settings before you quit, I presume... Wink


Display capture questions - kelvin - May 22, 2003 01:53 PM

1) When I set my app to draw fullscreen I define a frame to draw in. CoreGraphics will pick the best size resolution, and I clip to my frame. Here's the code I use to get the mouseLoc:
[sourcecode]- (NSPoint)mouseLocInFrame {
NSPoint mouseLoc = [NSEvent mouseLocation];
CGRect screenBounds = CGDisplayBounds(kCGDirectMainDisplay);
mouseLoc.y += screenBounds.size.height;
mouseLoc.y -= ([[NSScreen mainScreen] frame].size.height + 1);
mouseLoc.y -= frame.origin.y;
mouseLoc.x -= frame.origin.x;
if ( mouseLoc.x < 0 ) mouseLoc.x = 0;
if ( mouseLoc.x > [self frame].size.width-1 ) mouseLoc.x = [self frame].size.width-1;
if ( mouseLoc.y < 0 ) mouseLoc.y = 0;
if ( mouseLoc.y > [self frame].size.height-1 ) mouseLoc.y = [self frame].size.height-1;
return mouseLoc;
}[/sourcecode]

2)As long as you change the screen res only while the screen is captured, not before, not after, then your windows shouldn't move. Course you're gonna have to keep it captured the whole while.


Display capture questions - Mark Levin - May 22, 2003 06:58 PM

Code:
foo = CGGetActiveDisplayList(32, list, &count);
        foo = CGDisplayCapture(list[monitorChoice]);
        originalMode = CGDisplayCurrentMode(list[monitorChoice]);
        modes = CGDisplayAvailableModes(list[monitorChoice]);
        selectedMode = CFArrayGetValueAtIndex(modes, resChoice);
        CGDisplaySwitchToMode(list[monitorChoice], selectedMode);

monitorChoice and resChoice are, naturally, integers. They are generated earlier based on the active display list, and I'm sure that part is correct.

Then the game runs, and then:

Code:
bar = CGLClearDrawable(coreContext);
        bar = CGLDestroyContext(coreContext);
        foo = CGGetActiveDisplayList(32, list, &count);
        CGDisplaySwitchToMode(list[monitorChoice], originalMode);
        CGDisplayRelease(list[monitorChoice]);

Kelvin: I'm trying to stay general by not explicitly using the main display, just the one selected by the user. Guess I'll just use mouse deltas for that part.


Display capture questions - Fenris - Jan 24, 2006 12:23 PM

Gravedigging warning, but: thanks a lot, Kelvin.