Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kashmoney2006

macrumors regular
Original poster
Dec 12, 2007
232
0
So I have to learn GLUT for a project and I and trying to follow a tutorial. the problem is, when I run the code found in the tutorial, nothing happens? Why is this? Here is the code I am trying to get to work:

Code:
#include <stdlib.h>

#include <GLUT/glut.h>

void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glutSwapBuffers();
}

void reshape(int width, int height)
{
    glViewport(0, 0, width, height);
}

void idle(void)
{
    glutPostRedisplay();
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(640, 480);
    
    glutCreateWindow("GLUT Program");
    
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutIdleFunc(idle);
    
    glutMainLoop();
    return EXIT_SUCCESS;
}

It compiles without any errors or warnings but when it runs nothing happens. The tutorial says that a black window should pop up, but no window here?? Does anybody have any suggestions? I am running Xcode 3.1 on Mac OS 10.5.2 and the tutorial is here:
http://blog.onesadcookie.com/2007/12/xcodeglut-tutorial.html

I have also tried to compile and run code from other sources but I get the same result. Any help is appreciated. Thanks.
 

Muncher

macrumors 65816
Apr 19, 2007
1,465
0
California
I don't think the tutorial is to fault, I used it a couple months ago and it worked for me.

The general steps of the tutorial are this.

1. Make a new (empty) project.
2. Right-click (ctrl-click) on the top icon (project icon) under the "Groups & Files" column in the new project window. Select New Target. Click Carbon Application.
3. The target settings will pop up. Find the box which says: "Base SDK Path," and double click. A box will scroll down. Paste (if it isn't already there) "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk" (no quotes). If the line in the box ends with "MacOSX10.4u.sdk" switch ".4u" to ".5". For some reason if you use the 10.4 sdk, it won't work (just my experience, it probably works but it didn't for me).
4. Right-click (ctrl-click) on the top icon (project icon) under the "Groups & Files" column in the new project window. Select Existing Frameworks. Find and Command-click the following frameworks (folders):

Application Services
Carbon
Core Services
GLUT
Hit Add. It will ask you if you want to add them to the target you created. Hit yes.
5. Right-click (ctrl-click) on the top icon (project icon) under the "Groups & Files" column in the new project window. Select New File. Click either C or C++ file, or if you want to use Carbon, Carbon C or Carbon C++ (I recommend Carbon C++, you get the greatest flexibility with it.)
6. Paste your code into the C/C++ file you created.
7. In the Project window, hit Build and Go.

It should work! Let us know if you still have problems.
 

m85

macrumors newbie
Apr 8, 2008
8
0
You may also need to add OpenGL.framework.

I also had some trouble with a simple GLUT app a few days ago. My code would compile but would refuse to link the gl functions (glut functions were fine). It was a very basic Xcode 3.1 project with just main.c, GLUT.framework and the target (shell tool). This had previously worked for me in Xcode 2.4 so I got really stressed until I thought of adding OpenGL.framework and it worked.

Hope this helps.
 

kashmoney2006

macrumors regular
Original poster
Dec 12, 2007
232
0
I don't think the tutorial is to fault, I used it a couple months ago and it worked for me.

The general steps of the tutorial are this.

1. Make a new (empty) project.
2. Right-click (ctrl-click) on the top icon (project icon) under the "Groups & Files" column in the new project window. Select New Target. Click Carbon Application.
3. The target settings will pop up. Find the box which says: "Base SDK Path," and double click. A box will scroll down. Paste (if it isn't already there) "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk" (no quotes). If the line in the box ends with "MacOSX10.4u.sdk" switch ".4u" to ".5". For some reason if you use the 10.4 sdk, it won't work (just my experience, it probably works but it didn't for me).
4. Right-click (ctrl-click) on the top icon (project icon) under the "Groups & Files" column in the new project window. Select Existing Frameworks. Find and Command-click the following frameworks (folders):

Application Services
Carbon
Core Services
GLUT
Hit Add. It will ask you if you want to add them to the target you created. Hit yes.
5. Right-click (ctrl-click) on the top icon (project icon) under the "Groups & Files" column in the new project window. Select New File. Click either C or C++ file, or if you want to use Carbon, Carbon C or Carbon C++ (I recommend Carbon C++, you get the greatest flexibility with it.)
6. Paste your code into the C/C++ file you created.
7. In the Project window, hit Build and Go.

It should work! Let us know if you still have problems.

Thanks! I had to also add OpenGL.framework, but once i did that, it worked like a charm! Why did i choose Carbon Application? In the tutorial it said to choose Cocoa application, do you think that was the problem? or do you think it is the 3 other frameworks that you had me add (Application Services, Carbon, and Core Services)?
 

Muncher

macrumors 65816
Apr 19, 2007
1,465
0
California
Thanks! I had to also add OpenGL.framework, but once i did that, it worked like a charm! Why did i choose Carbon Application? In the tutorial it said to choose Cocoa application, do you think that was the problem? or do you think it is the 3 other frameworks that you had me add (Application Services, Carbon, and Core Services)?

Actually, you don't have to, but the button() function in Carbon is pretty handy for small demos :D.

@Cromulent: I thought you needed CoreServices, etc. I've always just added them automatically. Oh well. :p
 

matt90

macrumors member
Okay. I'm having a similar problem.

I'm an absolute beginner at OpenGL/GLUT in C. I've managed to compile programs properly in Ubuntu, but when I try to compile using gcc in Mac, it gives me the following error message:

/usr/bin/ld: Undefined symbols:
_glClear
_glClearColor
_glColor3f
_glColorMaterial
_glEnable
_glLightfv
_glLoadIdentity
_glMatrixMode
_glRotatef
_glTranslatef
_gluPerspective
_glutCreateWindow
_glutDisplayFunc
_glutIdleFunc
_glutInit
_glutInitDisplayMode
_glutInitWindowPosition
_glutInitWindowSize
_glutKeyboardFunc
_glutMainLoop
_glutSolidSphere
_glutSwapBuffers
collect2: ld returned 1 exit status

(Or, basically, all of the OpenGL/GLU/GLUT calls that I try to make.)

I've tried compiling with Xcode as well, but it gives me essentially the same error. I'm using Tiger 10.4.11. Also, when I change the target settings for the 10.4 SDK, it tells me that the SDK doesn't exist.
What am I doing wrong?
 

kashmoney2006

macrumors regular
Original poster
Dec 12, 2007
232
0
Okay. I'm having a similar problem.

I'm an absolute beginner at OpenGL/GLUT in C. I've managed to compile programs properly in Ubuntu, but when I try to compile using gcc in Mac, it gives me the following error message:

/usr/bin/ld: Undefined symbols:
_glClear
_glClearColor
_glColor3f
_glColorMaterial
_glEnable
_glLightfv
_glLoadIdentity
_glMatrixMode
_glRotatef
_glTranslatef
_gluPerspective
_glutCreateWindow
_glutDisplayFunc
_glutIdleFunc
_glutInit
_glutInitDisplayMode
_glutInitWindowPosition
_glutInitWindowSize
_glutKeyboardFunc
_glutMainLoop
_glutSolidSphere
_glutSwapBuffers
collect2: ld returned 1 exit status

(Or, basically, all of the OpenGL/GLU/GLUT calls that I try to make.)

I've tried compiling with Xcode as well, but it gives me essentially the same error. I'm using Tiger 10.4.11. Also, when I change the target settings for the 10.4 SDK, it tells me that the SDK doesn't exist.
What am I doing wrong?

did you include the libraries in your code? did you use GL/glut.h and GL/glu.h or GLUT/glut.h and OpenGL/glu.h? also, did you link the frameworks to your project? the OpenGL and GLUT frameworks should be linked to you target in Xcode. how big is your project? if you would like to send it to me I could try compiling it myself.
 

urchinsub

macrumors newbie
Nov 23, 2009
14
0
Exc_bad_access

My problem sounds similar but the advice hasn't worked. the error log says It experiences an "EXC_BAD_ACCESS". I am trying to use CFDate/data/string and have added the frameworks for those, could that be causing some kind of conflict with the console application?
 

Cromulent

macrumors 604
Oct 2, 2006
6,802
1,096
The Land of Hope and Glory
My problem sounds similar but the advice hasn't worked. the error log says It experiences an "EXC_BAD_ACCESS". I am trying to use CFDate/data/string and have added the frameworks for those, could that be causing some kind of conflict with the console application?

That sounds like you are trying to use a NULL pointer to me.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.