Here is some code that I used in a shipping game if it helps… if not maybe compare your code to this or any of the Apple OpenGL demos and see what you are doing differently
boolean gl_platform_initialize(
void)
{
boolean success= FALSE;
OSErr err= noErr;
AGLPixelFormat pixel_format;
GLint pixel_attributes_32bit=
{
AGL_ACCELERATED,
AGL_RGBA,
AGL_DOUBLEBUFFER,
AGL_DEPTH_SIZE,
32,
AGL_NONE
};
GLint pixel_attributes_16bit=
{
AGL_ACCELERATED,
AGL_RGBA,
AGL_DOUBLEBUFFER,
AGL_DEPTH_SIZE,
16,
AGL_NONE
};
static short window_width= 0;
static short window_height= 0;
static short window_depth= 0;
if (aglChoosePixelFormat == NULL)
{
message_box(“### requires OpenGL to run; please install OpenGL and try again.”);
exit(0);
}
if (original_display_width == 0)
{
boolean got_settings;
OSErr err= noErr;
unsigned long value= 0L;
// save initial display settings
got_settings= gl_get_current_display_setting(&original_display_width, &original_display_height, &original_display_depth);
startup_message("original display settings= %dx%dx%d : %s", original_display_width, original_display_height, original_display_depth,
(got_settings ? "SUCCESS" : "FAILED"));
err= DMGetDisplayMode(GetMainDevice(), &original_display_mode_info);
if (err != noErr)
{
startup_message("DMGetDisplayMode() returned err= %d", err);
}
}
assert(platform_data.game_window);
if (gl->context == NULL)
{
if (gl->bit_depth == 32)
{
pixel_format= aglChoosePixelFormat(NULL, 0, pixel_attributes_32bit);
}
else
{
pixel_format= aglChoosePixelFormat(NULL, 0, pixel_attributes_16bit);
}
if (pixel_format != NULL)
{
if (resolution_switch)
{
success= gl_change_display_setting(gl->width, gl->height, gl->bit_depth);
if (!success)
{
startup_message("changed display settings to: %dx%dx%d : FAILED", gl->width, gl->height, gl->bit_depth);
resolution_switch= FALSE;
success= TRUE;
}
else
{
startup_message("changed display settings to: %dx%dx%d : SUCCESS", gl->width, gl->height, gl->bit_depth);
}
}
else
{
success= TRUE;
}
if (success)
{
gl->context= aglCreateContext(pixel_format, NULL);
if (gl->context != NULL)
{
SizeWindow(platform_data.game_window, gl->width, gl->height, false);
success= aglSetDrawable((AGLContext)gl->context, GetWindowPort(platform_data.game_window));
if (success)
{
success= aglSetCurrentContext((AGLContext)gl->context);
aglDestroyPixelFormat(pixel_format);
window_width= gl->width;
window_height= gl->height;
window_depth= gl->bit_depth;
}
}
}
}
else // the app doesn't handle failure so we do it here
{
message_box("Unable to initialize OpenGL on your system; ### will now exit.");
exit(0);
}
}
…
if (success)
{
GLbyte *renderer_string, *vendor_string;
// punt if we end up in one of Apple's software renderers
renderer_string= GL_FXN(glGetString)(GL_RENDERER);
vendor_string= GL_FXN(glGetString)(GL_VENDOR);
if (renderer_string && vendor_string &&
(strstr(renderer_string, "APPLE") | | strstr(renderer_string, "Apple") | | strstr(renderer_string, "apple") | |
strstr(vendor_string, "APPLE") | | strstr(vendor_string, "Apple") | | strstr(vendor_string, "apple")))
{
message_box("Unable to initialize hardware accelerated OpenGL on your system with the current settings; ### will now exit.");
gl_platform_dispose();
exit(0);
}
// cursor won't stay hidden until we are done messing around with display settings
mac_hide_cursor();
}
return success;
}