Starting with Cocoa/OpenGL

BlueTide
Unregistered
 
Post: #1
Hi,

I'm just starting to dig into Mac programming, I've done C++ and other languages earlier quite some. Not that I am an expert of any kind, but survive on my own none the less.

Now, I would wish to start developing an application on Mac. I did a few quick ones earlier, with Objective-C and InterfaceBuilder, but this time I would wish to ditch the InteraceBuilder all together.

I did a program like this already, basicly just forming an empty screen, but that involved touching InterfaceBuilder. Is there away of doing such thing with Cocoa straight from the code (and how)? Or have I misunderstood something badly?

All I would want is a really simple template, a single .m file that opens an empty OpenGL fullscreen window.

EDIT: A bit of re-pharisng. Of course, I could save myself a lot by using C++ here. Also, I could just mix Objective C into the code. But I would wish to have services from QuickTime or such when needed as well.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
You could do it without Interface Builder, but why on earth would you want to? Interface Builder is there to make your life easier. Not using it makes your life harder. I don't see the point.

In any case, all the information you need is in the documentation / Xcode help. In particular, if you wish to pursue this random and foolish path, you'll want to read the NSApplication, NSWindow, NSView, NSOpenGLView and NSOpenGLPixelFormat documentation.
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #3
Honestly, Interface Builder is like candy without the side effects: it's just darn good. (And it improves your health.)

Going the IB route will enable you to do Mac applications that look and behave as they should, plus you get Apple's cool new inventions for free later.
Quote this message in a reply
Member
Posts: 201
Joined: 2002.06
Post: #4
Interface Builder is not some proprietary hack to get the job done, and it's not like these scripting engines that some people use. It practically works the same as if you had done it in code. There is no reason to dump it.
Quote this message in a reply
Sage
Posts: 1,234
Joined: 2002.10
Post: #5
Now, I'll counter what they've all said-- if all you want is to make a fullscreen GL window, there is absolutely no need to use IB. Create your GL context with an accelerated fullscreen pixel format, capture the display, and set the context fullscreen. No need to use any windows or views.

There is a bit more you should do to make the fullscreen app behave correctly, like hide the menu bar, sync to VBL, and handle events. This source contains the relevant code (and no window in the nib.)

Now, if you want to toggle between fullscreen and windowed mode then you have more work to do. And if you want any Cocoa UI in your window, you're better off just using IB, like they said.
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #6
arekkusu: sweet game Smile
Quote this message in a reply
BlueTide
Unregistered
 
Post: #7
arekkusu Wrote:Now, I'll counter what they've all said-- if all you want is to make a fullscreen GL window, there is absolutely no need to use IB. Create your GL context with an accelerated fullscreen pixel format, capture the display, and set the context fullscreen. No need to use any windows or views.

There is a bit more you should do to make the fullscreen app behave correctly, like hide the menu bar, sync to VBL, and handle events.

This was actually the most and so far only usefull answer, thank you very much for this. Indeed, I am only looking into making a fullscreen window like you said. I have no intentions to use controls that Apple provides. I am not hoping to have Apples menus of any kind, even if I might live with those.

For general information. Much of this is not exactly practical either, I understand that very well. It is to start somewhere that I partly know already, and incorporate Objective C gradually and gracefully without too much fuzz.

OneSadCookie Wrote:You could do it without Interface Builder, but why on earth would you want to? Interface Builder is there to make your life easier. Not using it makes your life harder. I don't see the point.

While I do not try to deny the usefullness of IB, at the beginning it seems to do more harm than it is worth. With the really, really basics yet not only the command line tools. In a way it is an obfuscation layer that has zillion menus and it hides you what happens and what code it creates. At the time being, one thing I am looking for is to be in total control what happens within the program so that I can see it (the code) clearly.

I'm very sure you could see what IB does as well, but it is not that evident where to find it. ->

geezusfreeek Wrote:Interface Builder is not some proprietary hack to get the job done, and it's not like these scripting engines that some people use. It practically works the same as if you had done it in code. There is no reason to dump it.

Actually, there can be a few reasons... ->

Fenris Wrote:Honestly, Interface Builder is like candy without the side effects: it's just darn good. (And it improves your health.)

Going the IB route will enable you to do Mac applications that look and behave as they should, plus you get Apple's cool new inventions for free later.

What I do, or planning to do when it comes to Mac, is dealing with experimental user-interfaces. So far, I've been doing this on either Windows and Linux, mainly just slapping in an OpenGL view and override next to everything the OS has to offer visually.

With Mac I am interested in services it might offer as well. Not GUI, mind you, but pipes to get data in and out in a form or another. Interface Builder as such does very little if anything usefull for this purpose. QuickTime component might do a lot.

Now, it might be that I need IB to use some of these services which would be a bummer. Not a show-stopper though. It might also be that I can access all this good stuff from C++ environment as well, but at the time being I would not mind having to dive into a bit Objective C, for the sake of my own education.
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #8
Ah, I see what you're doing now. Granted, going the non-IB route would make sense, if it weren't for one little detail: in fullscreen, you can't use the debugger (unless you have two monitors or can do remote gdb sessions). To me, that's the final showstopper, but each to their own. Smile
Quote this message in a reply
Sage
Posts: 1,234
Joined: 2002.10
Post: #9
You can still make a regular NSWindow without IB, and toggle between it and fullscreen.
Quote this message in a reply
nabobnick
Unregistered
 
Post: #10
You in luck, I've been tinkering with just that the past couple of days. I'm more of a hobby programmer not trying to finish anything worth while, but in my current project I have an application that does not use a NIB file at all. I haven't moved to opening windows/screens yet as I've done that in the past. I'm just concentrating on not having a NIB file, setting up the most basic menu possible (only one item and that's quit), and processing input in a elegant manner.

If you like I can post the source of what I have so far. I think it's something that Apple should give instructions on. Even though technically IB does this for you I think it's like Assembly language. You really don't need it because there is C and other high level languages but I think if you know it, it makes you a better programmer.

Both Apple and SDL use this low level approach to Cocoa (only way I know this is because that's how I learned). Apple uses it in their GLUT library and SDL uses it to make a more cross platform game programming system. I think it's a valid approach for people that need/want that knowledge and control.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Texture Loading Cocoa/OpenGL ultitech 1 7,188 Jan 31, 2011 12:51 PM
Last Post: mk12
  Cocoa/OpenGL drawing full-screen problem ultitech 5 8,584 Jan 13, 2011 01:11 PM
Last Post: SethWillits
  Cocoa OpenGL clapton541 3 5,062 Aug 5, 2007 09:22 PM
Last Post: BenRose3d
  setting up opengl w/cocoa Leroy 5 4,716 Jun 18, 2007 06:00 PM
Last Post: kelvin
  Cocoa OpenGL clapton541 3 4,647 Mar 26, 2007 03:55 AM
Last Post: MattDiamond