OpenGL and Mac OS X.5
I'm using OS X and my OpenGL teacher uses Linux. One of the sources he sent the class won't work when I load it into Xcode. I found
http://grammerjack.spaces.live.com/blog/cns!F2629C772A178A7C!200.entry
which says to use Eclipse, but when I follow the directions on it, I still can't get the sample to work.
Here is what it looks like.
#include <GL/glut.h>
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f (0.25, 0.25, 0.0);
glVertex3f (0.75, 0.25, 0.0);
glVertex3f (0.75, 0.75, 0.0);
glVertex3f (0.25, 0.75, 0.0);
glEnd();
glFlush ();
}
void init (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (250, 250);
glutInitWindowPosition (100, 100);
glutCreateWindow ("hello");
init ();
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}
I understand what it's doing, but it would be nice to actually run it. And be able to have my code work on his computer, so it can be graded. :)
Also, sorry for not using any markups. I don't know what they are. I tried using <link=></link> and <code></code>, but when I previewed it, they didn't work.
You're using Xcode so you have to create a project and add the GLUT framework to the project. Your include of glut.h will not work on Mac OS X. You need to use the following include:
#include <GLUT/glut.h>
For step by step instructions on using GLUT with Xcode on Leopard, read the article at the following URL:
http://blog.onesadcookie.com/2007/12/xcodeglut-tutorial.html
Mark
#include <GLUT/glut.h>
For step by step instructions on using GLUT with Xcode on Leopard, read the article at the following URL:
http://blog.onesadcookie.com/2007/12/xcodeglut-tutorial.html
Mark
Thanks, man. That helped A LOT.
One last question, tho.
If I changed #include <GLUT/glut.h> to #include <GL/glut.h> before I turned in my program, would that be all I would have to change for it to work on his computer? I only have to hand in the source.
One last question, tho.
If I changed #include <GLUT/glut.h> to #include <GL/glut.h> before I turned in my program, would that be all I would have to change for it to work on his computer? I only have to hand in the source.
Use the #if statement so you include GLUT the Mac way on a Mac and the Linux way on Linux. Here's an example.
For a GLUT program that doesn't load anything from a file, this would be all you would have to do for your code to work on your teacher's Linux computer.
#if __MACOSX__ #include <GLUT/glut.h>#else #include <GL/glut.h>#endif
For a GLUT program that doesn't load anything from a file, this would be all you would have to do for your code to work on your teacher's Linux computer.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement