Setting up OpenGL (was: XCode's fault or Mine?)

Marjock
Unregistered
 
Post: #1
so, when I try and like build and run this code in XCode (Carbon Application) XCode "unexpectedly quits"

The code is as follows:

----------------
Code:
#include <Carbon/Carbon.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <OpenGL/glext.h>

CFDictionaryRef newMode;                
CFDictionaryRef originalMode;            

size_t desiredBitDepth = 32;            
size_t desiredWidth = 1024;                
size_t desiredHeight = 768;        
boolean_t exactMatch;



int main() {


originalMode = CGDisplayCurrentMode( kCGDirectMainDisplay );

newMode = CGDisplayBestModeForParameters (
    kCGDirectMainDisplay,
    desiredBitDepth, desiredWidth,
    desiredHeight, &exactMatch);
    
if (NULL != newMode) {
    
    CGDisplayCapture( kCGDirectMainDisplay );
    CGDisplaySwitchToMode ( kCGDirectMainDisplay, newMode);
    CGDisplayHideCursor( kCGDirectMainDisplay);
    

    glClearColor( 0,0,0,1);
    glClear( GL_COLOR_BUFFER_BIT);
    
    glColor3f(0.0f, 1.0f, 0.0f);
    
    glBegin( GL_TRIANGLES); {
    
        glVertex3f (-1.0f, 1.0f, 0.0f);
        glVertex3f (1.0f, 1.0f, 0.0f);
        glVertex3f (0.0f,-1.0f, 0.0f);
    
    }
    
    glEnd();
    
    glFlush();
    
    
    CGDisplayShowCursor( kCGDirectMainDisplay);
    CGDisplaySwitchToMode( kCGDirectMainDisplay, originalMode);
    CGDisplayRelease( kCGDirectMainDisplay);
    
}

return 0;

}
----------------------

it's weird, If i delete all the commands that start with gl then it doesn't unexpectedly quit, but it doesn't really do anything, either.

So can someone tell me, am I doing something wrong? or is it just XCode? (I don't realy suspect the latter, but I guess it's possible)

Please Help,
Mark
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #2
It has been a while since I messed with OpenGL, but as far as I can tell you never create an OpenGL context. Needless to say, if that is the case then it is the cause of your crash. Wink
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #3
I don't know, but after a quick glance through your code I can see there are several problems with it -no context, no drawing loop!, etc. I would highly recommend going to http://nehe.gamedev.net/ and reading through some of the tutorials there. I think the first few are in Carbon so that should help out.
Quote this message in a reply
Marjock
Unregistered
 
Post: #4
and ah, how do you set up said OpenGL Context? I've been to NeHe but waht they tell you to do to set up a rendering context etc. doesn't work and is apparently PC code.

Also, this thread probably should've been started in the OpenGL forum, so sorry.

sorry for my n00bishness =)

-Mark
Quote this message in a reply
Moderator
Posts: 3,571
Joined: 2003.06
Post: #5
I just checked the NeHe code for you and it's either GLUT or Cocoa, although GLUT is Carbon. Go GLUT to begin with. You won't need to set up a context for GLUT since it handles that for you automatically. NeHe does indeed have most of the lessons downloadable for the Mac so don't be misled. You'll only have to read through minimal PC oriented tutorial stuff. The actual Mac download will contain the corrected code that you are interested in and you can extrapolate from there with relative ease. Here's the link to learn how to set up GLUT for OS X: http://nehe.gamedev.net/data/lessons/les...n=Mac_OS_X It's a little out of date but if you have any questions about it I'm sure someone can help you here. Be sure to look at the bottom of each lesson to find the relevent Mac code download.
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #6
Marjock Wrote:Also, this thread probably should've been started in the OpenGL forum, so sorry.
Good point. I have moved and renamed your thread for that reason.

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Marjock
Unregistered
 
Post: #7
Okay guys, thanks for all your help but I've decided to go in a slightly different direction. I'm going to like get a better grasp of C, then learn Cocoa, and then do OpenGL through that.

Well, that's this weeks plan, at least ^^

-Mark
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #8
Good plan. OpenGL programming is unlike other programming on OS X, because it has the tendency to freeze or kernel panic your entire machine. You also *have to* check your results on several different machines, because every video card renders a little bit differently. Get comfortable with regular programming first.
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #9
Very wise decision. Most people would just push on, copying other people's source instead of figuring out how and why it worked. You'll be much better off in the long run.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Setting OpenGL &amp; GLFW on my new mac! AdrianM 3 3,748 Oct 12, 2008 07:24 AM
Last Post: AdrianM
  Setting up OpenGL with toolchain MikeTV 0 1,722 Jul 22, 2008 09:44 PM
Last Post: MikeTV
  Setting Up An OpenGL project JohnDoe555 2 2,776 Sep 30, 2005 10:39 PM
Last Post: JohnDoe555
  tutorials for setting up a window in opengl cocoa vbuser1338 6 4,414 Mar 14, 2005 02:16 PM
Last Post: maaaaark
  Setting Far Cut Off Nick 2 2,440 Sep 7, 2004 05:57 PM
Last Post: Nick