Help with <GL/glut.h> please.

DudetheCreator
Unregistered
 
Post: #1
Hello, I have recently aquired the red book and am now looking through the first code. When I build in xCode I get errors. Before I go any further I will say that I HAVE included OpenGL and GLUT in my "Other Frameworks". Ok, I get 6 errors, 5 out of 6 of them are because xCode can't find <GL/glut.h>. The red book uses Glut, so it tells me to state this in all my code:

Quote:#include <GL/glut.h>

And I do, but xCode can't find glut.h. Where is it?

Just in case, here is the code:


Quote:#import <Cocoa/Cocoa.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>

void display(void)
{
/* clear all pixels */
glClear(GL_COLOR_BUFFER_BIT);

/* draw white polygon (in this case it's a rectangle...) */

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();

/* start processing buffered OpenGL routines */

glFlush();

}

void init(void)
{
/* select clearing (background) color, in this case, it's black */
glClearColor(0.0, 0.0, 0.0, 0.0);

/* initialize viewing variables */
gl_MatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

/*
Declare initial window size, position, and display mode
(single buffer and RGBA). Open with "hello" in its
title bar. Call initialization routines. Register
callback function to display graphics. Enter the main
loop and process events.
*/
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 NSApplicationMain(argc, (const char **) argv);
}


Thanks!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
http://onesadcookie.com/~keith/XcodeGLUT

(this particular problem is that Mac OS X calls it <GLUT/glut.h>, but that tutorial should solve some more errors you're just about to have Wink )
Quote this message in a reply
DudetheCreator
Unregistered
 
Post: #3
THANKS A TON! I bookmarked the tutorial, just in case, although your indiscreet wink indicates that i should probably make it my homepage! Grin
Quote this message in a reply
DudetheCreator
Unregistered
 
Post: #4
ARGH! It still doesn't work! I fixed the syntax and everything compiled ok, but when i click the app it starts then quits without displaying the window and polygon! Mad Cry

Sorry, I just despise errors! I think it's because it's a cocoa app and it needs an interface to render into. I will try it as a C Tool.
Quote this message in a reply
DudetheCreator
Unregistered
 
Post: #5
Ok, using your tutorial, I made the Carbon app. Now when I build, I get 3766 errors. Most of them complain about @ symbols. OpenGL Programming Guide is a uses C++, your manual references to main.c shouldn't it be main.cpp?
Quote this message in a reply
MarkJ
Unregistered
 
Post: #6
Make sure its not crashing. Check the crashlog from Console.app
Quote this message in a reply
DudetheCreator
Unregistered
 
Post: #7
Oh, good idea, thx. Anyway, by changing main.c to main.cpp I have narrowed it down to only 2541 errors! Phew... They complain about parse errors... I WILL COMPLETE THIS!!! ARGH!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
are you sure you made a Carbon project as the tutorial suggests? That sounds awfully like the number of errors people get when they make a Cocoa project...
Quote this message in a reply
Vertizor
Unregistered
 
Post: #9
I'm curious, why use a Carbon project template?

What I've done is start an empty project then I import the GLUT.framework, OGL.framework, and since GLUT in OSX uses CoreFoundation (Obj-C runtime) I also imported Cocoa.framework and then it would build.

It refuses to build unless I imported a framework that would bring in the Obj-C runtime. So I guess Core Foundation alone would have been enough.
Quote this message in a reply
DudetheCreator
Unregistered
 
Post: #10
I am pretty sure I made an empty project then added a carbon target. Along with cocoa, opengl and glut frameworks. I will try it with main.m...
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #11
Vertizor Wrote:... and since GLUT in OSX uses CoreFoundation (Obj-C runtime) ...

It refuses to build unless I imported a framework that would bring in the Obj-C runtime. So I guess Core Foundation alone would have been enough.

I think you're confusing CoreFoundation with Foundation. CoreFoundation is Carbon; Foundation is Cocoa. They share a lot of functionality, but are in fact two separate frameworks/APIs. GLUT on Mac OS X uses Cocoa.

- Alex Diener
Quote this message in a reply
DudetheCreator
Unregistered
 
Post: #12
Ah-Ha! So the tutorial is wrong? And I should add a cocoa target?
Quote this message in a reply
Vertizor
Unregistered
 
Post: #13
Hehe, glad someone understood what I was trying to say. Thanks for the correction.

And DudetheCreator, renaming it to .m should not be necessary but go ahead and give it a try.
Quote this message in a reply
DudetheCreator
Unregistered
 
Post: #14
Thanks a ton! So, now I shall make an empty project with a COCOA target!


Thanks!
Merci!
Muy Gracias!
Quote this message in a reply
Vertizor
Unregistered
 
Post: #15
The "target" is still just a .app bundle. I'm just saying, you may need to import Cocoa.framework. You are NOT building a Cocoa app per se.
Quote this message in a reply
Post Reply