简体   繁体   中英

Glut window - menu bar in MAC OSX

is there a way to remove the menu bar items in MAC OSX, when the window was created using glut (glutCreateWindow( "title" );)?

or are there any other alternatives to create (menuless) window for OpenGL in OSX using C/C++ and glut?

glut is creating menu bar items and even keyboard shortcuts on Mac OSX (just try Command+S and you'd be surprised...). There's no easy way to remove these things without accessing Cocoa. The GLUT source code from here shows where all that stuff is being implemented:

http://developer.apple.com/library/mac/#samplecode/glut/Introduction/Intro.html

In order to get rid of the Menus in GLUT, you have to do the following:

  1. #include "Cocoa/Cocoa.h" in your main.cpp file.
  2. right-click on your main.cpp file, select "Get Info", then in the "General" tab set your "File Type" to sourcecode.cpp.objcpp
  3. include the Cocoa framework in your xcode project
  4. add the following code after glutInit():

     if (NSApp){ NSMenu *menu; NSMenuItem *menuItem; [NSApp setMainMenu:[[NSMenu alloc] init]]; menu = [[NSMenu alloc] initWithTitle:@""]; [menu addItemWithTitle:@"About..." action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; menuItem = [[NSMenuItem alloc] initWithTitle:@"Apple" action:nil keyEquivalent:@""]; [menuItem setSubmenu:menu]; [[NSApp mainMenu] addItem:menuItem]; [NSApp setAppleMenu:menu]; }

The code is by Tom de Grunt from here: http://www.degrunt.net/2010/09/22/using-nsmenu-outside-the-nib/

This will set up your application with nothing but an "About..." button within a menu with your Apps name. Just deleting the menu will cause a crash as GLUT expects a menu and has registered a callback for that.

I have search up and down the web for an answer to this and hope that this will help others that ran into the same problem.

Glut has nothing to do with the menu bar. What you could do is to put the application into fullscreen with glutFullscreen() and then define several viewports in your Glut window to simulate your own windows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM