ofAppCocoaWindow - everything but fullscreen

Here is a project for 006 that uses a cocoa window created with interface builder:

http://www.openframeworks.cc/files/004–…-estApp.zip

I based the code mainly off of the basicOpenGLView example - http://developer.apple.com/SampleCode/C-…-ting3.html - which uses NSOpenGLView

There is one small mod to freeimage.h to make which is described by a forced error in main.cpp.

Fullscreen is a lot harder than it sounds as the window cannot be made to go fullscreen.
But I am looking into alternatives.

Oh and it also has fullscreen anti aliasing.

Theo

Hi theo,

have you tried the new fullscreen support for Leopard?

  
  
- (IBAction) toggleFullScreen:(id)the_sender	  
{  
	    // I'm lazy and rather use the new 10.5 Cocoa Fullscreen API.  
	    // For now, no legacy support for fullscreen.  
	    // One of the cool things about Obj-C is dynamic/late binding.  
	    // We can compile and run this code on versions prior to 10.5.  
	    // At run-time, we check to see if these methods actually exist  
	    // and if they do, we message them. If not, we avoid them.  
	    if([self respondsToSelector:@selector(isInFullScreenMode)])  
	    {  
	        if([self isInFullScreenMode])  
	        {  
	            [self exitFullScreenModeWithOptions:nil];  
	        }  
	        else  
	        {  
	            [self enterFullScreenMode:[NSScreen mainScreen] withOptions:nil];  
	        }  
	    }  
}  
  

self is an openglview or nsview. This works only for leopard, but better than nothing :wink:

(Code taken from the osgCocoaViewer example of the OpenSceneGraph-distribution, LGPL)

cheers,
Stephan

This is nice! And very much in the same direction as i try with QT framework http://forum.openframeworks.cc/t/qt-gui-interface/2164/0

This is nice! Does anybody know, how to add interface elements to this? When adding one in InterfaceBuilder it doesn’t show up in the compiled app. Also added menu items show up as if they were disabled!

Regards,
Gestalt

omg - that works! amazing.
damn - I spent all afternoon trying to hack too OpenGL contexts into NSOpenGLView.

Okay, so thats easy.
I will add it in and reupdate.

I have feeling though that in terms of graphics speed a non window fullscreen opengl context that captures the display might be faster.

but that can be something to try later
love quick fixes!

Theo

Okay so that was fairly easy to implement.

Attached is the new example with fullscreen (keys ‘f’ and ‘w’).

Note that when the window goes from fullscreen to window it loses focuses to key events so you have to click inside it to give it focus again - I am working on a fix for that. Also key up is currently not implemented.

I also increased the FSAA from 2 to 8 samples :slight_smile:
Looks a lot nicer.

005-ofAppCocoaWindowExample.zip

[quote author=“Gestalt”]This is nice! Does anybody know, how to add interface elements to this? When adding one in InterfaceBuilder it doesn’t show up in the compiled app. Also added menu items show up as if they were disabled!

Regards,
Gestalt[/quote]

Try hacking the Info and Animate menu items first. The callbacks are still in the BasicOpenGLView.m

Also when you make a menu item in IB you need to connect it to the BasicOpenGLView. You also need to give it a callback function name that BasicOpenGLView implements.

I have to say I know close to 0 about IB and Cocoa - so a lot of this has been guesswork for me :slight_smile:

Theo

nice theo,

have you tried to implement the cocoa screensaver API yet?

thank you!

as we speak :slight_smile:

kool work 8)

hi theo,

this is great!
i ran your example… although it’s only rendering what’s coming out of ofDrawBitmapString and only on one line, nothing else.

full screen and window modes are working correctly.

im running,

Mac OS X 10.5.7
MacBook Pro
Intel Core 2 Duo
2.4 GHz

Huh - that is very strange.

What if you comment out this line from main.cpp ?

  
//window.setUseFSAA(true);  

Can you post a screengrab?
Which version of xcode are you using?

I have similar specs:
Mac OS X 10.5.6
MacBook Pro
Intel Core 2 Duo
2.2 GHz
Nividia 8600m gt

btw I am using 0.06 and latest OF from svn.
But I don’t think that would be an issue.

Did you modify the example in anyway before running it?

Theo

its all good now.
just had to clean the project in XCode and it started working.
sorry about the false alarm.

This is great. This is exactly what I registered for the OpenFrameworks forum to ask about - feasibility of connecting to OF directly into CGLContexts or NSOpenGLContexts, which will allow integration with other core OS X technologies like Quartz Composer, etc.

Im working on what will be an open source VJ app, and want to be able to write sources and effects in OF.

Is this a project that will allow 3rd party code to be submitted to? Id love to help out.

Looking at this briefly (and admitedly being new to OF), I notice the the ofAppCocoaWindow class. Is it possible to have OF bind to an already pre-existing context?

Essentially what I would like to be able to do is render OF content to an FBO and output a texture within my app, so I dont need OF to house its own window, but I do need it to share a context with my main rendering destination. Does this sound feasible?

Thanks. Looks very exciting :slight_smile:

I think it would be easy - check out the screen saver topic too as its another example of OF in Cocoa but with a window defined outside of our code.

The main thing is that you create an opengl view which is either a view from an Interface Builder project ( cocoa window example ) or a sub view of a an existing view (see the screen saver example).

All of the ofApp*** windows are just essentially hacks between the cocoa world and the OF world. In the screensaver example the OF testApp is actually being created in the screenSaverView.m - in the ofAppCocoaWindow example we are doing it in main.cpp

Anyway the main point is - it can work :smiley:
Just have to figure out the best way for your configuration.

Theo

welcome to OF anton! :stuck_out_tongue:

what you wanna do is totally possible, though may be a bit tricky with some of the OF dependencies (poco, fmod etc.).

What you’ll have to do is replace ofAppCocoaWindow and write your own version of that class that creates (or receives) the context in the way you want it. I.e. in the normal distribution of OF there is the ofAppGlutWindow class which creates the opengl context using glut and sets up all the event callbacks (setup, update, draw, mouse + kbd events etc). For iphone that class is replaced by ofAppiPhoneWindow which uses NSOpenGLView and sets up an NSTimer to call the update/draw callbacks, and similar for native mac opengl ofAppCocoaWindow. The bottom line is you need to create a class that extends ofAppBaseWindow that has the necessary hooks between the host and your application (which extends ofBaseApp).

bring on ofAppQCWindow! \m/

[quote author=“memo”]welcome to OF anton! :frowning:

Theo; thanks for the pointer, but I feel stupid - I cant find that screen saver example. Is it included elsewhere?

Thanks, look forward to get this working.

Also, is there an IRC channel for those looking to chat about OF? I have some newbish questions that might be better served asking on IRC :slight_smile: Thanks again for the help!

Hey - its this post: http://forum.openframeworks.cc/t/screen-saver/1709/9
and the one below it.

Regarding proper Frameworks - it could be possible ( though fmod might make it tricky on mac ) - there just hasn’t been a big need for it as of yet. Anyway it is probably a discussion that is best for another thread :slight_smile:

Theo