Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 16, 2008, 05:48 PM   #1
kashmoney2006
macrumors regular
 
Join Date: Dec 2007
Problem running simple GLUT/OpenGL program in Xcode

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...-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.
kashmoney2006 is offline   0 Reply With Quote
Old Apr 16, 2008, 07:22 PM   #2
Muncher
macrumors 65816
 
Muncher's Avatar
 
Join Date: Apr 2007
Location: 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.
__________________
2.4Ghz 20" Rev. A iMac, Wii, crimson DS, intuos3 4x6, PS3
iPod touch 2G 16GB > Fiio E1 > Hifiman RE0
Muncher is offline   0 Reply With Quote
Old Apr 16, 2008, 08:51 PM   #3
m85
macrumors newbie
 
Join Date: Apr 2008
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.
m85 is offline   0 Reply With Quote
Old Apr 16, 2008, 10:29 PM   #4
kashmoney2006
Thread Starter
macrumors regular
 
Join Date: Dec 2007
Quote:
Originally Posted by Muncher View Post
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)?
kashmoney2006 is offline   0 Reply With Quote
Old Apr 17, 2008, 02:33 AM   #5
Cromulent
macrumors 603
 
Cromulent's Avatar
 
Join Date: Oct 2006
Location: The Land of Hope and Glory
The only frameworks you need are GLUT and OpenGL. I just make a standard C command line project as a Carbon application project seems a bit overkill really.
__________________
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
Cromulent is offline   0 Reply With Quote
Old Apr 18, 2008, 09:49 PM   #6
Muncher
macrumors 65816
 
Muncher's Avatar
 
Join Date: Apr 2007
Location: California
Quote:
Originally Posted by kashmoney2006 View Post
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 .

@Cromulent: I thought you needed CoreServices, etc. I've always just added them automatically. Oh well.
__________________
2.4Ghz 20" Rev. A iMac, Wii, crimson DS, intuos3 4x6, PS3
iPod touch 2G 16GB > Fiio E1 > Hifiman RE0
Muncher is offline   0 Reply With Quote
Old May 12, 2008, 09:03 PM   #7
matt90
macrumors member
 
Join Date: Feb 2008
Location: Los Alamos, New Mexico (Atomic City)
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?

Last edited by matt90; May 12, 2008 at 09:08 PM. Reason: Clarification
matt90 is offline   0 Reply With Quote
Old May 13, 2008, 01:08 PM   #8
kashmoney2006
Thread Starter
macrumors regular
 
Join Date: Dec 2007
Quote:
Originally Posted by matt90 View Post
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.
kashmoney2006 is offline   0 Reply With Quote
Old May 13, 2008, 01:22 PM   #9
m85
macrumors newbie
 
Join Date: Apr 2008
http://blog.onesadcookie.com/search/label/tutorial
m85 is offline   0 Reply With Quote
Old May 16, 2008, 07:37 PM   #10
matt90
macrumors member
 
Join Date: Feb 2008
Location: Los Alamos, New Mexico (Atomic City)
Well, it works now. I thought that I had already tried this, but after I added the GLUT and OpenGL frameworks and included GL/gl.h, GL/glu.h, and GL/glut.h, it started working. Thanks, everybody!
matt90 is offline   0 Reply With Quote
Old Nov 24, 2009, 01:35 AM   #11
urchinsub
macrumors newbie
 
Join Date: Nov 2009
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?
urchinsub is offline   0 Reply With Quote
Old Nov 24, 2009, 03:46 AM   #12
Cromulent
macrumors 603
 
Cromulent's Avatar
 
Join Date: Oct 2006
Location: The Land of Hope and Glory
Quote:
Originally Posted by urchinsub View Post
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.
__________________
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
Cromulent is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Coding OpenGL in XCode Sebnabt Mac Programming 2 Sep 23, 2013 12:58 PM
Xcode OpenGL Ram Problem jmfel1926 Mac Programming 5 Aug 21, 2013 07:06 PM
OpenGL ES Xcode Template Example -- Indices Blakeasd iPhone/iPad Programming 1 Jun 16, 2013 04:46 PM
Problem running a program because of Java GrantMeThePower OS X 10.8 Mountain Lion 5 Jan 16, 2013 08:24 PM
Very Simple Explanation of glOrthof() in OpenGL ES Blakeasd iPhone/iPad Programming 2 Dec 29, 2012 10:23 AM

Forum Jump

All times are GMT -5. The time now is 10:16 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC