Creating a window and accessing OpenGl using C++

Nibbie
Posts: 3
Joined: 2009.11
Post: #1
Hi guys,

I realise I'm new - I'm pretty sure I'm going about this all the wrong way and I'm willing to change things, please be patient.

I've been working on a 3D engine for a while (a few years now) and have all manner of things working, camera, file access, model loading, scenes etc.

This whole time I've been working with OpenGL and.. <gasp> GLUT.

Man, I hate GLUT it's ruining my engine because of it's terrible access (/end rant) - so now I've started work on making a cross-platform windowing kit for my engine. All it needs to do is create a window and an OpenGl context and provide access to said context in some manner.

I bought Hillegass' 'Cocoa Programming for Mac OS X' to get a better idea of how to go about it and worked through a few tutorials to get a basic understanding of how Cocoa works - it's quite nice isn't it!

How can I create a window, that uses interface builder, and creates an OpenGL context and provide access to these things to my C++ code.

Please bear in mind that I do use a main() function and I definately want my application to be primarily C++, it needs to remain portable.

Any help, advice, reading material or code snippets are very much welcome!

I'm looking to hang around here - so for general game development aid I might be of use too! Thanks for reading.
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #2
Hi RagingAvatar, welcome to iDevGames! Smile

I think you'd find a lot of your windowing issues could more easily be solved in a cross-platform way by using SDL. It's sort of like GLUT in that it's cross-platform, but it has industrial support for input and other things which GLUT wasn't designed to do. In fact, on the Mac, SDL is Cocoa based. They've already worked out all the details.

So if I were you, I'd give SDL a try first.
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2009.11
Post: #3
AnotherJake Wrote:Hi RagingAvatar, welcome to iDevGames! Smile

I think you'd find a lot of your windowing issues could more easily be solved in a cross-platform way by using SDL. It's sort of like GLUT in that it's cross-platform, but it has industrial support for input and other things which GLUT wasn't designed to do. In fact, on the Mac, SDL is Cocoa based. They've already worked out all the details.

So if I were you, I'd give SDL a try first.

Thanks for the suggestion but I'm trying to avoid using external libraries like SDL.

My issue is that I will be looking to take to other platforms later that SDL won't run on - portability is a major issue for me and I want to keep external code to a minimum. Adding SDL just for the Mac seems a little crazy when all I want for the moment is to open a window and create a GL instance! lol

Thanks for the suggestion though.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #4
SDL is more portable than you might think. If you're set on rolling your own systems, though, there are good ways to abstract the window system glue from your platform-independent code. The way I do this is by defining a simple C API for the wrapper code for the few "system" calls the platform-independent code needs to make, have my main entry point in the wrapper, and call into the main code after doing some simple bootstrapping. That way, most of your code doesn't need to know anything about the platform you're running on until link time.
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #5
RagingAvatar Wrote:Thanks for the suggestion but I'm trying to avoid using external libraries like SDL.

Okay, well, I'm just going to warn you up front that this is a lot harder to do *properly* than you might think.

Here's a recent thread where we discussed using Display Link: http://www.idevgames.com/forum/showthrea...291&page=2

In particular, you might check out my post on other details you might need to deal with, *just to implement full screen properly* : http://www.idevgames.com/forum/showpost....stcount=35

To use the standard NSTimer route, which is a little easier (because you can avoid threading issues), but not as smooth, you can look at this other version of Pong that I whipped together real quick for hairball: http://www.idevgames.com/forum/showpost....ostcount=5

There are loads of other little details to consider. I will tell you that one of the toughest details to deal with on the Mac is going to be joystick support. You'll need to use an external library, of which none are fully bug-proof/up-to-date, or you'll have to pound it together using the HID manager if you dare.

Honestly, I'd still recommend SDL. Wink
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
GLFW recently got a Cocoa port which you could use as a basis:

http://glfw.svn.sourceforge.net/viewvc/g...lib/cocoa/
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Accessing c++ class from Obj-C .h file dsedov 3 3,888 Jul 1, 2009 11:07 PM
Last Post: dsedov
  Accessing iTunes DB through Applescript? blobbo 2 3,440 Dec 30, 2005 06:51 AM
Last Post: blobbo