How to start Xcode4 opengl project for mac - opengl

Good Day
I want to start a opengl project, mainly to follow the Nehe tutorials.
My problem is that I only see templates for opengl es for iphone, and when I click build on those, I only have the choice between iphone or ipad simulator.
So How can I get started with a simple opengl template to follow the tutorial series, without using a simulator, but executing it natively on my mac osx lion?
Please give me a step by step instruction if possible :)
I looked around everywhere but all I found were instructions for Xcode 3 and below etc.
Any help would be appreciated

Create a normal Cocoa project, add the OpenGL framework. In your main window add a NSOpenGLView.
http://developer.apple.com/devcenter/mac/resources/opengl/

I am currently in the process of writing an intuitive Xcode 4 Template for an OpenGL Mac application, which I think is exactly what you were wanting.
In the mean time, you can look at this, a Pong clone I made in OpenGL on the Mac, done the proper way.
EDIT: The template isn't completely finished, but it's definately usable. I didn't implemenet the 3D option, so picking that in the dropdown will result in blank files.
Donwload it from here and then move it into the ~/Library/Developer/Xcode/Templates/Project Templates/Applications folder in your user director.

Related

Displaying a SDL window in Qt

Looking around at some SDL games and emulators I notice that each time there's an android version of it, same base code is used as the desktop versions.
For example in an atari 7800 emulator I've found on github, I don't really understand java and I'm trying to see how it's done there. I suppose that based on the line 991 it captures the display from the sdl2 process maybe by running it headless and rendering the sdlwindow in android?
No idea, trying to understand the code but I'm like looking at it like a cat looking at a calendar (a saying in my country).
What I'm trying to do is to somehow archive the same thing in QT5 since the platform I'm using uses it for the interface and anything app related to communicate with their APIs.

How to make a window using C++ on mac

I am looking for a way to use C++ to make a window using Xcode. the reason being I have looked for ways to do this, but they all seem to be using visual basic, and seeing as I have a mac, i can not run this. If it just to difficult to make a window on Xcode, is there another program I can use, because I am hoping to later turn this into a user interface for a program...
~Regards
Mark Calhoun
Well, you may want to look into a framework that Herb Sutter actually mentioned at Going Native, back in 2012: http://www.openframeworks.cc
I've actually experimented with this framework in Xcode 5 and it works as advertised
You should probably start with Apple's "Start Developing Mac Apps Today" tutorial. In particular the Your First Mac App page shows how to create a simple app with a window and some controls, and how to set that up in Xcode.

How can I 'break away' from Cocoa and develop Mac OpenGL applications in C/C++?

I am looking to get started with some 3D programming in C or C++. The problem I have is that it seems like the only tutorials I can find for Mac OS use objective C and Cocoa frameworks. I want to obtain the same environment as Windows users, more or less.
If I try to use a text editor and g++ compiler, I am missing headers, but, if I try to use Xcode, I am forced to grapple with Cocoa, which is frustrating to me. I don't really see any reason why the OpenGL/GLUT that comes pre-installed on Mac should force me to use Xcode, but it seems I can't get the header files without it.
How can I get through all of the Apple 'developer friendly' interfaces to write some old-fashioned code with full cross-platform portability?
Some portion of Objective-C is inevitable if you want to use the latest benefits of the OSX/Cocoa. The easiest way to port an existing application to MacOS would be the following:
Write the "bare bones" nibless application in Objective-C. It would only be a single AppDelegate class and a little setup in the main() function
Add the custom NSGLView descendant in your window which you create in the AppDelegate's didFinishLaunching event handler
Setup the CVDisplayLink and rendering callback in the NSGLView initialization
Use your existing OpenGL rendering code in the CVDisplayLink's callback
Now for the interesting part: where to get all of this ?
Surprisingly, a good nibless application sample is the UI for OSX's port of QEMU (yes, the emulator). Also the Apple's official GLEssenstialPractices demo shows all the information you need to set up OpenGL rendering pipeline. All the rest is up to you.
The detailed and modern introduction to system-level OSX programming can be found in the "Advanced Mac OS X Programming" book by Mark Dalrymple. It explains many things and after reading all of this I've understood most of the design decisions in the OS (it really makes you accept all the "non-standard" things if you think from the performance viewpoint).
To get through the "nibless" programming I would recommend you to read the blog posts like this one http://blog.kleymeyer.com/2008/05/creating-cocoa-applications-programatically-ie-nib-less/ The google search helps a lot.
The same tricks apply to the CocoaTouch/iOS and there are a lot of questions answered on SO, like this one Cocoa touch/Xcode - generating NIB-less graphics context
If you want to create cross-platform applications you could create a project with the Command Line Tool template.
Next, import the OpenGL and GLUT framework. This will get you a "blank" C++ project with the required OpenGL and GLUT headers.
Lighthouse 3D gives you some tips about portability and how to initiate your first project.
http://www.lighthouse3d.com/tutorials/glut-tutorial/initialization/
I have created a software layer (named cocoglut) that allows the translatation of basic or essential GLUT calls to COCOA. This library allows creating/destroying windows and register callbacks from a C/C++ application, just by using GLUT calls, without the need for nib files or for XCode project files (and can be compiled from the command line). This option uses full retina display resolution. The source is on GitHub.

Cocos2d-x vs cocos2d-android for an Android game

After using 'cocos2d-iphone' in one of my projects, I am trying to decide which flavor of Cocos2d I should use for an Android game. My personal list of pros and cons:
Cocos2d-x
pros: it should be easier to bring the game to iOS later, potentially other platforms as well
cons/doubts: debugging c++ code on Android (easy or not?), compatibility of NDK app with various Android devices (how much of a problem?), accessing platform-specific functionality (in-app purchases, etc.)
cocos2d-android
pros: all Java, easier to setup and access platform-specific functions
cons: will have to translate from Java to either c++ or Objective-C for other platforms
Are there other issues with either of the options that I didn't think about? If anybody had to make this choice, what did you choose and why?
Note that there are two projects with almost the same name: cocos2d-android and cocos2d-android*1*. The latter is a fork of the former and its author did it because cocos2d-android project was almost dead.
In the beginning I was in doubt about cocos2d-android1 (which seems to be a very good work) and cocos2d-x but the possibility to develop in C++ (that I like a lot) and be multi-platform made me chose cocos2d-x.
I'm still trying to learn cocos2d-x.
What I like about it:
List item
it's a C++ framework
you can develop for Android, iPhone, Bada, Blackblerry Playbook, Windows and Linux.
Please, notice that at the moment cocos2d-x team advises that Windows and Linux port are meant for easy your development not for production.
it has a Lua binding
it has a version for Marmalade (a paid multi-platform SDK)
cocos2d-x works with NDK since release 4. Currently I'm using NDK r7. You can develop for devices running since android 2.1 (API 7)
It seems that there are some issues with cocos2d-x on android 4 (what shouldn't be a problem because both it's still not that wide spread and cocos2d-x team will fix any problem they come across).
You will be able to access platform specific functionality like in-app purchase but it comes with a price: you will do almost everything using JNI.
Definitely it's harder than just putting a jar SDK into libs folder and directly call Java functions but it's feasible.
You can develop on Windows, Linux or Mac. For each OS you're using in the development machine the procedures to prepare your environment (cocos2d-x + target SDKs) varies. It's not a problem because you usually will stick with one of them.
Now let me tell you that it's not that easy to debug JNI / Java code. Why? Because there are many steps you must take to enable this and debugging process is slow.
So that cocos2d-x team advices to develop all your game for Linux or Windows and after that everything is up and running you compile it to Android. This way you will have minor problems to solve (if any)
I prefer to develop for android from the beginning.
All in all, I'm really happy coding with cocos2d-x. Community is very passionate about cocos2d-x and they are very supportive.
In the process of learning I wrote two tutorials:
Developing with cocos2d-x for android on Linux, that teaches how to prepare your environment to develop for android using cocos2d-x
How to debug cocos2d-x and Java code using Eclipse that explain in details all needed steps to perform debugging sessions.
Regards.
I had the same problem 2 month ago. Cocos2d-Android is dead, so use cocos2d-x. Here some links and tutorials to start using it.
If you are comfortable with C/C++ , by all means go the Cocos2d-x route.
HOWEVER, if you are coming from an Android and Java background, with no experience in C++ , it can be a really painful experience getting everything in order.
In asmuch as the Cocos2D for Android Project has been slow recently, I wont particularly say its dead. I used the version hosted on github here ..
https://github.com/ZhouWeikuan/cocos2d
There are several tutorial on getting started.
Step by Step Guide on How to build your first Slider Puzzle game in Cocos2d for Android – Part 1 http://denvycom.com/blog/step-by-step-guide-on-how-to-build-your-first-slider-puzzle-game-in-cocos2d-for-android-part-1/
How To Make A Simple Android Game with Cocos2D http://dan.clarke.name/2011/04/how-to-make-a-simple-android-game-with-cocos2d/
For all others coming to this thread, I hope this is useful!
cocos2d-x (98% in C++ and some Android Java Code) is the only version of cocos2d useful for Android.
cocos2d Android (all Java) may be useful if you want to create some prototypes, but as an active open source development project it is long dead and not maintained.
If you want to write a Java game on Android, use AndEngine - it is active and well maintained.

