Starting with OpenGL on MAC

Hi,
I just started with openGL on a MAC OS X Jaguar with Power Builder following the first tutorials found at nehe.gamedev.net … I just setted up my first window (seems to work buut white background… strange) … then I try to write the first shapes (White Triangle and Square) … and I got the same white window…

I was downloading the Mac OS X example and works but is written with Aple Script (i think) … my xperiencies before were on Visual C and on Linux as well… and i would like to know if is no way to write “standard” C code on MAC os X … i would like to have the code as much “portable” as possible…

somebody can give me a hand?

thanks,
edu.

OpenGL is not accessible from AppleScript, so I doubt that that’s the case.

It is perfectly possible to write standard C code on Mac OS X (of course). The GLUT ports of NeHe’s tutorials should work fine (give or take names of includes) on Mac OS X.

I don’t know what is exactly this code i downloaded (this works) … maybe is using a cocoa API? … i paste some code at the end of this message…

Anyway i was also updating to X11 beta3 but i still have problems… the code is compiling but i got always a blank screen window (in white color)…

OpenGL and GLUT frameworks are correctluy included in my project file… and of course, i have all the includes as is shown in the tutorial files… what can i do?

Here is some of the code i was downloading:

/* Lesson02Controller.m */

#import “Lesson02Controller.h”

@interface Lesson02Controller (InternalMethods)

  • (void) setupRenderTimer;
  • (void) updateGLView NSTimer *)timer;
  • (void) createFailed;
    @end

@implementation Lesson02Controller

  • (void) awakeFromNib
    {
    [ NSApp setDelegate:self ]; // We want delegate notifications
    renderTimer = nil;
    [ glWindow makeFirstResponder:self ];
    glView = [ [ Lesson02View alloc ] initWithFrame:[ glWindow frame ]
    colorBits:16 depthBits:16 fullscreen:FALSE ];
    if( glView != nil )
    {
    [ glWindow setContentView:glView ];
    [ glWindow makeKeyAndOrderFront:self ];
    [ self setupRenderTimer ];
    }
    else
    [ self createFailed ];
    }

/*

  • Setup timer to update the OpenGL view.
    */
  • (void) setupRenderTimer
    {
    NSTimeInterval timeInterval = 0.005;

    renderTimer = [ [ NSTimer scheduledTimerWithTimeInterval:timeInterval
    target:self
    selector:@selector( updateGLView: )
    userInfo:nil repeats:YES ] retain ];
    [ [ NSRunLoop currentRunLoop ] addTimer:renderTimer
    forMode:NSEventTrackingRunLoopMode ];
    [ [ NSRunLoop currentRunLoop ] addTimer:renderTimer
    forMode:NSModalPanelRunLoopMode ];
    }

/*

  • Called by the rendering timer.
    */
  • (void) updateGLView NSTimer *)timer
    {
    if( glView != nil )
    [ glView drawRect:[ glView frame ] ];
    }

/*

  • Handle key presses
    */
  • (void) keyDown NSEvent *)theEvent
    {
    unichar unicodeKey;

    unicodeKey = [ [ theEvent characters ] characterAtIndex:0 ];
    switch( unicodeKey )
    {
    // Handle key presses here
    }
    }

/*

  • Set full screen.
    */
  • (IBAction)setFullScreen id)sender
    {
    [ glWindow setContentView:nil ];
    if( [ glView isFullScreen ] )
    {
    if( ![ glView setFullScreen:FALSE inFrame:[ glWindow frame ] ] )
    [ self createFailed ];
    else
    [ glWindow setContentView:glView ];
    }
    else
    {
    if( ![ glView setFullScreen:TRUE
    inFrame:NSMakeRect( 0, 0, 800, 600 ) ] )
    [ self createFailed ];
    }
    }

/*

  • Called if we fail to create a valid OpenGL view
    */
  • (void) createFailed
    {
    NSWindow *infoWindow;

    infoWindow = NSGetCriticalAlertPanel( @“Initialization failed”,
    @“Failed to initialize OpenGL”,
    @“OK”, nil, nil );
    [ NSApp runModalForWindow:infoWindow ];
    [ infoWindow close ];
    [ NSApp terminate:self ];
    }

/*

  • Cleanup
    */
  • (void) dealloc
    {
    [ glWindow release ];
    [ glView release ];
    if( renderTimer != nil && [ renderTimer isValid ] )
    [ renderTimer invalidate ];
    }

@end

That is indeed Cocoa (written in Objective C). I suggest you get the GLUT ports of the tutorials and work through them instead.

GLUT, OpenGL & Cocoa don’t depend on X11 in any way. Upgrading it will have had no effect.

Do you have the .nib file in your project?

I’m not sure… I’m new in OS X and power builder… I think I have correctly linked both libs… but what is the .nib file? … what i should have there?

thanks a lot for your help.

The .nib file defines the user interface.

Just get the GLUT port of the tutorial and use that.

What do you mean with “GET the glut port” ?

I don’t know if I understand… I think I have a main.m file with the tutorial code (includding includes and defines)… and I have 3 frameworks setted up in my Project Builder Project (cocoa, OpenGL and GLUT)…

what should i write on the .nib file? … how i define the user interface?

thanks again for your help,
edu.

You should have downloaded the nib with the code, or followed the tutorial’s instructions on how to build it (one of those options).

In the list of ports at the bottom of the tutorial, there’s a link to the GLUT port as well as the cocoa port. Try that instead. You may need to change #include <GL/glut.h> to #include <GLUT/glut.h>, and #include <GL/gl.h> to #include <OpenGL/gl.h> to get it to compile. You’ll also need the GLUT, OpenGL and Cocoa frameworks.

i don’t know… i got back today to the first openGl tut, and i started again following step by step GLUT port definition in MAC OS X Project Builder, and I’m trying to create first shapes but same effect…

Code is compiling correctly, but I only got a white window when executing…

Could be something wrong in my system? …

these are my includes:

#include <OpenGL/gl.h> // Header File For The OpenGL32 Library
#include <OpenGL/glu.h> // Header File For The GLu32 Library
#include <GLUT/glut.h> // Header File For The GLut Library

and I have cocoa, GLUT and OpenGL frameworks installed…

A nib file was created by default when making “new project --> cocoa Application” as shown in first tutorial…

???

any idea? … the dev tools i installed are from Dec 2002 (last dev tools available in Mac developer member site) … and i was installing “project builder” separately as was explained in readme file…

Ok… works fine now… I was pasting a GLUT standard code and now it’s ok… it was any mistake in my includes and frameworks… so i guess was missing something in the code i was pasting from nehe’s websiite… (strange)

anyway, i think i can go on now with the rest of tutorials.

thanks for the help you was giving to me.
edu.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.