PDA

View Full Version : Getting Started with OpenGL - Mac


ThrottleMonkey
2003.03.10, 06:30 PM
I've been looking around the internet for quite some time. OpenGL.org has great tutorials and whatnot on how to get started... learning to code in OpenGL... but the Apple website (IMO) is crap when it comes to explaining how/where to get/download GLUT and OpenGL for OSX.

Would someone be kind enough to point a total newbie in the right direction?

macboy
2003.03.10, 06:36 PM
Click the "idg faq" button at the top then on the iDevGames site, look at some of the examples and such. :cool:

skyhawk
2003.03.10, 06:43 PM
standard nehe.gamedev.net plug applies

[edit] fixed site :rolleyes: jabber :p

Mark Levin
2003.03.10, 07:40 PM
GLUT is provided as a framework included with the dev tools. Throw it into the project, write a new main.c, and it should be good to go.

The next harder thing to learn is AGL, which is closely tied to the window manager, but you'll need it for Carbon work without GLUT.

OneSadCookie
2003.03.10, 08:22 PM
Just to explicitly say it, GLUT and OpenGL come with Mac OS X. There's nothing you need to install but the developer tools.

kelvin
2003.03.10, 08:46 PM
For glut, my suggestion would be just too pick apart Apple's sample code:
http://developer.apple.com/samplecode/Sample_Code/Graphics_3D/GLUT_for_OS_X.htm

if you're not interested in glut, and are looking for a more non-portable option, I'd suggest looking into working with OpenGL in Cocoa. If you have any questions about Cocoa and OpenGL I'll be happy to answer.

Josh
2003.03.10, 11:34 PM
Originally posted by skyhawk
standard nehe.gamedev.org plug applies I perfer nehe.gamedev.net :p

Feanor
2003.03.10, 11:39 PM
Was not there a bunch of stuff on the OpenGL list lately about GLUT being incomplete in the distribution and you had to compile it yourself to get it to work correctly? I know the framework that is installed is functional...

ThrottleMonkey, don't forget to tell us what OS version you are using and what developer tools you have chosen. In any case you have to link to the correct libraries/frameworks, and how you do that depends on the IDE. But I'll ditto OSC that you don't have to download or install anything. Also, if you have the Apple developer tools installed on OS X, there are a pile of AGL, NSGL and GLUT sample applications.