Is there a simple way for opening one (or many) opengl window in mac OS X with C++?

Yes, I hate Objective-c, plus my project will be portable, so I'd like to code as much of it in C++ as possible, ideally 100%.
So I have a regular C++ project made with Xcode, and want to open some OpenGL windows.
edit: Damn, Glut takes over the app's control with glutMainLoop() and I'll like to have more control over the loop.
Will try freeglut, although I can't find OSX binaries, and I always have such bad luck trying to compile someone else's code.
Update:
I tried yet again to link to SDL 1.3 and this time I could get it to work! yoo-hoo!
I always wanted to work with SDL, but using more than one window was mandatory, and that's a feature of version 1.3 which is under development and I never could get it working.
As it is portable to a zillion OSes, and handles 2D graphics as well as OpenGL I'm going with it. Thanks to all!
If you don't want to use objective-c you're going to have to use either the deprecated carbon libraries, X11, or another library like GLUT to create the window. If portability is a concern either go the GLUT route, or you'll need to write your own window management code for each platform you want to support.
If you don't go the GLUT route you will need to write window management code fore each operating system so I strongly suggest you bite the bullet and write the window management in objective-c++. The only thing you really need to know is that a pointer is always a pointer no matter which language it is in, so just store objective-c ids as void* and cast them back to ids, it actually works out pretty easy.
i guess NeHe tutorials could help;
GLUT works fine for your stated purpose, although you will probably wish for a nice C++ wrapper for it. I ended up hacking my own, and although GLUT isn't friendly to wrapping, it was doable.
EDIT: Since you have a problem with glutMainLoop(), you may be trying to do more than GLUT was designed to do -- it is mainly intended for hacks, one-off projects and opengl demos. And freeglut doesn't compile OOB on the mac, at least that was my experience.
For a portable, fuller featured app, Qt may be the way to go for you. Otherwise, design your C++ for portability and use a thin GUI layer on each platform. If getting something running on each platform is most important, go for the former. If the best user experience on each platform is most important, go for the latter. You may find that "thin" is not the most descriptive term for what is involved.
I found this demo to be useful for getting a simple Cocoa/OpenGL window working, even though the code has a number of ridiculous bugs: http://developer.apple.com/library/mac/#samplecode/CocoaGL/Introduction/Intro.html
This question has been asked over 3 years ago, yet remain quite fresh. I just recently went through similar exercise for planning school curriculum, and trying to figure out what's the best portable library to work with on Mac/Windows/Linux/mobile with OpenGL projects. Perhaps my notes will help someone make a decision. I only mention the main options that I've considered.
Higher level APIs, for window management plus additional goodies, like sprites, fonts, sounds, event handling, etc:
SFML and github repo: nice&tidy, C++, object oriented library that integrates with OpenGL natively. Portability for managing windows and OpenGL 3.3 contexts out of the box on MacOS, Win and Linux. Mobile support provided in the 2.2 branch (github).
SDL2: all major platforms, including mobile, supported. The OpenGL context needs to be manually managed somewhat, so use of GLEW for example comes really handy (see below). A bit lower level than SFML.
Lower level APIs, mostly for window and OpenGL context management:
GLWF: This is pretty much a GLUT replacement for modern OpenGL. Rather low level, but portable across: Win, OSX, Lin. In active development.
GLEW: I only mention it for completness. It doesn't manage windows, but helps managing OpenGL contexts and you might use it together with GLWF or SDL for example.
Others:
Freeglut: Open source continuation of GLUT. Suitable for small demo projects. I have not used it myself, but seen good docs and demo code. In active development.
GLUT: old one, discontinued. Legacy demos and code around the net.