Need some help before i blow up my head!!!!!

MicrosoftHater

Registered
For about 2 weeks ive been trying to learn OpenGL and use it on my mac, but even though ive found tutorials that "include" code for Mac OS X , they only change the header files and there are some things in there code that dosen't work for Mac, if any one here can give me a link to a nice and decent OpenGL tutorial made for Mac OS X in C++ ( usable in GCC 3.3 or Xcode's C++ tool ).

One of my other problems is that there is no Visual C++ complier , Xcode has a strange mixture of C# and C++ but it's made for C# and i know C++.

thanks for reading and hope you can help me!!
 
MicrosoftHater said:
For about 2 weeks ive been trying to learn OpenGL and use it on my mac, but even though ive found tutorials that "include" code for Mac OS X , they only change the header files and there are some things in there code that dosen't work for Mac, if any one here can give me a link to a nice and decent OpenGL tutorial made for Mac OS X in C++ ( usable in GCC 3.3 or Xcode's C++ tool ).

The first thing you have to decide is what language you want to use OpenGL from. If it's from Objective C, then what I say below doesn't apply.

However, since you mention C++ (or C for that matter) the advice below would apply.

To program in OpenGL, the first thing you have to decide is:

What is going to draw my windows, menus, etc? In short, what is going to provide my windowing system?

There are two ways to accomplish that:
1) Use GLUT. This gives you a simple interface to create windows, handle menus, etc. With a few simple calls, GLUT will create a window, create and OpenGL context and attach it to the window.

2) Use the platform's native API for creating windows. Since you're using C++, that'd be Carbon. You'd use Carbon functions to create the window, menubar, etc, and then you'd use OpenGL functions to create the context and attach it to the window.

For a beginner, I'd recommend #1. An OpenGL GLUT sample can be found in Apple's sample code, here:

http://developer.apple.com/samplecode/GLUTBasics/GLUTBasics.html

This will open up and run just fine in XCode - I just tested it.

The thing to understand is that OpenGL code isn't really different between platforms - the only thing that's different is:
1) The location of the header files
2) The file glext.h, which you'll see used in some PC programs is not used on OS X
3) The way you create an OpenGL context and attach it to a window (or go fullscreen)

Number 3 is where 99% of the difference is. It's the same thing on each platform, but each platform has their own routines. For example, on Windows, one uses the WGL routines to get a context created and attach it to a window. On a XWindows system, you'd use the GLX routines, and on the Mac, you use the AGL routines.

Once you get the window created and the context attached, OpenGL is nearly identical regardless of platform. Again, I'd recommend you just let GLUT handle all the windowing stuff at first.

The main thing you need to do is to learn how to convert a tutorial. For a simple GLUT tutorial, all you should really need to do is change some of the header include statements.

For example, take the MacOS tutorial at:

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=02

Now, this tutorial was written for OS 9, and includes a project file for MetroWerks CodeWarrior (a commercial C/C++ compiler).

However, I only had to change 3 include statements to get it to run.

Here's what I did:

1) I removed the source files from the GLUTBasics project. That is, I removed SurfaceGeometry.c, trackball.c and glutBasics.c.

2) I added the main.c file from the lesson 2 tutorial to the project

3) I changed line 21 from
#include <gl.h>
to the Mac format:
#include <OpenGL/gl.h>

4) Similarly, I changed line 22 from
#include <glu.h>
to the Mac format:
#include <OpenGL/glu.h>

5) And I changed line 23 from
#include <glut.h>
to the Mac format:
#include <GLUT/glut.h>

Then it will run fine.

Just for fun, let's do a more generic example that was written for another platform. Rather than using the MacOS code for Lesson 2, use just the generic GLUT code:

For example, for:

http://nehe.gamedev.net/data/lessons/glut/lesson02.zip

Here's how I got it to run on the Mac - again, I used the GLUTBasics project as my starting point.

1) I removed the source files from the GLUTBasics project. That is, I removed SurfaceGeometry.c, trackball.c and glutBasics.c.

2) I added the lesson2.cpp file to the project

3) I remove line 9, which is:
#include <windows.h>

this is a Windows-only file.

4) I changed line 10 from
#include <GL/gl.>
to the Mac format:
#include <OpenGL/gl.h>

5) Similarly, I changed line 11 from
#include <GL/glut.h>
to the Mac format:
#include <GLUT/glut.h>


6) Then there were some general errors that most compilers would probably choke on:

Line 65, exit() is undeclared. That's because on Unix, you need to #include <stdlib.h> - so put that at the top with the other includes.

Line 87, main returns void. I'm not sure how old the compiler this person was using was, but main returns int and has for many, many years. So change main to return an int.

int main ( int argc, char **argv )

Line 90, move the author's init() call to after the glutCreateWindow() call. He shouldn't be doing OpenGL operations until everything is completely setup - doing it where it is now will cause the program to crash.

With those changes, this most generic of tutorial code will run. That may seem like a lot of changes, but everything under #6 are the author's errors - not something specific to the Mac.


One of my other problems is that there is no Visual C++ complier , Xcode has a strange mixture of C# and C++ but it's made for C# and i know C++.

No, XCode doesn't do C# - that's a Windows thing.

Xcode does C, C++, Objective-C and Java. (And some others, but those are its strong suits)

XCode is just an IDE - same as Visual C++ on Windows. XCode just uses the command-line gcc tools underneath.

Hope this helps.

Wade
 
Back
Top