I recommend OS X, and either Project Builder (free) or CodeWarrior ($$) to develop with. You will probably get more help from those of us around here who like Apple's tools because they are free and work pretty darn well. If you are using GLUT, you also need to link to the Cocoa frameworks on OS X because they are used to implement GLUT. From there, either NeHe examples or, do yourself a favour, read the OpenGL Programming Guide. It's for sale in stores at v1.2, and free online for v1.1 (http://fly.cc.fer.hr/~unreal/theredbook/).

I have added some of this to the FAQ (http://www.crissman.net/macgamewiki/index.php/NewToOpenGL). If this is somehow redundant... then the FAQ needs reorganization. :p

ThrottleMonkey
2003.03.11, 01:59 AM
I have OSX 10.2.4 and CodeWarrior.

I really want to begin programming, but... well... I kinda need a mentor.

Preferably someone that is patient with someone (me) who asks lots of questions.

NEHE looks great, only the Tutorial on OpenGL is very vague as with which program you're supposed to be putting all that code in... is it CodeWarrior, GLUT? what?

I thank you all for your input. I'm just getting very frustrated at running around in circles in the past, trying to find good help, examples, tolerant people (who are tolerant of coders just starting out... total newbies like me).

Oh, and what's the Project Builder download link? I keep going to apples' dev site and only get the "run around" links... not some place i can actually download it.

OneSadCookie
2003.03.11, 04:08 AM
If you got a new Mac with 10.2 installed, there's a dev tools installer in /Applications/Installers/. It's not the most up-to-date, but it should do you to begin.

If you bought 10.2 retail, the dev tools came on an extra CD. Again, not the most recent version...

If you go to http://connect.apple.com/, you can sign up to be an online member of the Apple Developer Connection (free), this lets you download the latest developer tools (250-300MB).

Josh
2003.03.11, 09:27 AM
Originally posted by ThrottleMonkey
I really want to begin programming, but... well... I kinda need a mentor.Are you new to programming in general or just OpenGL?

Feanor
2003.03.11, 10:03 AM
Originally posted by ThrottleMonkey
NEHE looks great, only the Tutorial on OpenGL is very vague as with which program you're supposed to be putting all that code in... is it CodeWarrior, GLUT? what?

The NeHe Tutorials were originally written to work with Windows -- you'll see "#include <windows.h>" at the beginning of the example files. However, there are GLUT versions available for download. Also, note there are almost forty tutorials, from the absolute simplest all the way to quite complicated games.

Question: Are you already familiar with the C programming language? (Note to self: finish "ChooseYourEnvironment" in FAQ.)

sealfin
2003.03.11, 10:51 AM
Insert neheX (http://nehex.idevgames.com) plug here.
Insert guilt for not having finished the site yet here.

ThrottleMonkey
2003.03.11, 12:30 PM
Thank you Cookie. I'm downloading the Dev Tools right now. A whopping 300 Mb.

To answer the other questions, I'm only a couple weeks into C++, but I'm not a complete stranger to programming. Well, if you really call QBasic, HTML and FileMakerPro programming. :blush:

I've already written MUD-like text-based games in C++ to get used to the idea of programming for games and I'm wanting to make the graphical "leap".

I'm dedicated and highly motivated (sounds like a resume) but I'm the kind of guy that needs the initial spoon feeding and push in the right direction.

Thanks for everyone's comments so far, it's more help than I've gotten from the CodeWarriorU.com site.

BobbyWatson
2003.03.11, 12:58 PM
Instead of dealing with AGL for creating OpenGL contexts in windows or fullscreen, you may want to check out SDL (http://www.libsdl.org), a very nice little library which can create a context for you very easily (the way to do it is written in the documentation, it only takes a few function calls instead of the two pages of code Apple provides as a sample) and works pretty well from what I've seen.

Josh
2003.03.11, 03:48 PM
There are numerous Cocoa OpenGL examples here at iDG (in the source code section) and With a Y (http://www.withay.com/) has Cocoa ports of NeHe's tutorials. On the other hand, if you wish to continue with C++, I would recommend checking out sealfin's ports. (How are those going, btw?) If you ever have a specific question about programming or OpenGL, feel free to ask away. There are some gurus that frequent the boards that seem to be living programming references (you know who you are :lol: ). Good luck! Programming can be tricky but extremely rewarding!

ThrottleMonkey
2003.03.11, 04:52 PM
Ok, I've got all these files on my comptuer and no idea where to begin. Thanks for your patience so far.

I guess it would kind of help if everyone posted where they began with it all. Right now it's kind of overwhelming. The dedication is still there, and I can almost taste a beginning... but I'm really rather confused on where to start.

I guess I'm just lost!

Sure, programming can be tricky... but GETTING to the point where you can actually put in some kind of code seems to be the biggest step for me! :wacko: Help!

Also, when I open Project Builder (and am going through NEHE's first tutorial), select "File>NewProject" it gives me a screen that says "empty project" as my only option... This is an empty project with no files, targets, or build styles.

Where as NEHE's tutorial says I should be able to select a "Cocoa Application"... whatever he means there.

DoG
2003.03.11, 05:34 PM
Actually, I started with the opengl redbook, and only then went on to nehe tuts after I thought I understand the basics.

Mars_999
2003.03.11, 05:40 PM
I started with getting a good grasp on C++, and then got SDL and worked with that, and then bought the OpenGL game programming book and used SDL with it. The first thing to do is setup OpenGL and from their make a triangle and display it!! Then change the colors then rotate it and shift it ect.... Baby steps my young grasshopper!! I was the same way when I first was learning OpenGL and C++. Still got plenty to learn but who doesn't!! :wow:

Bachus
2003.03.11, 05:58 PM
Also, when I open Project Builder (and am going through NEHE's first tutorial), select "File>NewProject" it gives me a screen that says "empty project" as my only option... This is an empty project with no files, targets, or build styles.

Whoa. Are you sure? That's really weird. You should see "Empty Project" at the very top, with a bunch of subheadings like "Application," "Bundle," "Framework," etc. Try reinstalling Project Builder.

Okay. How to get started with OpenGL First of all, you should read this article (http://developer.apple.com/techpubs/macosx/Carbon/graphics/OpenGL/OpenGL/chap4/chapter_4_section_1.html) on setting up OpenGL in Cocoa (a notoriously hard article to find considering it's found in the *Carbon* docs). Just follow it step by step and you'll learn how to create an OpenGL View and draw things in it. After you've done that you're ready for the NeHe lessons (http://nehe.gamedev.net/). There's Cocoa code at the bottom of every sample that you can follow along with. Stick to the first 8 lessons until you've really got everything down.

Also see this documentation (http://developer.apple.com/techpubs/macosx/Cocoa/TasksAndConcepts/ProgrammingTopics/OpenGL/index.html) and this sample code (http://developer.apple.com/samplecode/Sample_Code/Graphics_3D/Cocoa_InitGL.htm).

Going through all that will probably take about two weeks for you to really learn it. Then you'll be ready for more advanced topics. Buy a copy of the OpenGL Red Book (http://www.amazon.com/exec/obidos/tg/detail/-/0201604582/qid=1047419338/sr=8-1/ref=sr_8_1/103-0198065-8586234?v=glance&s=books&n=507846). It's value can not be overstated (though don't begin with the book). Oh, and I'd stay away from GLUT or SDL, at least at first. You're not really learning if you're letting them do all the work for you.

Feanor
2003.03.11, 06:13 PM
ThrottleMonkey,

The hardest problem I ever had with programming was getting familiar with the tools. They are large, they are complicated, and they replace another kind of complication which exists under the surface. It took me quite a long time and a lot of different tools to finally get comfortable with the peripheral issues which are essential. Writing software requires a knowledge of the platform, especially the runtime.

It's too bad there isn't a short intro guide to the Mac OS X runtime. Apple has a big complicated one, and you might do well to skim the introduction to it: Mac OS X Runtime Architecture (http://developer.apple.com/samplecode/Sample_Code/Runtime_Architecture.htm). Very briefly, there is language, preprocessing, compiling, assembling, and linking. You should know a little about all of those (a lot about language), although compiling and assembling is mostly automatic. Now you know why people sometimes prefer BASIC or Java or another language where much of this is hidden from you.

Another key point is libraries (or frameworks): pre-compiled code provided by the operating system or third parties which you can take advantage of using the interface, by including the correct header files and linking to the library or framework. Read the Project Builder help files to learn about linking.

Once you understand a bit about the context of writing code, you will feel much more comfortable, and can then worry about the specifics of dealing with the OpenGL framework and its conventions. That will include learning the terminology of 3D rendering and the data types and functions used to access OpenGL's rendering features.

At this point, you must simply accept that there is a minimum amount of reading, searching, head scratching and question posing in order to go from treading water to swimming. If you take your time and don't panic, you will have no problem.

Josh
2003.03.11, 06:29 PM
Originally posted by ThrottleMonkey
Also, when I open Project Builder (and am going through NEHE's first tutorial), select "File>NewProject" it gives me a screen that says "empty project" as my only option... This is an empty project with no files, targets, or build styles.That's a new one. As Bachus said, you should see a lot of options. If you don't, perhaps you should try a different version? :blink:

ThrottleMonkey
2003.03.11, 06:52 PM
Doh! I moved my "Developer" folder to a different location... hence the empty project dilema.

You guys rock! Thanks for all your help! Though I'm sure you'll hear panic filled cries from me still.

ThrottleMonkey
2003.03.11, 07:26 PM
Ok, here's another question...

Since I can run Project Builder now, if I want the OpenGL tutorials to work that are provided by NEHE, do I just cut and paste? Sure I have to add the frameworks... but when I DO cut and paste after doing all the other stuff (adding frameworks) i get a bunch of build errors. What gives?

OneSadCookie
2003.03.11, 07:34 PM
What errors do you get?

Feanor
2003.03.11, 07:42 PM
NeHe, as I mentioned, wrote his tutorials for Windows. They will not work as is for Mac. Download the best match project file from the link at the bottom of the page. You have to decide whether to use AGL (Carbon), NSGL (Cocoa) or GLUT. I recommend GLUT. Start with the OS X GLUT tutorial (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=MacOSX), which spells everything out for you. Then continue onto the tutorials proper. There are also a ton of GLUT samples in the developer/examples/OpenGL/GLUT folder, all part of one uber-project, with which you can build a single project (recommended) or all the projects at once (not recommended).

Note on Project Builder: I strongly recommend choosing a shared build folder for projects, and not storing build products inside each project folder, especially with the samples. This will save you from some aggravations later. Read the Project Builder release notes and developer tools help topics now! Failure to heed this requirement will bring the anger of the OS X Developer gods (the Apple engineers) down upon you!

ThrottleMonkey
2003.03.12, 01:28 AM
Bachus:

Originally posted by Bachus
Okay. How to get started with OpenGL First of all, you should read this article (http://developer.apple.com/techpubs/macosx/Carbon/graphics/OpenGL/OpenGL/chap4/chapter_4_section_1.html) on setting up OpenGL in Cocoa (a notoriously hard article to find considering it's found in the *Carbon* docs). Just follow it step by step

Thanks for the link man, it looks way helpful.

ThrottleMonkey
2003.03.12, 02:12 AM
Okie dokie, I've already run into another problem.

On the 1st lesson mentioned in the quote above from Bachus, when it comes time to "Build and Run" I think I've done everything right, but I get the following error:


Missing file or directory: Green
Missing file or directory: Triangle_Prefix.h

Now, the file "Green Triangle_Prefix.h" exists... but it was in the "Other Sources" group folder. Does this matter?

Since it's breaking that into two files or directories, do I need to put an underscore between "Green" and "Triangle"?

Any hints? I'll keep re-working the tutorial again and again to make sure I'm not doing anything dumb. :p


*** EDIT !!! ***
Ok, YES! It was the fact that "Green Triangle_Prefix.h" were separated. Apple should make note of that for n00bs like me. Oh... and BTW... I DREW A GREEN TRIANGLE!!! :wow:
*cough* ok, more like jacked some code... :lol: Back to the tutorials I go!

Thanks again everyone for all your help!

ThrottleMonkey
2003.03.12, 02:54 AM
Cheers! I now have a pulsating green triangle!

:ohmy:

Hmm... I still don't know what I just did. :rolleyes:

Do the rest of those courses clear things up a bit? It seems like GL has a few new commands up its sleeve I'm still a bit fuzzy on.

skyhawk
2003.03.12, 02:58 AM
which commands are you unsure of? also, most (all?) opengl commands have a man page you can use to understand the function in depth

Feanor
2003.03.12, 10:10 AM
Originally posted by ThrottleMonkey
Do the rest of those courses clear things up a bit? It seems like GL has a few new commands up its sleeve I'm still a bit fuzzy on.
Congrats on your first OpenGL app.

The tutorials teach you some programming techniques. They will make sense in proportion to how much you know about how 3D rendering works on the inside. Here is an article (http://www.nvnews.net/articles/opengl/introduction.shtml) by someone in your position -- learning both OpenGL and 3D real time graphics for the first time. It looks good.

ThrottleMonkey
2003.03.12, 12:25 PM
That's a cool article! Thanks!

ThrottleMonkey
2003.03.12, 05:05 PM
Hey, I can't thank you guys enough! I've gone through everything that everyone has suggested and commented on and now I'm trucking through the NEHE tutorials and actually understand them. I can't thank you guys enough! You're awesome!

If I could bake cookies, I would!

Mars_999
2003.03.12, 06:46 PM
Originally posted by ThrottleMonkey
Hey, I can't thank you guys enough! I've gone through everything that everyone has suggested and commented on and now I'm trucking through the NEHE tutorials and actually understand them. I can't thank you guys enough! You're awesome!

If I could bake cookies, I would!

I would prefer if you bought Pizza!!

cheez0r
2003.03.17, 02:44 PM
Originally posted by ThrottleMonkey
If I could bake cookies, I would!

You could try nehe.bakingcookies.net

xDexx
2003.03.18, 06:07 PM
nehex finally got me to understand how to do basic opengl on mac os x :) im sure someone already suggested this already but i just thought i would throw in my expirance. nehex.idevgames.com
-brett