I would like to be able to go through a lesson on OpenGL so that I may learn to use OpenGL. This means that I need to be able to compile and run the programs myself, so that I may play around with them and begin making my own OpenGL projects. I can't do this if I can't install and include libraries that the lesson is using. So, I need either:
a lessons with instruction, for OSX, on how to install the libraries
that the lesson uses
a lesson that only teaches with the libraries that come with
OSX (GLUT and OpenGL).
From what I have seen around the web, it appears that GLEW is the most used library with these lessons so instruction on how to install that would be top priority. However, if there is another lesson that uses another library and you know how or have a link on how to set that library up for Mac, I would see that as a helpful answer.
Finally, overall, I would appreciate it if someone could tell me how they have their Mac set up with OpenGL, or point me to a tutorial that works with Macs.
Here are the tutorials I have been looking at:
http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Table-of-Contents.html
http://www.opengl-tutorial.org/
http://www.cprogramming.com/graphics-programming.html
I have been able to get the headers GLUT/GLUT.h and OpenGL/gl.h which I think are OpenGL's main header files so, alternatively, if there is a lesson out there that only relies on these two headers (or any headers in the GLUT.framework or the OpenGL.framework included with OS X Lion) that would work just fine for me.
To install most needed development libraries for os X, install fink and then use fink to install everything else:
Fink
Fink Glew page
As an added bonus here are some GLUT tutorials (although for an older version of Xcode).
I'm not sure this is what you need but i'll give you the basics for running an opengl/glut-based program using Xcode.
Create a new empty project, name it whatever you want
Under the project menu click "New Target"
On the left menu select "Cocoa", then click "Application", name it whatever you want
You should have a new window called "Target 'your-program's-name' info"
Under the tab "Build" scroll all the way down to "GCC_PREFIX_HEADER", double click the value (wich should be something like "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h", delete this line, click ok.
Close the info window
Right click your project's name, click Add > Existing frameworks > Select "OpenGL.framework", click add.
Again, right click your project's name, click Add > Existing frameworks > Select "GLUT.framework", click add.
Right click your project's name, click Add > New File > under the "C and C++" tab, select C++ file, click next, name it whatever you want. (make sure it's being added to your project and target), click finish.
You're now ready to build and run any c++ project using OpenGl.framework and GLUT.framework
-You can use command + enter for building and running and command + shift + enter for closing an active window.
-When you require input from the user you should run it from terminal, compile like this:
"gcc -o func2d func2d.c -framework carbon -framework OpenGL -framework GLUT"
where func2d is the name of your application executable and func2d.c is the c file used
The imports required in case you don't have them are:
OpenGL/gl.h
OpenGL/glu.h
GLUT/glut.h
stdlib.h
Related
I am building a C++ OpenGL card game in Xcode 4.3.3, with the intention of running it on both 64-bit and 32-bit Macs, which is not my problem. My problem is that I have reached a point in the development of the program where I would like to test that it works on a different 32-bit Mac (mine is 64-bit) without having to install Xcode. This, obviously, requires me exporting it as an .app. I can find and run the exported Unix Executable File from my project, after some cd'ing, through Terminal, but that is undesirable for me and the intended audience of the program. I have trawled the google and Stack Overflow, looking for anything to help me, but all the things mentioning Archiving seem to have been unsuccessful with my particular project, and I think that's because it's a C++ command line tool project. So, can someone please help me export my project as a .app?
Thanks in advance.
The simplest way of doing this would be to create a Cocoa project, go to 'build phases' and remove all the objective-c frameworks from the 'link with libraries' build phase, remove any objective-c files added by the template (app delegate, etc.) and then replace main.c with your main.cpp file.
There's nothing really special about a Cocoa project except for the fact that it links against Cocoa and calls NSApplicationMain() from its main() function.
There are also a bunch of .plist entries used by Cocoa which you'll no longer need. But they won't affect the way OS X treats your application.
I'm searching for an XCode Settings solution but here's my current way to create an app:
You have to take your binary file (let say myapp) and put it in "MyApp.app/Contents/MacOS/myapp" then it can now be launched as a .app. That's a trick.
Just go to the targets folder in the file navigator on the left, and there will be an executable listed there. Left click on that executable and click "show in finder". (I'm describing from memory so I may have the exact details wrong.) The file path is ridiculously long (there is an arbitrary alphanumerical pathname involved, I have no idea why), so you probably won't be able to find it with the command line.
If you want you can change the extension of the file from nothing to ".app", it shouldn't affect the nature of the file at all. Also if you want a custom icon, you can "get info" on it in the finder, then click on the icon in the info window, and use Cmd-V to paste it in (obviously you have to have your icon copied to the clipboard). There is also a way to do this inside of Xcode, but I don't remember it.
I'm trying to set up SDL with Xcode using the tutorial here.
http://www.sdltutorials.com/sdl-tutorial-basics
I have everything set up correctly according to this tutorial, and there are no errors after building. The only problem is that when I run the program, the SDL_Surface never appears. The console says nothing and no errors are thrown. I've been searching for solutions for says, but I am unable to find anything that relates to my issue. I put my code up here on Git if anyone would like to check it out and tell me what I'm doing wrong. Thanks so much!
https://github.com/syobonaction/rubicon.git
This is a silly but easy mistake to make!
In your project, you have included main.m (included in a default cocoa application project) and have not included SDLMain.m, so your SDL code is never executing, and instead you are just running a blank Cocoa application!
To fix this, click on SDLMain.m, open the utilities pane on the right, and click the checkbox to add SDLMain.m to your target. Next, go to Supporting Files in your left navigation pane, find main.m, and delete it from your project. You don't need main.m at all, because all it does is start a Cocoa application, which you don't want to do! (SDLMain.m will also start a cocoa application, but not before linking the cocoa application to the SDL system.)
I'm very new to OS X and XCode, so please don't assume I know all terminology.
I've been developing my game in Linux for a year. Now I'm moving to OS X with XCode. I saw that in OS X, all the applications, even games, are only one package (ending with a hidden .app extension if I'm correct). And I want to use that system as well: one single user-friendly .app package, which can be started by double clicking on it.
Question 1: Is a .app package one single file or is it only a folder?
I started a new project in XCode using the Command line application option in the wizard. Is this the correct choice? Or should I've chosen something else to make a .app application? I've chosen that one because of I'm using SDL, which makes the window automatically.
Now, I finally managed it to make my whole game compile in XCode (using SDL, OpenGL, Box2D), by linking a lot of libraries (SDL.framework, SDL_image.framework, libBox2D.dylib, Cocoa.framework, OpenGL.framework).
I want to add resources for my game in the .app package as well and of course being able to read them.
Question 2: How to work with .app packages in XCode includes resources for my game?
Thanks in advance.
Hopefully, someone can help me out quickly because, tomorrow, I'm going on holiday without internet access.
Question 1:
It is a directory. You can examine the contents of a .app bundle via the command line or by using "Show Package Contents" in Finder.
Question 1.5:
You did not want to pick "Command Line Application." You most likely wanted to pick "Cocoa Application" or maybe "Carbon Application." You can read more about the two frameworks at Apple's dev site: http://developer.apple.com
Question 2:
The easiest way is to add your resource files to your Xcode project. There are other ways, but most people don't have to worry about that. In order to read the resource files out of the application bundle, you have to use the NSBundle Objective-C class.
Not asked:
If you use Cocoa, you will have to use Objective-C. Even if you don't, you should learn it anyway if you are going to be writing code for OS X.
I'm using Xcode 4 for my C++ programming. I want to add a framework, specifically an OpenGL framework, and I'm not quite used to where things are yet. It says in the help documentation that I should select the target, and from there I get the summery pane where I can add a linked framework/library. When I do that, the summery pane doesn't show up. It does show up when my target is a cocoa application, but since I'm programming in C++, I choose the command line tool, and select the language from there. So, how exactly do I add the OpenGL framework to my target?
maybe go under "build phases" (instead of "summary") and then click "Link Binary With Libraries" and add button then search OpenGL.framework
im not sure 100%, im new to this too :)
The easiest way is to go to your project settings, and under Linking -> Other Linking Flags add:
-framework OpenGL
In your project, create a group 'frameworks' (not really necessary but keeps things organized)
With Finder goto: /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks
Locate the OpenGL.framework folder
Drag and drop the folder into your XCode project (in the frameworks group)
Don't copy the files(!)
Probably you want to copy 'GLUT.framework' as well.
I have never been clearly understand all these linking/building/dependency business. Now, I am trying to build the FreeType library (which is in C++), into the *.a library file for the iPhone (because another library I am trying to use, openFrameworks, would depend on FreeType).
I know that to compile C++ with iPhone I simply need to rename *.cpp to *.mm. (I have tried with some simply programs in main() and it works) But how can I build the library in Xcode then ? (without the main() I suppose)
On the other hand, it would be great if you guys could recommend some books or documents on such linking/building topics, which I found myself most confused about.
PS. I have already got the paid version of Xcode and some sample apps compiled onto the iPhone.
Renaming .cpp files to .mm would mean they'll be treated as Objective-C++ code rather than C++ code. I don't think that'd be a good idea, even if it should still work. Besides, FreeType is written in C, not C++.
Google for "compiler linker" and you'll find quite a few documents on how they work. That should help for documentation.
It's entirely possible to compile static libraries for the iPhone; what you can't do is compile dynamic libraries or frameworks - you could, but it's not encouraged.
Open your project
In the source/target browser, select the "Targets" node (with the little red and white target icon).
Right-click on the node, and in the popup menu select "Add", followed by "New Target".
A dialog opens. On the left hand side, there's an iPhone OS and a Mac OS X section. The iPhone OS section should already be selected; if not do so.
You should have three choices of targets, one of it is a static library. Select it, click OK.
Give the library a name in the next page. Click finish.
Your "Targets" node has includes a child for your static library now. You can add sources either via the file menu, or by dragging it onto the "Compile Sources" child node.
Hope that helps.
First, you do not need to rename any files to compile C++ code for the iPhone. Secondly, you'll want to create a separate project for the library. It looks like the iPhone target types don't include "static library", so you might need to create a Mac OS X project and modify it to output an ARM .a file. Not trivial, but probably doable.
Alternatively, if you're not going to be using this code in a lot of otherwise unrelated projects, you could include the source files directly into your App project. Collect them all into their own group, and you'll hardly know they are there.