diff --git a/CocoaGL.zip b/CocoaGL.zip new file mode 100644 index 00000000..cf0f1596 Binary files /dev/null and b/CocoaGL.zip differ diff --git a/CocoaGL/AppDelegate.h b/CocoaGL/AppDelegate.h new file mode 100644 index 00000000..83fabb03 --- /dev/null +++ b/CocoaGL/AppDelegate.h @@ -0,0 +1,56 @@ +// +// File: AppDelegate.h +// +// Abstract: Tells the application to quit once the main window closes +// +// Version: 1.0 - Original release. +// +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") +// in consideration of your agreement to the following terms, and your use, +// installation, modification or redistribution of this Apple software +// constitutes acceptance of these terms. If you do not agree with these +// terms, please do not use, install, modify or redistribute this Apple +// software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non - exclusive +// license, under Apple's copyrights in this original Apple software ( the +// "Apple Software" ), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and / or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following text +// and disclaimers in all such redistributions of the Apple Software. Neither +// the name, trademarks, service marks or logos of Apple Inc. may be used to +// endorse or promote products derived from the Apple Software without specific +// prior written permission from Apple. Except as expressly stated in this +// notice, no other rights or licenses, express or implied, are granted by +// Apple herein, including but not limited to any patent rights that may be +// infringed by your derivative works or by other works in which the Apple +// Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO +// WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED +// WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION +// ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +// CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION +// AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER +// UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR +// OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright ( C ) 2003-2007 Apple Inc. All Rights Reserved. +// + +#import + +@interface AppDelegate : NSObject +{ +} +- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication; + +@end diff --git a/CocoaGL/AppDelegate.m b/CocoaGL/AppDelegate.m new file mode 100644 index 00000000..3bfa23c1 --- /dev/null +++ b/CocoaGL/AppDelegate.m @@ -0,0 +1,59 @@ +// +// File: AppDelegate.m +// +// Abstract: Tells the application to quit once the main window closes +// +// Version: 1.0 - Original release. +// +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") +// in consideration of your agreement to the following terms, and your use, +// installation, modification or redistribution of this Apple software +// constitutes acceptance of these terms. If you do not agree with these +// terms, please do not use, install, modify or redistribute this Apple +// software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non - exclusive +// license, under Apple's copyrights in this original Apple software ( the +// "Apple Software" ), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and / or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following text +// and disclaimers in all such redistributions of the Apple Software. Neither +// the name, trademarks, service marks or logos of Apple Inc. may be used to +// endorse or promote products derived from the Apple Software without specific +// prior written permission from Apple. Except as expressly stated in this +// notice, no other rights or licenses, express or implied, are granted by +// Apple herein, including but not limited to any patent rights that may be +// infringed by your derivative works or by other works in which the Apple +// Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO +// WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED +// WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION +// ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +// CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION +// AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER +// UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR +// OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright ( C ) 2003-2007 Apple Inc. All Rights Reserved. +// + + +#import "AppDelegate.h" + +@implementation AppDelegate + +- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication +{ + return YES; +} + +@end diff --git a/CocoaGL/BasicOpenGLView.h b/CocoaGL/BasicOpenGLView.h new file mode 100755 index 00000000..fec22761 --- /dev/null +++ b/CocoaGL/BasicOpenGLView.h @@ -0,0 +1,151 @@ +// +// File: BasicOpenGLView.m +// +// Abstract: Basic OpenGL View with Renderer information +// +// Version: 1.1 - minor fixes. +// 1.0 - Original release. +// +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") +// in consideration of your agreement to the following terms, and your use, +// installation, modification or redistribution of this Apple software +// constitutes acceptance of these terms. If you do not agree with these +// terms, please do not use, install, modify or redistribute this Apple +// software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non - exclusive +// license, under Apple's copyrights in this original Apple software ( the +// "Apple Software" ), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and / or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following text +// and disclaimers in all such redistributions of the Apple Software. Neither +// the name, trademarks, service marks or logos of Apple Inc. may be used to +// endorse or promote products derived from the Apple Software without specific +// prior written permission from Apple. Except as expressly stated in this +// notice, no other rights or licenses, express or implied, are granted by +// Apple herein, including but not limited to any patent rights that may be +// infringed by your derivative works or by other works in which the Apple +// Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO +// WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED +// WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION +// ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +// CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION +// AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER +// UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR +// OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright ( C ) 2003-2007 Apple Inc. All Rights Reserved. +// + + +#import +#import +#import + +#import "GLString.h" + +typedef struct { + GLdouble x,y,z; +} recVec; + +typedef struct { + recVec viewPos; // View position + recVec viewDir; // View direction vector + recVec viewUp; // View up direction + recVec rotPoint; // Point to rotate about + GLdouble aperture; // pContextInfo->camera aperture + GLint viewWidth, viewHeight; // current window/screen height and width +} recCamera; + +@interface BasicOpenGLView : NSOpenGLView +{ + // string attributes + NSMutableDictionary * stanStringAttrib; + + // string textures + GLString * helpStringTex; + GLString * infoStringTex; + GLString * camStringTex; + GLString * capStringTex; + GLString * msgStringTex; + CFAbsoluteTime msgTime; // message posting time for expiration + + NSTimer* timer; + + bool fAnimate; + IBOutlet NSMenuItem * animateMenuItem; + bool fInfo; + IBOutlet NSMenuItem * infoMenuItem; + bool fDrawHelp; + bool fDrawCaps; + + CFAbsoluteTime time; + + // spin + GLfloat rRot [3]; + GLfloat rVel [3]; + GLfloat rAccel [3]; + + // camera handling + recCamera camera; + GLfloat worldRotation [4]; + GLfloat objectRotation [4]; + GLfloat shapeSize; + +} + ++ (NSOpenGLPixelFormat*) basicPixelFormat; + +- (void) updateProjection; +- (void) updateModelView; +- (void) resizeGL; +- (void) resetCamera; + +- (void) updateObjectRotationForTimeDelta:(CFAbsoluteTime)deltaTime; +- (void)animationTimer:(NSTimer *)timer; + +- (void) createHelpString; +- (void) createMessageString; +- (void) updateInfoString; +- (void) updateCameraString; +- (void) drawInfo; + +-(IBAction) animate: (id) sender; +-(IBAction) info: (id) sender; + +- (void)keyDown:(NSEvent *)theEvent; + +- (void) mouseDown:(NSEvent *)theEvent; +- (void) rightMouseDown:(NSEvent *)theEvent; +- (void) otherMouseDown:(NSEvent *)theEvent; +- (void) mouseUp:(NSEvent *)theEvent; +- (void) rightMouseUp:(NSEvent *)theEvent; +- (void) otherMouseUp:(NSEvent *)theEvent; +- (void) mouseDragged:(NSEvent *)theEvent; +- (void) scrollWheel:(NSEvent *)theEvent; +- (void) rightMouseDragged:(NSEvent *)theEvent; +- (void) otherMouseDragged:(NSEvent *)theEvent; + +- (void) drawRect:(NSRect)rect; + +- (void) prepareOpenGL; +- (void) update; // moved or resized + +- (BOOL) acceptsFirstResponder; +- (BOOL) becomeFirstResponder; +- (BOOL) resignFirstResponder; + +- (id) initWithFrame: (NSRect) frameRect; +- (void) awakeFromNib; + +@end diff --git a/CocoaGL/BasicOpenGLView.m b/CocoaGL/BasicOpenGLView.m new file mode 100755 index 00000000..750d8a07 --- /dev/null +++ b/CocoaGL/BasicOpenGLView.m @@ -0,0 +1,848 @@ +// +// File: BasicOpenGLView.m +// +// Abstract: Basic OpenGL View with Renderer information +// +// Version: 1.1 - minor fixes. +// 1.0 - Original release. +// +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") +// in consideration of your agreement to the following terms, and your use, +// installation, modification or redistribution of this Apple software +// constitutes acceptance of these terms. If you do not agree with these +// terms, please do not use, install, modify or redistribute this Apple +// software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non - exclusive +// license, under Apple's copyrights in this original Apple software ( the +// "Apple Software" ), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and / or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following text +// and disclaimers in all such redistributions of the Apple Software. Neither +// the name, trademarks, service marks or logos of Apple Inc. may be used to +// endorse or promote products derived from the Apple Software without specific +// prior written permission from Apple. Except as expressly stated in this +// notice, no other rights or licenses, express or implied, are granted by +// Apple herein, including but not limited to any patent rights that may be +// infringed by your derivative works or by other works in which the Apple +// Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO +// WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED +// WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION +// ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +// CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION +// AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER +// UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR +// OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright ( C ) 2003-2007 Apple Inc. All Rights Reserved. +// + +#import "BasicOpenGLView.h" +#import "GLCheck.h" +#import "trackball.h" +#import "drawinfo.h" + +// ================================== + +// simple cube data +GLint cube_num_vertices = 8; + +GLfloat cube_vertices [8][3] = { +{1.0, 1.0, 1.0}, {1.0, -1.0, 1.0}, {-1.0, -1.0, 1.0}, {-1.0, 1.0, 1.0}, +{1.0, 1.0, -1.0}, {1.0, -1.0, -1.0}, {-1.0, -1.0, -1.0}, {-1.0, 1.0, -1.0} }; + +GLfloat cube_vertex_colors [8][3] = { +{1.0, 1.0, 1.0}, {1.0, 1.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 1.0, 1.0}, +{1.0, 0.0, 1.0}, {1.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, 1.0} }; + +GLint num_faces = 6; + +short cube_faces [6][4] = { +{3, 2, 1, 0}, {2, 3, 7, 6}, {0, 1, 5, 4}, {3, 0, 4, 7}, {1, 2, 6, 5}, {4, 5, 6, 7} }; + +recVec gOrigin = {0.0, 0.0, 0.0}; + +// single set of interaction flags and states +GLint gDollyPanStartPoint[2] = {0, 0}; +GLfloat gTrackBallRotation [4] = {0.0f, 0.0f, 0.0f, 0.0f}; +GLboolean gDolly = GL_FALSE; +GLboolean gPan = GL_FALSE; +GLboolean gTrackball = GL_FALSE; +BasicOpenGLView * gTrackingViewInfo = NULL; + +// time and message info +CFAbsoluteTime gMsgPresistance = 10.0f; + +// error output +GLString * gErrStringTex; +float gErrorTime; + +// ================================== + +#pragma mark ---- OpenGL Capabilities ---- + +// GL configuration info globals +// see GLCheck.h for more info +GLCaps * gDisplayCaps = NULL; // array of GLCaps +CGDisplayCount gNumDisplays = 0; + +static void getCurrentCaps (void) +{ + // Check for existing opengl caps here + // This can be called again with same display caps array when display configurations are changed and + // your info needs to be updated. Note, if you are doing dynmaic allocation, the number of displays + // may change and thus you should always reallocate your display caps array. + if (gDisplayCaps && HaveOpenGLCapsChanged (gDisplayCaps, gNumDisplays)) { // see if caps have changed + free (gDisplayCaps); + gDisplayCaps = NULL; + } + if (!gDisplayCaps) { // if we do not have caps + CheckOpenGLCaps (0, NULL, &gNumDisplays); // will just update number of displays + gDisplayCaps = (GLCaps*) malloc (sizeof (GLCaps) * gNumDisplays); + CheckOpenGLCaps (gNumDisplays, gDisplayCaps, &gNumDisplays); + initCapsTexture (gDisplayCaps, gNumDisplays); // (re)init the texture for printing caps + } +} + +#pragma mark ---- Utilities ---- + +static CFAbsoluteTime gStartTime = 0.0f; + +// set app start time +static void setStartTime (void) +{ + gStartTime = CFAbsoluteTimeGetCurrent (); +} + +// --------------------------------- + +// return float elpased time in seconds since app start +static CFAbsoluteTime getElapsedTime (void) +{ + return CFAbsoluteTimeGetCurrent () - gStartTime; +} + +#pragma mark ---- Error Reporting ---- + +// error reporting as both window message and debugger string +void reportError (char * strError) +{ + NSMutableDictionary *attribs = [NSMutableDictionary dictionary]; + [attribs setObject: [NSFont fontWithName: @"Monaco" size: 9.0f] forKey: NSFontAttributeName]; + [attribs setObject: [NSColor whiteColor] forKey: NSForegroundColorAttributeName]; + + gErrorTime = getElapsedTime (); + NSString * errString = [NSString stringWithFormat:@"Error: %s (at time: %0.1f secs).", strError, gErrorTime]; + NSLog (@"%@\n", errString); + if (gErrStringTex) + [gErrStringTex setString:errString withAttributes:attribs]; + else { + gErrStringTex = [[GLString alloc] initWithString:errString withAttributes:attribs withTextColor:[NSColor colorWithDeviceRed:1.0f green:1.0f blue:1.0f alpha:1.0f] withBoxColor:[NSColor colorWithDeviceRed:1.0f green:0.0f blue:0.0f alpha:0.3f] withBorderColor:[NSColor colorWithDeviceRed:1.0f green:0.0f blue:0.0f alpha:0.8f]]; + } +} + +// --------------------------------- + +// if error dump gl errors to debugger string, return error +GLenum glReportError (void) +{ + GLenum err = glGetError(); + if (GL_NO_ERROR != err) + reportError ((char *) gluErrorString (err)); + return err; +} + +#pragma mark ---- OpenGL Utils ---- + +// --------------------------------- + +// draw our simple cube based on current modelview and projection matrices +static void drawCube (GLfloat fSize) +{ + long f, i; + if (1) { + glColor3f (1.0, 0.5, 0.0); + glBegin (GL_QUADS); + for (f = 0; f < num_faces; f++) + for (i = 0; i < 4; i++) { + glColor3f (cube_vertex_colors[cube_faces[f][i]][0], cube_vertex_colors[cube_faces[f][i]][1], cube_vertex_colors[cube_faces[f][i]][2]); + glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize); + } + glEnd (); + } + if (1) { + glColor3f (0.0, 0.0, 0.0); + for (f = 0; f < num_faces; f++) { + glBegin (GL_LINE_LOOP); + for (i = 0; i < 4; i++) + glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize); + glEnd (); + } + } +} + +// =================================== + +@implementation BasicOpenGLView + +// pixel format definition ++ (NSOpenGLPixelFormat*) basicPixelFormat +{ + NSOpenGLPixelFormatAttribute attributes [] = { + NSOpenGLPFAWindow, + NSOpenGLPFADoubleBuffer, // double buffered + NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)16, // 16 bit depth buffer + (NSOpenGLPixelFormatAttribute)nil + }; + return [[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] autorelease]; +} + +// --------------------------------- + +// update the projection matrix based on camera and view info +- (void) updateProjection +{ + GLdouble ratio, radians, wd2; + GLdouble left, right, top, bottom, near, far; + + [[self openGLContext] makeCurrentContext]; + + // set projection + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + near = -camera.viewPos.z - shapeSize * 0.5; + if (near < 0.00001) + near = 0.00001; + far = -camera.viewPos.z + shapeSize * 0.5; + if (far < 1.0) + far = 1.0; + radians = 0.0174532925 * camera.aperture / 2; // half aperture degrees to radians + wd2 = near * tan(radians); + ratio = camera.viewWidth / (float) camera.viewHeight; + if (ratio >= 1.0) { + left = -ratio * wd2; + right = ratio * wd2; + top = wd2; + bottom = -wd2; + } else { + left = -wd2; + right = wd2; + top = wd2 / ratio; + bottom = -wd2 / ratio; + } + glFrustum (left, right, bottom, top, near, far); + [self updateCameraString]; +} + +// --------------------------------- + +// updates the contexts model view matrix for object and camera moves +- (void) updateModelView +{ + [[self openGLContext] makeCurrentContext]; + + // move view + glMatrixMode (GL_MODELVIEW); + glLoadIdentity (); + gluLookAt (camera.viewPos.x, camera.viewPos.y, camera.viewPos.z, + camera.viewPos.x + camera.viewDir.x, + camera.viewPos.y + camera.viewDir.y, + camera.viewPos.z + camera.viewDir.z, + camera.viewUp.x, camera.viewUp.y ,camera.viewUp.z); + + // if we have trackball rotation to map (this IS the test I want as it can be explicitly 0.0f) + if ((gTrackingViewInfo == self) && gTrackBallRotation[0] != 0.0f) + glRotatef (gTrackBallRotation[0], gTrackBallRotation[1], gTrackBallRotation[2], gTrackBallRotation[3]); + else { + } + // accumlated world rotation via trackball + glRotatef (worldRotation[0], worldRotation[1], worldRotation[2], worldRotation[3]); + // object itself rotating applied after camera rotation + glRotatef (objectRotation[0], objectRotation[1], objectRotation[2], objectRotation[3]); + rRot[0] = 0.0f; // reset animation rotations (do in all cases to prevent rotating while moving with trackball) + rRot[1] = 0.0f; + rRot[2] = 0.0f; + [self updateCameraString]; +} + +// --------------------------------- + +// handles resizing of GL need context update and if the window dimensions change, a +// a window dimension update, reseting of viewport and an update of the projection matrix +- (void) resizeGL +{ + NSRect rectView = [self bounds]; + + // ensure camera knows size changed + if ((camera.viewHeight != rectView.size.height) || + (camera.viewWidth != rectView.size.width)) { + camera.viewHeight = rectView.size.height; + camera.viewWidth = rectView.size.width; + + glViewport (0, 0, camera.viewWidth, camera.viewHeight); + [self updateProjection]; // update projection matrix + [self updateInfoString]; + } +} + +// --------------------------------- + +// move camera in z axis +-(void)mouseDolly: (NSPoint) location +{ + GLfloat dolly = (gDollyPanStartPoint[1] -location.y) * -camera.viewPos.z / 300.0f; + camera.viewPos.z += dolly; + if (camera.viewPos.z == 0.0) // do not let z = 0.0 + camera.viewPos.z = 0.0001; + gDollyPanStartPoint[0] = location.x; + gDollyPanStartPoint[1] = location.y; +} + +// --------------------------------- + +// move camera in x/y plane +- (void)mousePan: (NSPoint) location +{ + GLfloat panX = (gDollyPanStartPoint[0] - location.x) / (900.0f / -camera.viewPos.z); + GLfloat panY = (gDollyPanStartPoint[1] - location.y) / (900.0f / -camera.viewPos.z); + camera.viewPos.x -= panX; + camera.viewPos.y -= panY; + gDollyPanStartPoint[0] = location.x; + gDollyPanStartPoint[1] = location.y; +} + +// --------------------------------- + +// sets the camera data to initial conditions +- (void) resetCamera +{ + camera.aperture = 40; + camera.rotPoint = gOrigin; + + camera.viewPos.x = 0.0; + camera.viewPos.y = 0.0; + camera.viewPos.z = -10.0; + camera.viewDir.x = -camera.viewPos.x; + camera.viewDir.y = -camera.viewPos.y; + camera.viewDir.z = -camera.viewPos.z; + + camera.viewUp.x = 0; + camera.viewUp.y = 1; + camera.viewUp.z = 0; +} + +// --------------------------------- + +// given a delta time in seconds and current rotation accel, velocity and position, update overall object rotation +- (void) updateObjectRotationForTimeDelta:(CFAbsoluteTime)deltaTime +{ + // update rotation based on vel and accel + float rotation[4] = {0.0f, 0.0f, 0.0f, 0.0f}; + GLfloat fVMax = 2.0; + short i; + // do velocities + for (i = 0; i < 3; i++) { + rVel[i] += rAccel[i] * deltaTime * 30.0; + + if (rVel[i] > fVMax) { + rAccel[i] *= -1.0; + rVel[i] = fVMax; + } else if (rVel[i] < -fVMax) { + rAccel[i] *= -1.0; + rVel[i] = -fVMax; + } + + rRot[i] += rVel[i] * deltaTime * 30.0; + + while (rRot[i] > 360.0) + rRot[i] -= 360.0; + while (rRot[i] < -360.0) + rRot[i] += 360.0; + } + rotation[0] = rRot[0]; + rotation[1] = 1.0f; + addToRotationTrackball (rotation, objectRotation); + rotation[0] = rRot[1]; + rotation[1] = 0.0f; rotation[2] = 1.0f; + addToRotationTrackball (rotation, objectRotation); + rotation[0] = rRot[2]; + rotation[2] = 0.0f; rotation[3] = 1.0f; + addToRotationTrackball (rotation, objectRotation); +} + +// --------------------------------- + +// per-window timer function, basic time based animation preformed here +- (void)animationTimer:(NSTimer *)timer +{ + BOOL shouldDraw = NO; + if (fAnimate) { + CFTimeInterval deltaTime = CFAbsoluteTimeGetCurrent () - time; + + if (deltaTime > 10.0) // skip pauses + return; + else { + // if we are not rotating with trackball in this window + if (!gTrackball || (gTrackingViewInfo != self)) { + [self updateObjectRotationForTimeDelta: deltaTime]; // update object rotation + } + shouldDraw = YES; // force redraw + } + } + time = CFAbsoluteTimeGetCurrent (); //reset time in all cases + // if we have current messages + if (((getElapsedTime () - msgTime) < gMsgPresistance) || ((getElapsedTime () - gErrorTime) < gMsgPresistance)) + shouldDraw = YES; // force redraw + if (YES == shouldDraw) + [self drawRect:[self bounds]]; // redraw now instead dirty to enable updates during live resize +} + +#pragma mark ---- Text Drawing ---- + +// these functions create or update GLStrings one should expect to have to regenerate the image, bitmap and texture when the string changes thus these functions are not particularly light weight + +- (void) updateInfoString +{ // update info string texture + NSString * string = [NSString stringWithFormat:@"(%0.0f x %0.0f) \n%s \n%s", [self bounds].size.width, [self bounds].size.height, glGetString (GL_RENDERER), glGetString (GL_VERSION)]; + if (infoStringTex) + [infoStringTex setString:string withAttributes:stanStringAttrib]; + else { + infoStringTex = [[GLString alloc] initWithString:string withAttributes:stanStringAttrib withTextColor:[NSColor colorWithDeviceRed:1.0f green:1.0f blue:1.0f alpha:1.0f] withBoxColor:[NSColor colorWithDeviceRed:0.5f green:0.5f blue:0.5f alpha:0.5f] withBorderColor:[NSColor colorWithDeviceRed:0.8f green:0.8f blue:0.8f alpha:0.8f]]; + } +} + +// --------------------------------- + +- (void) createHelpString +{ + NSString * string = [NSString stringWithFormat:@"Cmd-A: animate Cmd-I: show info \n'h': toggle help 'c': toggle OpenGL caps"]; + helpStringTex = [[GLString alloc] initWithString:string withAttributes:stanStringAttrib withTextColor:[NSColor colorWithDeviceRed:1.0f green:1.0f blue:1.0f alpha:1.0f] withBoxColor:[NSColor colorWithDeviceRed:0.0f green:0.5f blue:0.0f alpha:0.5f] withBorderColor:[NSColor colorWithDeviceRed:0.3f green:0.8f blue:0.3f alpha:0.8f]]; +} + +// --------------------------------- + +- (void) createMessageString +{ + NSString * string = [NSString stringWithFormat:@"No messages..."]; + msgStringTex = [[GLString alloc] initWithString:string withAttributes:stanStringAttrib withTextColor:[NSColor colorWithDeviceRed:1.0f green:1.0f blue:1.0f alpha:1.0f] withBoxColor:[NSColor colorWithDeviceRed:0.5f green:0.5f blue:0.5f alpha:0.5f] withBorderColor:[NSColor colorWithDeviceRed:0.8f green:0.8f blue:0.8f alpha:0.8f]]; +} + +// --------------------------------- + +- (void) updateCameraString +{ // update info string texture + static recCamera savedCamera; + + // This is a compromise between a heavy comparison + // and updating the camera texture when not needed + // what is faster the comparison or the texture update + // only empirical data on a particular configuration + // will yield a real answer + + if ( (savedCamera.viewPos.x == camera.viewPos.x) && + (savedCamera.viewPos.y == camera.viewPos.y) && + (savedCamera.viewPos.z == camera.viewPos.z) && + (savedCamera.viewDir.x == camera.viewDir.x) && + (savedCamera.viewDir.y == camera.viewDir.y) && + (savedCamera.viewDir.z == camera.viewDir.z) && + (savedCamera.aperture == camera.aperture) ) + { + return; // Don't update texture! (which usually is more expensive than the comparison above) + } else { + NSString * string = [NSString stringWithFormat:@"Camera at (%0.1f, %0.1f, %0.1f) looking at (%0.1f, %0.1f, %0.1f) with %0.1f aperture", camera.viewPos.x, camera.viewPos.y, camera.viewPos.z, camera.viewDir.x, camera.viewDir.y, camera.viewDir.z, camera.aperture]; + if (camStringTex) + [camStringTex setString:string withAttributes:stanStringAttrib]; + else { + camStringTex = [[GLString alloc] initWithString:string withAttributes:stanStringAttrib withTextColor:[NSColor colorWithDeviceRed:1.0f green:1.0f blue:1.0f alpha:1.0f] withBoxColor:[NSColor colorWithDeviceRed:0.5f green:0.5f blue:0.5f alpha:0.5f] withBorderColor:[NSColor colorWithDeviceRed:0.8f green:0.8f blue:0.8f alpha:0.8f]]; + } + } + + savedCamera = camera; +} + +// --------------------------------- + +// draw text info using our GLString class for much more optimized text drawing +- (void) drawInfo +{ + GLint matrixMode; + GLboolean depthTest = glIsEnabled (GL_DEPTH_TEST); + GLfloat height, width, messageTop = 10.0f; + + height = camera.viewHeight; + width = camera.viewWidth; + + // set orthograhic 1:1 pixel transform in local view coords + glGetIntegerv (GL_MATRIX_MODE, &matrixMode); + glMatrixMode (GL_PROJECTION); + glPushMatrix(); + glLoadIdentity (); + glMatrixMode (GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity (); + glScalef (2.0f / width, -2.0f / height, 1.0f); + glTranslatef (-width / 2.0f, -height / 2.0f, 0.0f); + + glColor4f (1.0f, 1.0f, 1.0f, 1.0f); + [infoStringTex drawAtPoint:NSMakePoint (10.0f, height - [infoStringTex frameSize].height - 10.0f)]; + [camStringTex drawAtPoint:NSMakePoint (10.0f, messageTop)]; + messageTop += [camStringTex frameSize].height + 3.0f; + + if (fDrawHelp) + [helpStringTex drawAtPoint:NSMakePoint (floor ((width - [helpStringTex frameSize].width) / 2.0f), floor ((height - [helpStringTex frameSize].height) / 3.0f))]; + + if (fDrawCaps) { + long renderer; + [[self pixelFormat] getValues:&renderer forAttribute:NSOpenGLPFARendererID forVirtualScreen:[[self openGLContext] currentVirtualScreen]]; + drawCaps (gDisplayCaps, gNumDisplays, renderer, width); + } + + // message string + float currTime = getElapsedTime (); + if ((currTime - msgTime) < gMsgPresistance) { + GLfloat comp = (gMsgPresistance - getElapsedTime () + msgTime) * 0.1; // premultiplied fade + glColor4f (comp, comp, comp, comp); + [msgStringTex drawAtPoint:NSMakePoint (10.0f, messageTop)]; + messageTop += [msgStringTex frameSize].height + 3.0f; + } + // global error message + if ((currTime - gErrorTime) < gMsgPresistance) { + GLfloat comp = (gMsgPresistance - getElapsedTime () + gErrorTime) * 0.1; // premultiplied fade + glColor4f (comp, comp, comp, comp); + [gErrStringTex drawAtPoint:NSMakePoint (10.0f, messageTop)]; + } + + // reset orginal martices + glPopMatrix(); // GL_MODELVIEW + glMatrixMode (GL_PROJECTION); + glPopMatrix(); + glMatrixMode (matrixMode); + + glDisable (GL_TEXTURE_RECTANGLE_EXT); + glDisable (GL_BLEND); + if (depthTest) + glEnable (GL_DEPTH_TEST); + glReportError (); +} + +#pragma mark ---- IB Actions ---- + +-(IBAction) animate: (id) sender +{ + fAnimate = 1 - fAnimate; + if (fAnimate) + [animateMenuItem setState: NSOnState]; + else + [animateMenuItem setState: NSOffState]; +} + +// --------------------------------- + +-(IBAction) info: (id) sender +{ + fInfo = 1 - fInfo; + if (fInfo) + [infoMenuItem setState: NSOnState]; + else + [infoMenuItem setState: NSOffState]; + [self setNeedsDisplay: YES]; +} + +#pragma mark ---- Method Overrides ---- + +-(void)keyDown:(NSEvent *)theEvent +{ + NSString *characters = [theEvent characters]; + if ([characters length]) { + unichar character = [characters characterAtIndex:0]; + switch (character) { + case 'h': + // toggle help + fDrawHelp = 1 - fDrawHelp; + [self setNeedsDisplay: YES]; + break; + case 'c': + // toggle caps + fDrawCaps = 1 - fDrawCaps; + [self setNeedsDisplay: YES]; + break; + } + } +} + +// --------------------------------- + +- (void)mouseDown:(NSEvent *)theEvent // trackball +{ + if ([theEvent modifierFlags] & NSControlKeyMask) // send to pan + [self rightMouseDown:theEvent]; + else if ([theEvent modifierFlags] & NSAlternateKeyMask) // send to dolly + [self otherMouseDown:theEvent]; + else { + NSPoint location = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + location.y = camera.viewHeight - location.y; + gDolly = GL_FALSE; // no dolly + gPan = GL_FALSE; // no pan + gTrackball = GL_TRUE; + startTrackball (location.x, location.y, 0, 0, camera.viewWidth, camera.viewHeight); + gTrackingViewInfo = self; + } +} + +// --------------------------------- + +- (void)rightMouseDown:(NSEvent *)theEvent // pan +{ + NSPoint location = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + location.y = camera.viewHeight - location.y; + if (gTrackball) { // if we are currently tracking, end trackball + if (gTrackBallRotation[0] != 0.0) + addToRotationTrackball (gTrackBallRotation, worldRotation); + gTrackBallRotation [0] = gTrackBallRotation [1] = gTrackBallRotation [2] = gTrackBallRotation [3] = 0.0f; + } + gDolly = GL_FALSE; // no dolly + gPan = GL_TRUE; + gTrackball = GL_FALSE; // no trackball + gDollyPanStartPoint[0] = location.x; + gDollyPanStartPoint[1] = location.y; + gTrackingViewInfo = self; +} + +// --------------------------------- + +- (void)otherMouseDown:(NSEvent *)theEvent //dolly +{ + NSPoint location = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + location.y = camera.viewHeight - location.y; + if (gTrackball) { // if we are currently tracking, end trackball + if (gTrackBallRotation[0] != 0.0) + addToRotationTrackball (gTrackBallRotation, worldRotation); + gTrackBallRotation [0] = gTrackBallRotation [1] = gTrackBallRotation [2] = gTrackBallRotation [3] = 0.0f; + } + gDolly = GL_TRUE; + gPan = GL_FALSE; // no pan + gTrackball = GL_FALSE; // no trackball + gDollyPanStartPoint[0] = location.x; + gDollyPanStartPoint[1] = location.y; + gTrackingViewInfo = self; +} + +// --------------------------------- + +- (void)mouseUp:(NSEvent *)theEvent +{ + if (gDolly) { // end dolly + gDolly = GL_FALSE; + } else if (gPan) { // end pan + gPan = GL_FALSE; + } else if (gTrackball) { // end trackball + gTrackball = GL_FALSE; + if (gTrackBallRotation[0] != 0.0) + addToRotationTrackball (gTrackBallRotation, worldRotation); + gTrackBallRotation [0] = gTrackBallRotation [1] = gTrackBallRotation [2] = gTrackBallRotation [3] = 0.0f; + } + gTrackingViewInfo = NULL; +} + +// --------------------------------- + +- (void)rightMouseUp:(NSEvent *)theEvent +{ + [self mouseUp:theEvent]; +} + +// --------------------------------- + +- (void)otherMouseUp:(NSEvent *)theEvent +{ + [self mouseUp:theEvent]; +} + +// --------------------------------- + +- (void)mouseDragged:(NSEvent *)theEvent +{ + NSPoint location = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + location.y = camera.viewHeight - location.y; + if (gTrackball) { + rollToTrackball (location.x, location.y, gTrackBallRotation); + [self setNeedsDisplay: YES]; + } else if (gDolly) { + [self mouseDolly: location]; + [self updateProjection]; // update projection matrix (not normally done on draw) + [self setNeedsDisplay: YES]; + } else if (gPan) { + [self mousePan: location]; + [self setNeedsDisplay: YES]; + } +} + +// --------------------------------- + +- (void)scrollWheel:(NSEvent *)theEvent +{ + float wheelDelta = [theEvent deltaX] +[theEvent deltaY] + [theEvent deltaZ]; + if (wheelDelta) + { + GLfloat deltaAperture = wheelDelta * -camera.aperture / 200.0f; + camera.aperture += deltaAperture; + if (camera.aperture < 0.1) // do not let aperture <= 0.1 + camera.aperture = 0.1; + if (camera.aperture > 179.9) // do not let aperture >= 180 + camera.aperture = 179.9; + [self updateProjection]; // update projection matrix + [self setNeedsDisplay: YES]; + } +} + +// --------------------------------- + +- (void)rightMouseDragged:(NSEvent *)theEvent +{ + [self mouseDragged: theEvent]; +} + +// --------------------------------- + +- (void)otherMouseDragged:(NSEvent *)theEvent +{ + [self mouseDragged: theEvent]; +} + +// --------------------------------- + +- (void) drawRect:(NSRect)rect +{ + // setup viewport and prespective + [self resizeGL]; // forces projection matrix update (does test for size changes) + [self updateModelView]; // update model view matrix for object + + // clear our drawable + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + // model view and projection matricies already set + + drawCube (1.5f); // draw scene + if (fInfo) + [self drawInfo]; + + if ([self inLiveResize] && !fAnimate) + glFlush (); + else + [[self openGLContext] flushBuffer]; + glReportError (); +} + +// --------------------------------- + +// set initial OpenGL state (current context is set) +// called after context is created +- (void) prepareOpenGL +{ + long swapInt = 1; + + [[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; // set to vbl sync + + // init GL stuff here + glEnable(GL_DEPTH_TEST); + + glShadeModel(GL_SMOOTH); + glEnable(GL_CULL_FACE); + glFrontFace(GL_CCW); + glPolygonOffset (1.0f, 1.0f); + + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + [self resetCamera]; + shapeSize = 7.0f; // max radius of of objects + + // init fonts for use with strings + NSFont * font =[NSFont fontWithName:@"Helvetica" size:12.0]; + stanStringAttrib = [[NSMutableDictionary dictionary] retain]; + [stanStringAttrib setObject:font forKey:NSFontAttributeName]; + [stanStringAttrib setObject:[NSColor whiteColor] forKey:NSForegroundColorAttributeName]; + [font release]; + + // ensure strings are created + [self createHelpString]; + [self createMessageString]; + +} +// --------------------------------- + +// this can be a troublesome call to do anything heavyweight, as it is called on window moves, resizes, and display config changes. So be +// careful of doing too much here. +- (void) update // window resizes, moves and display changes (resize, depth and display config change) +{ +msgTime = getElapsedTime (); +[msgStringTex setString:[NSString stringWithFormat:@"update at %0.1f secs", msgTime] withAttributes:stanStringAttrib]; + [super update]; + if (![self inLiveResize]) {// if not doing live resize + [self updateInfoString]; // to get change in renderers will rebuld string every time (could test for early out) + getCurrentCaps (); // this call checks to see if the current config changed in a reasonably lightweight way to prevent expensive re-allocations + } +} + +// --------------------------------- + +-(id) initWithFrame: (NSRect) frameRect +{ + NSOpenGLPixelFormat * pf = [BasicOpenGLView basicPixelFormat]; + + self = [super initWithFrame: frameRect pixelFormat: pf]; + return self; +} + +// --------------------------------- + +- (BOOL)acceptsFirstResponder +{ + return YES; +} + +// --------------------------------- + +- (BOOL)becomeFirstResponder +{ + return YES; +} + +// --------------------------------- + +- (BOOL)resignFirstResponder +{ + return YES; +} + +// --------------------------------- + +- (void) awakeFromNib +{ + setStartTime (); // get app start time + getCurrentCaps (); // get current GL capabilites for all displays + + // set start values... + rVel[0] = 0.3; rVel[1] = 0.1; rVel[2] = 0.2; + rAccel[0] = 0.003; rAccel[1] = -0.005; rAccel[2] = 0.004; + fInfo = 1; + fAnimate = 1; + time = CFAbsoluteTimeGetCurrent (); // set animation time start time + fDrawHelp = 1; + + // start animation timer + timer = [NSTimer timerWithTimeInterval:(1.0f/60.0f) target:self selector:@selector(animationTimer:) userInfo:nil repeats:YES]; + [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode]; + [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode]; // ensure timer fires during resize +} + + +@end diff --git a/CocoaGL/Cocoa GL.icns b/CocoaGL/Cocoa GL.icns new file mode 100644 index 00000000..0b0f4ac2 Binary files /dev/null and b/CocoaGL/Cocoa GL.icns differ diff --git a/CocoaGL/Cocoa OpenGL.app/Contents/Info.plist b/CocoaGL/Cocoa OpenGL.app/Contents/Info.plist new file mode 100644 index 00000000..1b7be725 --- /dev/null +++ b/CocoaGL/Cocoa OpenGL.app/Contents/Info.plist @@ -0,0 +1,28 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + Cocoa OpenGL + CFBundleIconFile + Cocoa GL + CFBundleIdentifier + com.apple.Cocoa OpenGL + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + Cocoa OpenGL + CFBundlePackageType + APPL + CFBundleSignature + ???? + CFBundleVersion + 1.1 + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/CocoaGL/Cocoa OpenGL.app/Contents/MacOS/Cocoa OpenGL b/CocoaGL/Cocoa OpenGL.app/Contents/MacOS/Cocoa OpenGL new file mode 100755 index 00000000..c0d4b650 Binary files /dev/null and b/CocoaGL/Cocoa OpenGL.app/Contents/MacOS/Cocoa OpenGL differ diff --git a/CocoaGL/Cocoa OpenGL.app/Contents/PkgInfo b/CocoaGL/Cocoa OpenGL.app/Contents/PkgInfo new file mode 100644 index 00000000..bd04210f --- /dev/null +++ b/CocoaGL/Cocoa OpenGL.app/Contents/PkgInfo @@ -0,0 +1 @@ +APPL???? \ No newline at end of file diff --git a/CocoaGL/Cocoa OpenGL.app/Contents/Resources/Cocoa GL.icns b/CocoaGL/Cocoa OpenGL.app/Contents/Resources/Cocoa GL.icns new file mode 100644 index 00000000..0b0f4ac2 Binary files /dev/null and b/CocoaGL/Cocoa OpenGL.app/Contents/Resources/Cocoa GL.icns differ diff --git a/CocoaGL/Cocoa OpenGL.app/Contents/Resources/Credits.rtf b/CocoaGL/Cocoa OpenGL.app/Contents/Resources/Credits.rtf new file mode 100644 index 00000000..3d844718 --- /dev/null +++ b/CocoaGL/Cocoa OpenGL.app/Contents/Resources/Credits.rtf @@ -0,0 +1,7 @@ +{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf420 +{\fonttbl\f0\fswiss\fcharset77 Helvetica;} +{\colortbl;\red255\green255\blue255;} +\margl1440\margr1440\vieww9000\viewh8400\viewkind0 +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural +{\field{\*\fldinst{HYPERLINK "http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/"}}{\fldrslt +\f0\fs24 \cf0 OpenGL Programming Guide for Mac OS X}}} \ No newline at end of file diff --git a/CocoaGL/Cocoa OpenGL.app/Contents/Resources/English.lproj/InfoPlist.strings b/CocoaGL/Cocoa OpenGL.app/Contents/Resources/English.lproj/InfoPlist.strings new file mode 100644 index 00000000..97e75150 Binary files /dev/null and b/CocoaGL/Cocoa OpenGL.app/Contents/Resources/English.lproj/InfoPlist.strings differ diff --git a/CocoaGL/Cocoa OpenGL.app/Contents/Resources/English.lproj/MainMenu.nib/classes.nib b/CocoaGL/Cocoa OpenGL.app/Contents/Resources/English.lproj/MainMenu.nib/classes.nib new file mode 100644 index 00000000..b6bcfe04 --- /dev/null +++ b/CocoaGL/Cocoa OpenGL.app/Contents/Resources/English.lproj/MainMenu.nib/classes.nib @@ -0,0 +1,49 @@ + + + + + IBClasses + + + CLASS + AppDelegate + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + ACTIONS + + animate + id + info + id + + CLASS + BasicOpenGLView + LANGUAGE + ObjC + OUTLETS + + animateMenuItem + NSMenuItem + infoMenuItem + NSMenuItem + + SUPERCLASS + NSOpenGLView + + + IBVersion + 1 + + diff --git a/CocoaGL/Cocoa OpenGL.app/Contents/Resources/English.lproj/MainMenu.nib/info.nib b/CocoaGL/Cocoa OpenGL.app/Contents/Resources/English.lproj/MainMenu.nib/info.nib new file mode 100644 index 00000000..ce0e4237 --- /dev/null +++ b/CocoaGL/Cocoa OpenGL.app/Contents/Resources/English.lproj/MainMenu.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 629 + IBLastKnownRelativeProjectPath + ../../Cocoa OpenGL.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 21 + + IBSystem Version + 9A581 + targetFramework + IBCocoaFramework + + diff --git a/CocoaGL/Cocoa OpenGL.app/Contents/Resources/English.lproj/MainMenu.nib/keyedobjects.nib b/CocoaGL/Cocoa OpenGL.app/Contents/Resources/English.lproj/MainMenu.nib/keyedobjects.nib new file mode 100644 index 00000000..9e73461f Binary files /dev/null and b/CocoaGL/Cocoa OpenGL.app/Contents/Resources/English.lproj/MainMenu.nib/keyedobjects.nib differ diff --git a/CocoaGL/Cocoa OpenGL.xcodeproj/project.pbxproj b/CocoaGL/Cocoa OpenGL.xcodeproj/project.pbxproj new file mode 100644 index 00000000..ebaa0c8b --- /dev/null +++ b/CocoaGL/Cocoa OpenGL.xcodeproj/project.pbxproj @@ -0,0 +1,349 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 42; + objects = { + +/* Begin PBXBuildFile section */ + 740959030CC8255A00261DBF /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 740959010CC8255A00261DBF /* AppDelegate.m */; }; + 7409592A0CC826D800261DBF /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 740959290CC826D800261DBF /* Credits.rtf */; }; + 745217950CA98A790067AF41 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 745217940CA98A790067AF41 /* OpenGL.framework */; }; + 745217CB0CA98B160067AF41 /* drawInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 74F0EC600CA98A08009E924F /* drawInfo.m */; }; + 745217CC0CA98B160067AF41 /* GLCheck.c in Sources */ = {isa = PBXBuildFile; fileRef = 74F0EC5F0CA98A08009E924F /* GLCheck.c */; }; + 745217CD0CA98B160067AF41 /* GLString.m in Sources */ = {isa = PBXBuildFile; fileRef = 74F0EC690CA98A30009E924F /* GLString.m */; }; + 745217CE0CA98B160067AF41 /* trackball.c in Sources */ = {isa = PBXBuildFile; fileRef = 74F0EC6C0CA98A30009E924F /* trackball.c */; }; + 74A064910CC824A500C5C702 /* Cocoa GL.icns in Resources */ = {isa = PBXBuildFile; fileRef = 74A064900CC824A500C5C702 /* Cocoa GL.icns */; }; + 74F0EC5D0CA989F9009E924F /* BasicOpenGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = 74F0EC5B0CA989F9009E924F /* BasicOpenGLView.m */; }; + 8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; }; + 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; }; + 8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; }; + 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; }; + 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; + 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 29B97319FDCFA39411CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MainMenu.nib; sourceTree = ""; }; + 32CA4F630368D1EE00C91783 /* Cocoa OpenGL_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Cocoa OpenGL_Prefix.pch"; sourceTree = ""; }; + 740959010CC8255A00261DBF /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 740959020CC8255A00261DBF /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 740959290CC826D800261DBF /* Credits.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = ""; }; + 7439218A0CC944C3009BCC59 /* ReadMe.rtfd */ = {isa = PBXFileReference; lastKnownFileType = wrapper.rtfd; path = ReadMe.rtfd; sourceTree = ""; }; + 745217940CA98A790067AF41 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = /System/Library/Frameworks/OpenGL.framework; sourceTree = ""; }; + 74A064900CC824A500C5C702 /* Cocoa GL.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = "Cocoa GL.icns"; sourceTree = ""; }; + 74F0EC5B0CA989F9009E924F /* BasicOpenGLView.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = BasicOpenGLView.m; sourceTree = ""; }; + 74F0EC5C0CA989F9009E924F /* BasicOpenGLView.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = BasicOpenGLView.h; sourceTree = ""; }; + 74F0EC5E0CA98A08009E924F /* drawInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = drawInfo.h; sourceTree = ""; }; + 74F0EC5F0CA98A08009E924F /* GLCheck.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = GLCheck.c; sourceTree = ""; }; + 74F0EC600CA98A08009E924F /* drawInfo.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = drawInfo.m; sourceTree = ""; }; + 74F0EC610CA98A08009E924F /* GLCheck.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GLCheck.h; sourceTree = ""; }; + 74F0EC690CA98A30009E924F /* GLString.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GLString.m; sourceTree = ""; }; + 74F0EC6A0CA98A30009E924F /* GLString.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GLString.h; sourceTree = ""; }; + 74F0EC6B0CA98A30009E924F /* trackball.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = trackball.h; sourceTree = ""; }; + 74F0EC6C0CA98A30009E924F /* trackball.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = trackball.c; sourceTree = ""; }; + 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; + 8D1107320486CEB800E47090 /* Cocoa OpenGL.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Cocoa OpenGL.app"; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 8D11072E0486CEB800E47090 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */, + 745217950CA98A790067AF41 /* OpenGL.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 080E96DDFE201D6D7F000001 /* Classes */ = { + isa = PBXGroup; + children = ( + 74E01FB50CAC4E510030A4D8 /* GL Utilities */, + 74F0EC5B0CA989F9009E924F /* BasicOpenGLView.m */, + 74F0EC5C0CA989F9009E924F /* BasicOpenGLView.h */, + ); + name = Classes; + sourceTree = ""; + }; + 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = { + isa = PBXGroup; + children = ( + 745217940CA98A790067AF41 /* OpenGL.framework */, + 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */, + ); + name = "Linked Frameworks"; + sourceTree = ""; + }; + 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = "Other Frameworks"; + sourceTree = ""; + }; + 19C28FACFE9D520D11CA2CBB /* Products */ = { + isa = PBXGroup; + children = ( + 8D1107320486CEB800E47090 /* Cocoa OpenGL.app */, + ); + name = Products; + sourceTree = ""; + }; + 29B97314FDCFA39411CA2CEA /* Cocoa OpenGL */ = { + isa = PBXGroup; + children = ( + 7439218A0CC944C3009BCC59 /* ReadMe.rtfd */, + 080E96DDFE201D6D7F000001 /* Classes */, + 29B97315FDCFA39411CA2CEA /* Other Sources */, + 29B97317FDCFA39411CA2CEA /* Resources */, + 29B97323FDCFA39411CA2CEA /* Frameworks */, + 19C28FACFE9D520D11CA2CBB /* Products */, + ); + name = "Cocoa OpenGL"; + sourceTree = ""; + }; + 29B97315FDCFA39411CA2CEA /* Other Sources */ = { + isa = PBXGroup; + children = ( + 740959010CC8255A00261DBF /* AppDelegate.m */, + 740959020CC8255A00261DBF /* AppDelegate.h */, + 32CA4F630368D1EE00C91783 /* Cocoa OpenGL_Prefix.pch */, + 29B97316FDCFA39411CA2CEA /* main.m */, + ); + name = "Other Sources"; + sourceTree = ""; + }; + 29B97317FDCFA39411CA2CEA /* Resources */ = { + isa = PBXGroup; + children = ( + 740959290CC826D800261DBF /* Credits.rtf */, + 74A064900CC824A500C5C702 /* Cocoa GL.icns */, + 8D1107310486CEB800E47090 /* Info.plist */, + 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */, + 29B97318FDCFA39411CA2CEA /* MainMenu.nib */, + ); + name = Resources; + sourceTree = ""; + }; + 29B97323FDCFA39411CA2CEA /* Frameworks */ = { + isa = PBXGroup; + children = ( + 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */, + 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */, + ); + name = Frameworks; + sourceTree = ""; + }; + 74E01FB50CAC4E510030A4D8 /* GL Utilities */ = { + isa = PBXGroup; + children = ( + 74F0EC5E0CA98A08009E924F /* drawInfo.h */, + 74F0EC600CA98A08009E924F /* drawInfo.m */, + 74F0EC6B0CA98A30009E924F /* trackball.h */, + 74F0EC6C0CA98A30009E924F /* trackball.c */, + 74F0EC690CA98A30009E924F /* GLString.m */, + 74F0EC6A0CA98A30009E924F /* GLString.h */, + 74F0EC5F0CA98A08009E924F /* GLCheck.c */, + 74F0EC610CA98A08009E924F /* GLCheck.h */, + ); + name = "GL Utilities"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 8D1107260486CEB800E47090 /* Cocoa OpenGL */ = { + isa = PBXNativeTarget; + buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "Cocoa OpenGL" */; + buildPhases = ( + 8D1107290486CEB800E47090 /* Resources */, + 8D11072C0486CEB800E47090 /* Sources */, + 8D11072E0486CEB800E47090 /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "Cocoa OpenGL"; + productInstallPath = "$(HOME)/Applications"; + productName = "Cocoa OpenGL"; + productReference = 8D1107320486CEB800E47090 /* Cocoa OpenGL.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 29B97313FDCFA39411CA2CEA /* Project object */ = { + isa = PBXProject; + buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "Cocoa OpenGL" */; + compatibilityVersion = "Xcode 2.4"; + hasScannedForEncodings = 1; + mainGroup = 29B97314FDCFA39411CA2CEA /* Cocoa OpenGL */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 8D1107260486CEB800E47090 /* Cocoa OpenGL */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 8D1107290486CEB800E47090 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */, + 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */, + 74A064910CC824A500C5C702 /* Cocoa GL.icns in Resources */, + 7409592A0CC826D800261DBF /* Credits.rtf in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 8D11072C0486CEB800E47090 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 745217CB0CA98B160067AF41 /* drawInfo.m in Sources */, + 745217CC0CA98B160067AF41 /* GLCheck.c in Sources */, + 745217CD0CA98B160067AF41 /* GLString.m in Sources */, + 745217CE0CA98B160067AF41 /* trackball.c in Sources */, + 8D11072D0486CEB800E47090 /* main.m in Sources */, + 74F0EC5D0CA989F9009E924F /* BasicOpenGLView.m in Sources */, + 740959030CC8255A00261DBF /* AppDelegate.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + 089C165DFE840E0CC02AAC07 /* English */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; + 29B97318FDCFA39411CA2CEA /* MainMenu.nib */ = { + isa = PBXVariantGroup; + children = ( + 29B97319FDCFA39411CA2CEA /* English */, + ); + name = MainMenu.nib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + C01FCF4B08A954540054247B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COPY_PHASE_STRIP = NO; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_FIX_AND_CONTINUE = YES; + GCC_MODEL_TUNING = G5; + GCC_OPTIMIZATION_LEVEL = 0; + INFOPLIST_FILE = Info.plist; + INSTALL_PATH = "$(HOME)/Applications"; + PRODUCT_NAME = "Cocoa OpenGL"; + WRAPPER_EXTENSION = app; + ZERO_LINK = YES; + }; + name = Debug; + }; + C01FCF4C08A954540054247B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = ( + ppc, + i386, + ); + GCC_GENERATE_DEBUGGING_SYMBOLS = NO; + GCC_MODEL_TUNING = G5; + INFOPLIST_FILE = Info.plist; + INSTALL_PATH = "$(HOME)/Applications"; + PRODUCT_NAME = "Cocoa OpenGL"; + WRAPPER_EXTENSION = app; + }; + name = Release; + }; + C01FCF4F08A954540054247B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS = NO; + GCC_WARN_MISSING_PARENTHESES = NO; + GCC_WARN_PEDANTIC = NO; + GCC_WARN_SHADOW = NO; + GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNKNOWN_PRAGMAS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_LABEL = YES; + GCC_WARN_UNUSED_PARAMETER = NO; + GCC_WARN_UNUSED_VALUE = YES; + GCC_WARN_UNUSED_VARIABLE = NO; + PREBINDING = NO; + SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk; + }; + name = Debug; + }; + C01FCF5008A954540054247B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = ( + ppc, + i386, + ); + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS = NO; + GCC_WARN_MISSING_PARENTHESES = NO; + GCC_WARN_PEDANTIC = NO; + GCC_WARN_SHADOW = NO; + GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNKNOWN_PRAGMAS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_LABEL = YES; + GCC_WARN_UNUSED_PARAMETER = NO; + GCC_WARN_UNUSED_VALUE = YES; + GCC_WARN_UNUSED_VARIABLE = NO; + PREBINDING = NO; + SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "Cocoa OpenGL" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C01FCF4B08A954540054247B /* Debug */, + C01FCF4C08A954540054247B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + C01FCF4E08A954540054247B /* Build configuration list for PBXProject "Cocoa OpenGL" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C01FCF4F08A954540054247B /* Debug */, + C01FCF5008A954540054247B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 29B97313FDCFA39411CA2CEA /* Project object */; +} diff --git a/CocoaGL/Cocoa OpenGL_Prefix.pch b/CocoaGL/Cocoa OpenGL_Prefix.pch new file mode 100644 index 00000000..58d07a15 --- /dev/null +++ b/CocoaGL/Cocoa OpenGL_Prefix.pch @@ -0,0 +1,7 @@ +// +// Prefix header for all source files of the 'Cocoa OpenGL' target in the 'Cocoa OpenGL' project +// + +#ifdef __OBJC__ + #import +#endif diff --git a/CocoaGL/Credits.rtf b/CocoaGL/Credits.rtf new file mode 100644 index 00000000..3d844718 --- /dev/null +++ b/CocoaGL/Credits.rtf @@ -0,0 +1,7 @@ +{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf420 +{\fonttbl\f0\fswiss\fcharset77 Helvetica;} +{\colortbl;\red255\green255\blue255;} +\margl1440\margr1440\vieww9000\viewh8400\viewkind0 +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural +{\field{\*\fldinst{HYPERLINK "http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/"}}{\fldrslt +\f0\fs24 \cf0 OpenGL Programming Guide for Mac OS X}}} \ No newline at end of file diff --git a/CocoaGL/English.lproj/InfoPlist.strings b/CocoaGL/English.lproj/InfoPlist.strings new file mode 100644 index 00000000..97e75150 Binary files /dev/null and b/CocoaGL/English.lproj/InfoPlist.strings differ diff --git a/CocoaGL/English.lproj/MainMenu.nib/classes.nib b/CocoaGL/English.lproj/MainMenu.nib/classes.nib new file mode 100644 index 00000000..b6bcfe04 --- /dev/null +++ b/CocoaGL/English.lproj/MainMenu.nib/classes.nib @@ -0,0 +1,49 @@ + + + + + IBClasses + + + CLASS + AppDelegate + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + CLASS + FirstResponder + LANGUAGE + ObjC + SUPERCLASS + NSObject + + + ACTIONS + + animate + id + info + id + + CLASS + BasicOpenGLView + LANGUAGE + ObjC + OUTLETS + + animateMenuItem + NSMenuItem + infoMenuItem + NSMenuItem + + SUPERCLASS + NSOpenGLView + + + IBVersion + 1 + + diff --git a/CocoaGL/English.lproj/MainMenu.nib/info.nib b/CocoaGL/English.lproj/MainMenu.nib/info.nib new file mode 100644 index 00000000..ce0e4237 --- /dev/null +++ b/CocoaGL/English.lproj/MainMenu.nib/info.nib @@ -0,0 +1,20 @@ + + + + + IBFramework Version + 629 + IBLastKnownRelativeProjectPath + ../../Cocoa OpenGL.xcodeproj + IBOldestOS + 5 + IBOpenObjects + + 21 + + IBSystem Version + 9A581 + targetFramework + IBCocoaFramework + + diff --git a/CocoaGL/English.lproj/MainMenu.nib/keyedobjects.nib b/CocoaGL/English.lproj/MainMenu.nib/keyedobjects.nib new file mode 100644 index 00000000..9e73461f Binary files /dev/null and b/CocoaGL/English.lproj/MainMenu.nib/keyedobjects.nib differ diff --git a/CocoaGL/GLCheck.c b/CocoaGL/GLCheck.c new file mode 100755 index 00000000..8d69fed3 --- /dev/null +++ b/CocoaGL/GLCheck.c @@ -0,0 +1,647 @@ +// +// File: GLCheck.c +// (Originally glCheck.c) +// +// Abstract: glcheck allows developer to check the hardware capabilities of all GPU's +// returning an array of records reflecting the attached hardware. This +// list can be regenerated on Display Manager notifications to keep the +// client update to on capabilities and setup changes. This is provided as +// sample to allow developers the freedom to check as few or as many +// conditions and capabilities as they would like or add their own checks +// +// Version: 1.1 - Removed QD dependencies, list of extensions +// 1.0 - Original release. +// +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") +// in consideration of your agreement to the following terms, and your use, +// installation, modification or redistribution of this Apple software +// constitutes acceptance of these terms. If you do not agree with these +// terms, please do not use, install, modify or redistribute this Apple +// software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non - exclusive +// license, under Apple's copyrights in this original Apple software ( the +// "Apple Software" ), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and / or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following text +// and disclaimers in all such redistributions of the Apple Software. Neither +// the name, trademarks, service marks or logos of Apple Inc. may be used to +// endorse or promote products derived from the Apple Software without specific +// prior written permission from Apple. Except as expressly stated in this +// notice, no other rights or licenses, express or implied, are granted by +// Apple herein, including but not limited to any patent rights that may be +// infringed by your derivative works or by other works in which the Apple +// Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO +// WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED +// WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION +// ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +// CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION +// AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER +// UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR +// OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright ( C ) 2003-2007 Apple Inc. All Rights Reserved. +// + +// see glcheck.h for more explanation on the use of CheckOpenGLCaps and it's associated data + + +#include "GLCheck.h" + +#include +#include +#include +#include + +#include + +// ------------------------- + +// local CF dictionary routines + +static long _getDictLong (CFDictionaryRef refDict, CFStringRef key) +{ + long int_value; + CFNumberRef num_value = (CFNumberRef)CFDictionaryGetValue(refDict, key); + if (!num_value) // if can't get a number for the dictionary + return -1; // fail + // or if cant convert it + if (!CFNumberGetValue(num_value, kCFNumberLongType, &int_value)) + return -1; // fail + return int_value; // otherwise return the long value +} + +static double _getDictDouble (CFDictionaryRef refDict, CFStringRef key) +{ + double double_value; + CFNumberRef num_value = (CFNumberRef)CFDictionaryGetValue(refDict, key); + if (!num_value) // if can't get a number for the dictionary + return -1; // fail + // or if cant convert it + if (!CFNumberGetValue(num_value, kCFNumberDoubleType, &double_value)) + return -1; // fail + return double_value; // otherwise return the long value +} + +// ------------------------- + +// this does a reasonable check to see if things have changed without being +// too heavy weight; returns 1 if changed 0 if not +// checks num displays, displayID, displayMask, each display geometry and +// renderer VRAM and ID + +unsigned char HaveOpenGLCapsChanged (GLCaps aDisplayCaps[], + CGDisplayCount dspyCnt) +{ + CGDisplayCount maxDisplays = 32; + CGDirectDisplayID activeDspys[32]; + CGDisplayErr theError; + short i; + CGDisplayCount newDspyCnt = 0; + + if (NULL == aDisplayCaps) return 1; + + theError = CGGetActiveDisplayList(maxDisplays, activeDspys, &newDspyCnt); + // if theError getting list mark as changed + if (theError) return 1; + // if number of displays not equal + if (dspyCnt != newDspyCnt) return 1; + + for (i = 0; i < dspyCnt; i++) { + // get device ids + if (aDisplayCaps[i].cgDisplayID != activeDspys[i]) return 1; + if (aDisplayCaps[i].cglDisplayMask != + CGDisplayIDToOpenGLDisplayMask(activeDspys[i])) return 1; + + // get current geometry + { + CGRect displayRect = CGDisplayBounds (activeDspys[i]); + // get mode dictionary + CFDictionaryRef dispMode = CGDisplayCurrentMode (activeDspys[i]); + // check for all geometry matches + if (aDisplayCaps[i].deviceWidth != (long) displayRect.size.width) + return 1; + if (aDisplayCaps[i].deviceHeight != (long) displayRect.size.height) + return 1; + if (aDisplayCaps[i].deviceOriginX != (long) displayRect.origin.x) + return 1; + if (aDisplayCaps[i].deviceOriginY != (long) displayRect.origin.y) + return 1; + if (aDisplayCaps[i].deviceDepth != + (short) _getDictLong (dispMode, kCGDisplayBitsPerPixel)) + return 1; + if (aDisplayCaps[i].deviceRefresh != + (short)(_getDictDouble (dispMode, kCGDisplayRefreshRate) + 0.5)) + return 1; // round to GLint + } + + // get renderer info based on gDevice + { + CGLRendererInfoObj info; + long j, numRenderers = 0, rv = 0; + CGLError theErr = 0; + long deviceVRAM; // video memory in bytes + unsigned long rendererID; // renderer ID + + theErr = CGLQueryRendererInfo (aDisplayCaps[i].cglDisplayMask, + &info, &numRenderers); + if(0 == theErr) { + CGLDescribeRenderer (info, 0, kCGLRPRendererCount, &numRenderers); + for (j = 0; j < numRenderers; j++) { + // find accelerated renderer (assume only one) + CGLDescribeRenderer (info, j, kCGLRPAccelerated, &rv); + if (true == rv) { // if accelerated + // what is the renderer ID + CGLDescribeRenderer (info, j, kCGLRPRendererID, (long *)&rendererID); + if (rendererID != aDisplayCaps[i].rendererID) // check match + return 1; + // what is the VRAM + CGLDescribeRenderer (info, j, kCGLRPVideoMemory, &deviceVRAM); + if (deviceVRAM != aDisplayCaps[i].deviceVRAM) // check match + return 1; + break; // done + } + } + } + CGLDestroyRendererInfo (info); + } + } + return 0; +} + +// ------------------------- + +// This will walk all active displays and gather information about their +// hardware renderer + +// An array length (maxDisplays) and array of GLCaps are passed in. Up to +// maxDisplays of the array are filled in with the displays meeting the +// specified criteria. The actual number of displays filled in is returned +// in dspyCnt. Calling this function with maxDisplays of 0 will just +// return the number of displays in dspyCnt. + +// Developers should note this is NOT an exhaustive list of all the +// capabilities one could query, nor a required set of capabilities, +// feel free to add or subtract queries as you find helpful for your +// application/use. + +// one note on mirrored displays... if the display configuration is +// changed it is possible (and likely) that the current active display +// in a mirrored configuration (as identified by the OpenGL Display Mask) +// will change if the mirrored display is removed. +// This is due to the preference of selection the external display as +// the active display. This may affect full screen apps which should +// always detect display configuration changes and respond accordingly. + +void CheckOpenGLCaps (CGDisplayCount maxDspys, + GLCaps dCaps[], + CGDisplayCount * dCnt) +{ + CGLContextObj curr_ctx = 0; + CGDirectDisplayID dspys[32]; + CGDisplayErr theErr; + short i; + short size = sizeof (GLCaps); + + // no devices + *dCnt = 0; + + if (maxDspys == 0) { // find number of displays + *dCnt = 0; + theErr = CGGetActiveDisplayList (32, dspys, dCnt); + if (theErr) // theErr getting list + *dCnt = 0; // 0 displays since can't correctly find any + // zero list to ensure the routines are used correctly + memset (dspys, 0, sizeof (CGDirectDisplayID) * *dCnt); + return; // return dCnt + } + if (NULL == dCaps) return; + + theErr = CGGetActiveDisplayList(maxDspys, dspys, dCnt); + if (theErr) return; // theErr getting list + if (0 == *dCnt) return; // no displays + + memset (dCaps, 0, size * *dCnt); // zero memory + + for (i = 0; i < *dCnt; i++) { + // get device ids + dCaps[i].cgDisplayID = dspys[i]; + dCaps[i].cglDisplayMask = CGDisplayIDToOpenGLDisplayMask(dspys[i]); + + { // get current geometry + CGRect displayRect = CGDisplayBounds (dspys[i]); + // get mode dictionary + CFDictionaryRef dispMode = CGDisplayCurrentMode (dspys[i]); + dCaps[i].deviceWidth = (long) displayRect.size.width; + dCaps[i].deviceHeight = (long) displayRect.size.height; + dCaps[i].deviceOriginX = (long) displayRect.origin.x; + dCaps[i].deviceOriginY = (long) displayRect.origin.y; + dCaps[i].deviceDepth = (short) _getDictLong (dispMode, + kCGDisplayBitsPerPixel); + dCaps[i].deviceRefresh = (short) (_getDictDouble (dispMode, + kCGDisplayRefreshRate) + 0.5); + } + + { // get renderer info based on gDevice + CGLRendererInfoObj info; + long j, numRenderers = 0, rv = 0; + CGLError theErr2 = 0; + + theErr2 = CGLQueryRendererInfo (dCaps[i].cglDisplayMask, + &info, + &numRenderers); + if(0 == theErr2) { + CGLDescribeRenderer (info, 0, kCGLRPRendererCount, &numRenderers); + for (j = 0; j < numRenderers; j++) { + // find accelerated renderer (assume only one) + CGLDescribeRenderer (info, j, kCGLRPAccelerated, &rv); + if (true == rv) { // if accelerated + // what is the renderer ID + CGLDescribeRenderer (info, j, kCGLRPRendererID, + &dCaps[i].rendererID); + // can we do full screen? + CGLDescribeRenderer (info, j, kCGLRPFullScreen, &rv); + dCaps[i].fullScreenCapable = (bool) rv; + // what is the VRAM? + CGLDescribeRenderer (info, j, kCGLRPVideoMemory, + &dCaps[i].deviceVRAM); + // what is the current texture memory? + CGLDescribeRenderer (info, j, kCGLRPTextureMemory, + &dCaps[i].deviceTextureRAM); + break; // done + } + } + } + CGLDestroyRendererInfo (info); + } + + { // build context and context specific info + CGLPixelFormatAttribute attribs[] = { kCGLPFADisplayMask, + dCaps[i].cglDisplayMask, + (CGLPixelFormatAttribute)0 }; + CGLPixelFormatObj pixelFormat = NULL; + long numPixelFormats = 0; + CGLContextObj cglContext; + + curr_ctx = CGLGetCurrentContext (); // get current CGL context + CGLChoosePixelFormat (attribs, &pixelFormat, &numPixelFormats); + if (pixelFormat) { + CGLCreateContext(pixelFormat, NULL, &cglContext); + CGLDestroyPixelFormat (pixelFormat); + CGLSetCurrentContext (cglContext); + if (cglContext) { + const GLubyte * strExt; + const GLubyte * strRend; + const GLubyte * strVers; + const GLubyte * strVend; + + // get renderer strings + strRend = glGetString (GL_RENDERER); + strncpy (dCaps[i].strRendererName, (char *) strRend, 255); + strVend = glGetString (GL_VENDOR); + strncpy (dCaps[i].strRendererVendor, (char *) strVend, 255); + strVers = glGetString (GL_VERSION); + strncpy (dCaps[i].strRendererVersion, (char *) strVers, 255); + { // get BCD version + short j = 0; + short shiftVal = 8; + while (((strVers[j] <= '9') && (strVers[j] >= '0')) || + (strVers[j] == '.')) { + // get only basic version info (until first non-digit or non-.) + if ((strVers[j] <= '9') && (strVers[j] >= '0')) { + dCaps[i].glVersion += (strVers[j] - '0') << shiftVal; + shiftVal -= 4; + } + j++; + } + } + strExt = glGetString (GL_EXTENSIONS); + + // get caps + glGetIntegerv (GL_MAX_TEXTURE_UNITS, + &dCaps[i].textureUnits); + glGetIntegerv (GL_MAX_TEXTURE_SIZE, + &dCaps[i].maxTextureSize); + glGetIntegerv (GL_MAX_3D_TEXTURE_SIZE, + &dCaps[i].max3DTextureSize); + glGetIntegerv (GL_MAX_CUBE_MAP_TEXTURE_SIZE, + &dCaps[i].maxCubeMapTextureSize); + + // get functionality info + dCaps[i].fSpecularVector = + gluCheckExtension ((const GLubyte *) "GL_APPLE_specular_vector", strExt); + dCaps[i].fTransformHint = + gluCheckExtension ((const GLubyte *) "GL_APPLE_transform_hint", strExt); + dCaps[i].fPackedPixels = + gluCheckExtension ((const GLubyte *) "GL_APPLE_packed_pixels", strExt) || + gluCheckExtension ((const GLubyte *) "GL_APPLE_packed_pixel", strExt) || + (dCaps[i].glVersion >= 0x0120); + dCaps[i].fClientStorage = + gluCheckExtension ((const GLubyte *) "GL_APPLE_client_storage", strExt); + dCaps[i].fYCbCr = + gluCheckExtension ((const GLubyte *) "GL_APPLE_ycbcr_422", strExt); + dCaps[i].fTextureRange = + gluCheckExtension ((const GLubyte *) "GL_APPLE_texture_range", strExt); + dCaps[i].fFence = + gluCheckExtension ((const GLubyte *) "GL_APPLE_fence", strExt); + dCaps[i].fVAR = + gluCheckExtension ((const GLubyte *) "GL_APPLE_vertex_array_range", strExt); + dCaps[i].fVAO = + gluCheckExtension ((const GLubyte *) "GL_APPLE_vertex_array_object", strExt); + dCaps[i].fElementArray = + gluCheckExtension ((const GLubyte *) "GL_APPLE_element_array", strExt); + dCaps[i].fVPEvals = + gluCheckExtension ((const GLubyte *) "GL_APPLE_vertex_program_evaluators",strExt); + dCaps[i].fFloatPixels = + gluCheckExtension ((const GLubyte *) "GL_APPLE_float_pixels", strExt); + dCaps[i].fFlushRenderer = + gluCheckExtension ((const GLubyte *) "GL_APPLE_flush_render", strExt); + dCaps[i].fPixelBuffer = + gluCheckExtension ((const GLubyte *) "GL_APPLE_pixel_buffer", strExt); + dCaps[i].fImaging = + gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt); + dCaps[i].fTransposeMatrix = + gluCheckExtension ((const GLubyte *) "GL_ARB_transpose_matrix", strExt) || + (dCaps[i].glVersion >= 0x0130); + dCaps[i].fMultitexture = + gluCheckExtension ((const GLubyte *) "GL_ARB_multitexture", strExt) || + (dCaps[i].glVersion >= 0x0130); + dCaps[i].fTexEnvAdd = + gluCheckExtension ((const GLubyte *) "GL_ARB_texture_env_add", strExt) || + gluCheckExtension ((const GLubyte *) "GL_EXT_texture_env_add", strExt) || + (dCaps[i].glVersion >= 0x0130); + dCaps[i].fTexEnvCombine = + gluCheckExtension ((const GLubyte *) "GL_ARB_texture_env_combine", strExt) || + (dCaps[i].glVersion >= 0x0130); + dCaps[i].fTexEnvDot3 = + gluCheckExtension ((const GLubyte *) "GL_ARB_texture_env_dot3", strExt) || + (dCaps[i].glVersion >= 0x0130); + dCaps[i].fTexEnvCrossbar = + gluCheckExtension ((const GLubyte *) "GL_ARB_texture_env_crossbar", strExt) || + (dCaps[i].glVersion >= 0x0140); + dCaps[i].fTexCubeMap = + gluCheckExtension ((const GLubyte *) "GL_ARB_texture_cube_map", strExt) || + (dCaps[i].glVersion >= 0x0130); + dCaps[i].fTexCompress = + gluCheckExtension ((const GLubyte *) "GL_ARB_texture_compression", strExt) || + (dCaps[i].glVersion >= 0x0130); + dCaps[i].fMultisample = + gluCheckExtension ((const GLubyte *) "GL_ARB_multisample", strExt) || + (dCaps[i].glVersion >= 0x0130); + dCaps[i].fTexBorderClamp = + gluCheckExtension ((const GLubyte *) "GL_ARB_texture_border_clamp", strExt) || + (dCaps[i].glVersion >= 0x0130); + dCaps[i].fPointParam = + gluCheckExtension ((const GLubyte *) "GL_ARB_point_parameters", strExt) || + (dCaps[i].glVersion >= 0x0140); + dCaps[i].fVertexProg = + gluCheckExtension ((const GLubyte *) "GL_ARB_vertex_program", strExt); + dCaps[i].fFragmentProg = + gluCheckExtension ((const GLubyte *) "GL_ARB_fragment_program", strExt); + dCaps[i].fTexMirrorRepeat = + gluCheckExtension ((const GLubyte *) "GL_ARB_texture_mirrored_repeat", strExt) || + (dCaps[i].glVersion >= 0x0140); + dCaps[i].fDepthTex = + gluCheckExtension ((const GLubyte *) "GL_ARB_depth_texture", strExt) || + (dCaps[i].glVersion >= 0x0140); + dCaps[i].fShadow = + gluCheckExtension ((const GLubyte *) "GL_ARB_shadow", strExt) || + (dCaps[i].glVersion >= 0x0140); + dCaps[i].fShadowAmbient = + gluCheckExtension ((const GLubyte *) "GL_ARB_shadow_ambient", strExt); + dCaps[i].fVertexBlend = + gluCheckExtension ((const GLubyte *) "GL_ARB_vertex_blend", strExt); + dCaps[i].fWindowPos = + gluCheckExtension ((const GLubyte *) "GL_ARB_window_pos", strExt) || + (dCaps[i].glVersion >= 0x0140); + dCaps[i].fTex3D = + gluCheckExtension ((const GLubyte *) "GL_EXT_texture3D", strExt) || + (dCaps[i].glVersion >= 0x0120); + dCaps[i].fClipVolHint = + gluCheckExtension ((const GLubyte *) "GL_EXT_clip_volume_hint", strExt); + dCaps[i].fRescaleNorm = + gluCheckExtension ((const GLubyte *) "GL_EXT_rescale_normal", strExt) || + (dCaps[i].glVersion >= 0x0120); + dCaps[i].fBlendColor = + gluCheckExtension ((const GLubyte *) "GL_EXT_blend_color", strExt) || + gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt); + dCaps[i].fBlendMinMax = + gluCheckExtension ((const GLubyte *) "GL_EXT_blend_minmax", strExt) || + gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt); + dCaps[i].fBlendSub = + gluCheckExtension ((const GLubyte *) "GL_EXT_blend_subtract", strExt) || + gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt); + dCaps[i].fCVA = + gluCheckExtension ((const GLubyte *) "GL_EXT_compiled_vertex_array", strExt); + dCaps[i].fTexLODBias = + gluCheckExtension ((const GLubyte *) "GL_EXT_texture_lod_bias", strExt) || + (dCaps[i].glVersion >= 0x0140); + dCaps[i].fABGR = + gluCheckExtension ((const GLubyte *) "GL_EXT_abgr", strExt); + dCaps[i].fBGRA = + gluCheckExtension ((const GLubyte *) "GL_EXT_bgra", strExt) || + (dCaps[i].glVersion >= 0x0120); + dCaps[i].fTexFilterAniso = + gluCheckExtension ((const GLubyte *) "GL_EXT_texture_filter_anisotropic",strExt); + dCaps[i].fPaletteTex = + gluCheckExtension ((const GLubyte *) "GL_EXT_paletted_texture", strExt); + dCaps[i].fShareTexPalette = + gluCheckExtension ((const GLubyte *) "GL_EXT_shared_texture_palette", strExt); + dCaps[i].fSecColor = + gluCheckExtension ((const GLubyte *) "GL_EXT_secondary_color", strExt) || + (dCaps[i].glVersion >= 0x0140); + dCaps[i].fTexCompressS3TC = + gluCheckExtension ((const GLubyte *) "GL_EXT_texture_compression_s3tc", strExt); + dCaps[i].fTexRect = + gluCheckExtension ((const GLubyte *) "GL_EXT_texture_rectangle", strExt); + dCaps[i].fFogCoord = + gluCheckExtension ((const GLubyte *) "GL_EXT_fog_coord", strExt); + dCaps[i].fDrawRangeElements = + gluCheckExtension ((const GLubyte *) "GL_EXT_draw_range_elements", strExt); + dCaps[i].fStencilWrap = + gluCheckExtension ((const GLubyte *) "GL_EXT_stencil_wrap", strExt) || + (dCaps[i].glVersion >= 0x0140); + dCaps[i].fBlendFuncSep = + gluCheckExtension ((const GLubyte *) "GL_EXT_blend_func_separate", strExt) || + (dCaps[i].glVersion >= 0x0140); + dCaps[i].fMultiDrawArrays = + gluCheckExtension ((const GLubyte *) "GL_EXT_multi_draw_arrays", strExt) || + (dCaps[i].glVersion >= 0x0140); + dCaps[i].fShadowFunc = + gluCheckExtension ((const GLubyte *) "GL_EXT_shadow_funcs", strExt); + dCaps[i].fStencil2Side = + gluCheckExtension ((const GLubyte *) "GL_EXT_stencil_two_side", strExt) || + (dCaps[i].glVersion >= 0x0140); + dCaps[i].fColorSubtable = + gluCheckExtension ((const GLubyte *) "GL_EXT_color_subtable", strExt) || + gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt); + dCaps[i].fConvolution = + gluCheckExtension ((const GLubyte *) "GL_EXT_convolution", strExt) || + gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt); + dCaps[i].fHistogram = + gluCheckExtension ((const GLubyte *) "GL_EXT_histogram", strExt) || + gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt); + dCaps[i].fColorTable = + gluCheckExtension ((const GLubyte *) "GL_SGI_color_table", strExt) || + gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt); + dCaps[i].fColorMatrix = + gluCheckExtension ((const GLubyte *) "GL_SGI_color_matrix", strExt) || + gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt); + dCaps[i].fTexEdgeClamp = + gluCheckExtension ((const GLubyte *) "GL_SGIS_texture_edge_clamp", strExt) || + (dCaps[i].glVersion >= 0x0120); + dCaps[i].fGenMipmap = + gluCheckExtension ((const GLubyte *) "GL_SGIS_generate_mipmap", strExt); + dCaps[i].fTexLOD = + gluCheckExtension ((const GLubyte *) "GL_SGIS_texture_lod", strExt) || + (dCaps[i].glVersion >= 0x0120); + dCaps[i].fPointCull = + gluCheckExtension ((const GLubyte *) "GL_ATI_point_cull_mode", strExt); + dCaps[i].fTexMirrorOnce = + gluCheckExtension ((const GLubyte *) "GL_ATI_texture_mirror_once", strExt); + dCaps[i].fPNtriangles = + gluCheckExtension ((const GLubyte *) "GL_ATI_pn_triangles", strExt) || + gluCheckExtension ((const GLubyte *) "GL_ATIX_pn_triangles", strExt); + dCaps[i].fTextFragShader = + gluCheckExtension ((const GLubyte *) "GL_ATI_text_fragment_shader", strExt); + dCaps[i].fATIBlendEqSep = + gluCheckExtension ((const GLubyte *) "GL_ATI_blend_equation_separate", strExt); + dCaps[i].fBlendWeightMinMax = + gluCheckExtension ((const GLubyte *) "GL_ATI_blend_weighted_minmax", strExt); + dCaps[i].fCombine3 = + gluCheckExtension ((const GLubyte *) "GL_ATI_texture_env_combine3", strExt); + dCaps[i].fSepStencil = + gluCheckExtension ((const GLubyte *) "GL_ATI_separate_stencil", strExt); + dCaps[i].fArrayRevComps4Byte = + gluCheckExtension ((const GLubyte *) "GL_ATI_array_rev_comps_in_4_bytes",strExt); + dCaps[i].fNVPointSprite = + gluCheckExtension ((const GLubyte *) "GL_NV_point_sprite", strExt); + dCaps[i].fRegCombiners = + gluCheckExtension ((const GLubyte *) "GL_NV_register_combiners", strExt); + dCaps[i].fRegCombiners2 = + gluCheckExtension ((const GLubyte *) "GL_NV_register_combiners2", strExt); + dCaps[i].fTexEnvCombine4 = + gluCheckExtension ((const GLubyte *) "GL_NV_texture_env_combine4", strExt); + dCaps[i].fBlendSquare = + gluCheckExtension ((const GLubyte *) "GL_NV_blend_square", strExt) || + (dCaps[i].glVersion >= 0x0140); + dCaps[i].fFogDist = + gluCheckExtension ((const GLubyte *) "GL_NV_fog_distance", strExt); + dCaps[i].fMultisampleFilterHint = + gluCheckExtension ((const GLubyte *) "GL_NV_multisample_filter_hint", strExt); + dCaps[i].fTexGenReflect = + gluCheckExtension ((const GLubyte *) "GL_NV_texgen_reflection", strExt); + dCaps[i].fTexShader = + gluCheckExtension ((const GLubyte *) "GL_NV_texture_shader", strExt); + dCaps[i].fTexShader2 = + gluCheckExtension ((const GLubyte *) "GL_NV_texture_shader2", strExt); + dCaps[i].fTexShader3 = + gluCheckExtension ((const GLubyte *) "GL_NV_texture_shader3", strExt); + dCaps[i].fDepthClamp = + gluCheckExtension ((const GLubyte *) "GL_NV_depth_clamp", strExt); + dCaps[i].fLightMaxExp = + gluCheckExtension ((const GLubyte *) "GL_NV_light_max_exponent", strExt); + dCaps[i].fRasterPosClip = + gluCheckExtension ((const GLubyte *) "GL_IBM_rasterpos_clip", strExt); + dCaps[i].fConvBorderModes = + gluCheckExtension ((const GLubyte *) "GL_HP_convolution_border_modes", strExt) || + gluCheckExtension ((const GLubyte *) "GL_ARB_imaging", strExt); + dCaps[i].fAuxDeptStencil = + gluCheckExtension ((const GLubyte *) "GL_APPLE_aux_depth_stencil", strExt); + dCaps[i].fFlushBufferRange = + gluCheckExtension ((const GLubyte *) "GL_APPLE_flush_buffer_range", strExt); + dCaps[i].fObjectPurgeable = + gluCheckExtension ((const GLubyte *) "GL_APPLE_object_purgeable", strExt); + dCaps[i].fDrawBuffers = + gluCheckExtension ((const GLubyte *) "GL_ARB_draw_buffers", strExt) || + (dCaps[i].glVersion >= 0x0200); + dCaps[i].fFragmentProgShadow = + gluCheckExtension ((const GLubyte *) "GL_ARB_fragment_program_shadow", strExt); + dCaps[i].fFragmentShader = + gluCheckExtension ((const GLubyte *) "GL_ARB_fragment_shader", strExt) || + (dCaps[i].glVersion >= 0x0200); + dCaps[i].fHalfFloatPixel = + gluCheckExtension ((const GLubyte *) "GL_ARB_half_float_pixel", strExt); + dCaps[i].fOcclusionQuery = + gluCheckExtension ((const GLubyte *) "GL_ARB_occlusion_query", strExt) || + (dCaps[i].glVersion >= 0x0150); + dCaps[i].fPBO = + gluCheckExtension ((const GLubyte *) "GL_ARB_pixel_buffer_object", strExt) || + (dCaps[i].glVersion >= 0x0210); + dCaps[i].fPointSprite = + gluCheckExtension ((const GLubyte *) "GL_ARB_point_sprite", strExt) || + (dCaps[i].glVersion >= 0x0200); + dCaps[i].fShaderObjects = + gluCheckExtension ((const GLubyte *) "GL_ARB_shader_objects", strExt) || + (dCaps[i].glVersion >= 0x0200); + dCaps[i].fShaderTextureLOD = + gluCheckExtension ((const GLubyte *) "GL_ARB_shader_texture_lod", strExt); + dCaps[i].fShadingLanguage100 = + gluCheckExtension ((const GLubyte *) "GL_ARB_shading_language_100", strExt) || + (dCaps[i].glVersion >= 0x0200); + dCaps[i].fTexFloat = + gluCheckExtension ((const GLubyte *) "GL_ARB_texture_float", strExt); + dCaps[i].fTexNPOT = + gluCheckExtension ((const GLubyte *) "GL_ARB_texture_non_power_of_two", strExt) || + (dCaps[i].glVersion >= 0x0200); + dCaps[i].fVBO = + gluCheckExtension ((const GLubyte *) "GL_ARB_vertex_buffer_object", strExt) || + (dCaps[i].glVersion >= 0x0150); + dCaps[i].fVertexShader = + gluCheckExtension ((const GLubyte *) "GL_ARB_vertex_shader", strExt) || + (dCaps[i].glVersion >= 0x0200); + dCaps[i].fTexComp3dc = + gluCheckExtension ((const GLubyte *) "GL_ATI_texture_compression_3dc", strExt); + dCaps[i].fTexATIfloat = + gluCheckExtension ((const GLubyte *) "GL_ATI_texture_float", strExt); + dCaps[i].fBlendEqSep = + gluCheckExtension ((const GLubyte *) "GL_EXT_blend_equation_separate", strExt) || + (dCaps[i].glVersion >= 0x0200); + dCaps[i].fDepthBounds = + gluCheckExtension ((const GLubyte *) "GL_EXT_depth_bounds_test", strExt); + dCaps[i].fFBOblit = + gluCheckExtension ((const GLubyte *) "GL_EXT_framebuffer_blit", strExt); + dCaps[i].fFBO = + gluCheckExtension ((const GLubyte *) "GL_EXT_framebuffer_object", strExt); + dCaps[i].fGeometryShader4 = + gluCheckExtension ((const GLubyte *) "GL_EXT_geometry_shader4", strExt); + dCaps[i].fGPUProgParams = + gluCheckExtension ((const GLubyte *) "GL_EXT_gpu_program_parameters", strExt); + dCaps[i].fGPUShader4 = + gluCheckExtension ((const GLubyte *) "GL_EXT_gpu_shader4", strExt); + dCaps[i].fDepthStencil = + gluCheckExtension ((const GLubyte *) "GL_EXT_packed_depth_stencil", strExt); + dCaps[i].fSepSpecColor = + gluCheckExtension ((const GLubyte *) "GL_EXT_separate_specular_color", strExt) || + (dCaps[i].glVersion >= 0x0120); + dCaps[i].fTexCompDXT1 = + gluCheckExtension ((const GLubyte *) "GL_EXT_texture_compression_dxt1", strExt); + dCaps[i].fTexMirrorClamp = + gluCheckExtension ((const GLubyte *) "GL_EXT_texture_mirror_clamp", strExt); + dCaps[i].fTexSRGB = + gluCheckExtension ((const GLubyte *) "GL_EXT_texture_sRGB", strExt) || + (dCaps[i].glVersion >= 0x0210); + + if (dCaps[i].fTexRect) // only check if extension supported + glGetIntegerv (GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT, + &dCaps[i].maxRectTextureSize); + else + dCaps[i].maxRectTextureSize = 0; + + CGLDestroyContext (cglContext); + } + } + CGLSetCurrentContext (curr_ctx); // reset current CGL context + } + } +} diff --git a/CocoaGL/GLCheck.h b/CocoaGL/GLCheck.h new file mode 100755 index 00000000..c39b0831 --- /dev/null +++ b/CocoaGL/GLCheck.h @@ -0,0 +1,249 @@ +// +// File: GLCheck.h +// (Originally glCheck.h) +// +// Abstract: glcheck allows developer to check the hardware capabilities of all GPU's +// returning an array of records reflecting the attached hardware. This +// list can be regenerated on Display Manager notifications to keep the +// client update to on capabilities and setup changes. This is provided as +// sample to allow developers the freedom to check as few or as many +// conditions and capabilities as they would like or add their own checks +// +// Version: 1.1 - Removed QD dependencies, list of extensions +// 1.0 - Original release. +// +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") +// in consideration of your agreement to the following terms, and your use, +// installation, modification or redistribution of this Apple software +// constitutes acceptance of these terms. If you do not agree with these +// terms, please do not use, install, modify or redistribute this Apple +// software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non - exclusive +// license, under Apple's copyrights in this original Apple software ( the +// "Apple Software" ), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and / or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following text +// and disclaimers in all such redistributions of the Apple Software. Neither +// the name, trademarks, service marks or logos of Apple Inc. may be used to +// endorse or promote products derived from the Apple Software without specific +// prior written permission from Apple. Except as expressly stated in this +// notice, no other rights or licenses, express or implied, are granted by +// Apple herein, including but not limited to any patent rights that may be +// infringed by your derivative works or by other works in which the Apple +// Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO +// WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED +// WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION +// ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +// CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION +// AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER +// UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR +// OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright ( C ) 2003-2007 Apple Inc. All Rights Reserved. +// + +#include + +typedef struct { + // developers can add capabilities as required + + CGDirectDisplayID cgDisplayID; // CG display ID (main identifier) + CGOpenGLDisplayMask cglDisplayMask; // CGL display mask + + // current (at time of look up) device geometry + long deviceWidth; // pixel width + long deviceHeight; // pixel width + long deviceOriginX; // left location of device (relative to main device) + long deviceOriginY; // upper location of device (relative to main device) + short deviceDepth; // pixel depth in bits + short deviceRefresh; // integer refresh rate in Hz + + // Renderer info + long deviceVRAM; // video memory in bytes + long deviceTextureRAM; // uses current mode (geometry, pixel depth, etc.) + long rendererID; // renderer ID + char strRendererName [256]; // name of hardware renderer + char strRendererVendor [256]; // name of hardware renderer vendor + char strRendererVersion [256]; // string rep of hardware renderer version + bool fullScreenCapable; // does device support full screen + // can add more device specs as you want + + // Renderer Caps + long textureUnits; // standard gl path max number of texture units + long maxTextureSize; // maximum 1D and 2D texture size supported + long max3DTextureSize; // maximum 3D texture size supported + long maxCubeMapTextureSize; // maximum cube map texture size supported + long maxRectTextureSize; // maximum rectangular texture size supported + + // OpenGL version support + unsigned short glVersion; // bcd gl version (ie. 1.4 is 0x0140) + + // Functionality (extensive but not all inclusive list, add as needed) + bool fAuxDeptStencil; // GL_APPLE_aux_depth_stencil +++ + bool fClientStorage; // GL_APPLE_client_storage + bool fElementArray; // GL_APPLE_element_array + bool fFence; // GL_APPLE_fence + bool fFloatPixels; // GL_APPLE_float_pixels + bool fFlushBufferRange; // GL_APPLE_flush_buffer_range +++ + bool fFlushRenderer; // GL_APPLE_flush_render + bool fObjectPurgeable; // GL_APPLE_object_purgeable +++ + bool fPackedPixels; // GL_APPLE_packed_pixels or 1.2+ + bool fPixelBuffer; // GL_APPLE_pixel_buffer + bool fSpecularVector; // GL_APPLE_specular_vector + bool fTextureRange; // GL_APPLE_texture_range (AGP texturing) + bool fTransformHint; // GL_APPLE_transform_hint + bool fVAO; // GL_APPLE_vertex_array_object + bool fVAR; // GL_APPLE_vertex_array_range + bool fVPEvals; // GL_APPLE_vertex_program_evaluators + bool fYCbCr; // GL_APPLE_ycbcr_422 (YUV texturing) + bool fDepthTex; // GL_ARB_depth_texture or 1.4+ + bool fDrawBuffers; // GL_ARB_draw_buffers or 2.0+ +++ + bool fFragmentProg; // GL_ARB_fragment_program + bool fFragmentProgShadow; // GL_ARB_fragment_program_shadow +++ + bool fFragmentShader; // GL_ARB_fragment_shader or 2.0 +++ + bool fHalfFloatPixel; // GL_ARB_half_float_pixel +++ + bool fImaging; // GL_ARB_imaging (not required in 1.2+) + bool fMultisample; // GL_ARB_multisample or 1.3+ (Anti-aliasing) + bool fMultitexture; // GL_ARB_multitexture or 1.3+ + bool fOcclusionQuery; // GL_ARB_occlusion_query or 1.5+ +++ + bool fPBO; // GL_ARB_pixel_buffer_object or 2.1 +++ + bool fPointParam; // GL_ARB_point_parameters or 1.4+ + bool fPointSprite; // GL_ARB_point_sprite or 2.0+ +++ + bool fShaderObjects; // GL_ARB_shader_objects or 2.0+ +++ + bool fShaderTextureLOD; // GL_ARB_shader_texture_lod +++ + bool fShadingLanguage100; // GL_ARB_shading_language_100 or 2.0 +++ + bool fShadow; // GL_ARB_shadow or 1.4+ + bool fShadowAmbient; // GL_ARB_shadow_ambient + bool fTexBorderClamp; // GL_ARB_texture_border_clamp or 1.3+ + bool fTexCompress; // GL_ARB_texture_compression or 1.3+ + bool fTexCubeMap; // GL_ARB_texture_cube_map or 1.3+ + bool fTexEnvAdd; // GL_ARB_texture_env_add, GL_EXT_texture_env_add or 1.3+ + bool fTexEnvCombine; // GL_ARB_texture_env_combine or 1.3+ + bool fTexEnvCrossbar; // GL_ARB_texture_env_crossbar or 1.4+ + bool fTexEnvDot3; // GL_ARB_texture_env_dot3 or 1.3+ + bool fTexFloat; // GL_ARB_texture_float +++ + bool fTexMirrorRepeat; // GL_ARB_texture_mirrored_repeat or 1.4+ + bool fTexNPOT; // GL_ARB_texture_non_power_of_two or 2.0+ +++ + bool fTexRectARB; // GL_ARB_texture_rectangle + bool fTransposeMatrix; // GL_ARB_transpose_matrix or 1.3+ + bool fVertexBlend; // GL_ARB_vertex_blend + bool fVBO; // GL_ARB_vertex_buffer_object or 1.5+ +++ + bool fVertexProg; // GL_ARB_vertex_program + bool fVertexShader; // GL_ARB_vertex_shader or 2.0+ +++ + bool fWindowPos; // GL_ARB_window_pos or 1.4+ + bool fArrayRevComps4Byte; // GL_ATI_array_rev_comps_in_4_bytes + bool fATIBlendEqSep; // GL_ATI_blend_equation_separate + bool fBlendWeightMinMax; // GL_ATI_blend_weighted_minmax + bool fPNtriangles; // GL_ATI_pn_triangles or GL_ATIX_pn_triangles + bool fPointCull; // GL_ATI_point_cull_mode + bool fSepStencil; // GL_ATI_separate_stencil + bool fTextFragShader; // GL_ATI_text_fragment_shader + bool fTexComp3dc; // GL_ATI_texture_compression_3dc +++ + bool fCombine3; // GL_ATI_texture_env_combine3 + bool fTexATIfloat; // GL_ATI_texture_float +++ + bool fTexMirrorOnce; // GL_ATI_texture_mirror_once + bool fABGR; // GL_EXT_abgr + bool fBGRA; // GL_EXT_bgra or 1.2+ + bool fBlendColor; // GL_EXT_blend_color or GL_ARB_imaging + bool fBlendEqSep; // GL_EXT_blend_equation_separate or 2.0+ +++ + bool fBlendFuncSep; // GL_EXT_blend_func_separate or 1.4+ + bool fBlendMinMax; // GL_EXT_blend_minmax or GL_ARB_imaging + bool fBlendSub; // GL_EXT_blend_subtract or GL_ARB_imaging + bool fClipVolHint; // GL_EXT_clip_volume_hint + bool fColorSubtable; // GL_EXT_color_subtable or GL_ARB_imaging + bool fCVA; // GL_EXT_compiled_vertex_array + bool fDepthBounds; // GL_EXT_depth_bounds_test +++ + bool fConvolution; // GL_EXT_convolution or GL_ARB_imaging + bool fDrawRangeElements; // GL_EXT_draw_range_elements + bool fFogCoord; // GL_EXT_fog_coord + bool fFBOblit; // GL_EXT_framebuffer_blit +++ + bool fFBO; // GL_EXT_framebuffer_object +++ + bool fGeometryShader4; // GL_EXT_geometry_shader4 +++ + bool fGPUProgParams; // GL_EXT_gpu_program_parameters +++ + bool fGPUShader4; // GL_EXT_gpu_shader4 +++ + bool fHistogram; // GL_EXT_histogram or GL_ARB_imaging + bool fDepthStencil; // GL_EXT_packed_depth_stencil +++ + bool fMultiDrawArrays; // GL_EXT_multi_draw_arrays or 1.4+ + bool fPaletteTex; // GL_EXT_paletted_texture + bool fRescaleNorm; // GL_EXT_rescale_normal or 1.2+ + bool fSecColor; // GL_EXT_secondary_color or 1.4+ + bool fSepSpecColor; // GL_EXT_separate_specular_color or 1.2+ +++ + bool fShadowFunc; // GL_EXT_shadow_funcs + bool fShareTexPalette; // GL_EXT_shared_texture_palette + bool fStencil2Side; // GL_EXT_stencil_two_side + bool fStencilWrap; // GL_EXT_stencil_wrap or 1.4+ + bool fTexCompDXT1; // GL_EXT_texture_compression_dxt1 +++ + bool fTex3D; // GL_EXT_texture3D or 1.2+ + bool fTexCompressS3TC; // GL_EXT_texture_compression_s3tc + bool fTexFilterAniso; // GL_EXT_texture_filter_anisotropic + bool fTexLODBias; // GL_EXT_texture_lod_bias or 1.4+ + bool fTexMirrorClamp; // GL_EXT_texture_mirror_clamp +++ + bool fTexRect; // GL_EXT_texture_rectangle + bool fTexSRGB; // GL_EXT_texture_sRGB or 2.1+ +++ + bool fTransformFeedback; // GL_EXT_transform_feedback +++ + bool fConvBorderModes; // GL_HP_convolution_border_modes or GL_ARB_imaging + bool fRasterPosClip; // GL_IBM_rasterpos_clip + bool fBlendSquare; // GL_NV_blend_square or 1.4+ + bool fDepthClamp; // GL_NV_depth_clamp + bool fFogDist; // GL_NV_fog_distance + bool fLightMaxExp; // GL_NV_light_max_exponent + bool fMultisampleFilterHint; // GL_NV_multisample_filter_hint + bool fNVPointSprite; // GL_NV_point_sprite + bool fRegCombiners; // GL_NV_register_combiners + bool fRegCombiners2; // GL_NV_register_combiners2 + bool fTexGenReflect; // GL_NV_texgen_reflection + bool fTexEnvCombine4; // GL_NV_texture_env_combine4 + bool fTexShader; // GL_NV_texture_shader + bool fTexShader2; // GL_NV_texture_shader2 + bool fTexShader3; // GL_NV_texture_shader3 + bool fGenMipmap; // GL_SGIS_generate_mipmap or 1.4+ + bool fTexEdgeClamp; // GL_SGIS_texture_edge_clamp or 1.2+ + bool fTexLOD; // GL_SGIS_texture_lod or 1.2+ + bool fColorMatrix; // GL_SGI_color_matrix + bool fColorTable; // GL_SGI_color_table or GL_ARB_imaging +} GLCaps; + +// this does a reasonable check to see if things have changed without being +// too heavy weight; returns 1 if changed 0 if not +// checks num displays, displayID, displayMask, each display geometry and +// renderer VRAM and ID +unsigned char HaveOpenGLCapsChanged (GLCaps aDisplayCaps[], + CGDisplayCount dspyCnt); + + +// This will walk all active displays and gather information about their +// hardware renderer + +// An array length (maxDisplays) and array of GLCaps are passed in. Up to +// maxDisplays of the array are filled in with the displays meeting the +// specified criteria. The actual number of displays filled in is returned +// in dspyCnt. Calling this function with maxDisplays of 0 will just +// return the number of displays in dspyCnt. + +// Developers should note this is NOT an exhaustive list of all the +// capabilities one could query, nor a required set of capabilities, +// feel free to add or subtract queries as you find helpful for your +// application/use. + +// one note on mirrored displays... if the display configuration is +// changed it is possible (and likely) that the current active display +// in a mirrored configuration (as identified by the OpenGL Display Mask) +// will change if the mirrored display is removed. +// This is due to the preference of selection the external display as +// the active display. This may affect full screen apps which should +// always detect display configuration changes and respond accordingly. + +void CheckOpenGLCaps (CGDisplayCount maxDisplays, + GLCaps * aDisplayCaps, + CGDisplayCount * dspyCnt); \ No newline at end of file diff --git a/CocoaGL/GLString.h b/CocoaGL/GLString.h new file mode 100755 index 00000000..b4b84d42 --- /dev/null +++ b/CocoaGL/GLString.h @@ -0,0 +1,127 @@ +// +// File: GLString.h +// (Originally StringTexture.h) +// +// Abstract: Uses Quartz to draw a string into an OpenGL texture +// +// Version: 1.1 - Minor enhancements and bug fixes. +// 1.0 - Original release. +// +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") +// in consideration of your agreement to the following terms, and your use, +// installation, modification or redistribution of this Apple software +// constitutes acceptance of these terms. If you do not agree with these +// terms, please do not use, install, modify or redistribute this Apple +// software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non - exclusive +// license, under Apple's copyrights in this original Apple software ( the +// "Apple Software" ), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and / or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following text +// and disclaimers in all such redistributions of the Apple Software. Neither +// the name, trademarks, service marks or logos of Apple Inc. may be used to +// endorse or promote products derived from the Apple Software without specific +// prior written permission from Apple. Except as expressly stated in this +// notice, no other rights or licenses, express or implied, are granted by +// Apple herein, including but not limited to any patent rights that may be +// infringed by your derivative works or by other works in which the Apple +// Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO +// WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED +// WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION +// ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +// CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION +// AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER +// UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR +// OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright ( C ) 2003-2007 Apple Inc. All Rights Reserved. +// + +#import +#import +#import +#import +#import + +@interface NSBezierPath (RoundRect) ++ (NSBezierPath *)bezierPathWithRoundedRect:(NSRect)rect cornerRadius:(float)radius; + +- (void)appendBezierPathWithRoundedRect:(NSRect)rect cornerRadius:(float)radius; +@end + +@interface GLString : NSObject { + CGLContextObj cgl_ctx; // current context at time of texture creation + GLuint texName; + NSSize texSize; + + NSAttributedString * string; + NSColor * textColor; // default is opaque white + NSColor * boxColor; // default transparent or none + NSColor * borderColor; // default transparent or none + BOOL staticFrame; // default in NO + BOOL antialias; // default to YES + NSSize marginSize; // offset or frame size, default is 4 width 2 height + NSSize frameSize; // offset or frame size, default is 4 width 2 height + float cRadius; // Corner radius, if 0 just a rectangle. Defaults to 4.0f + + BOOL requiresUpdate; +} + +// this API requires a current rendering context and all operations will be performed in regards to thar context +// the same context should be current for all method calls for a particular object instance + +// designated initializer +- (id) initWithAttributedString:(NSAttributedString *)attributedString withTextColor:(NSColor *)color withBoxColor:(NSColor *)color withBorderColor:(NSColor *)color; + +- (id) initWithString:(NSString *)aString withAttributes:(NSDictionary *)attribs withTextColor:(NSColor *)color withBoxColor:(NSColor *)color withBorderColor:(NSColor *)color; + +// basic methods that pick up defaults +- (id) initWithString:(NSString *)aString withAttributes:(NSDictionary *)attribs; +- (id) initWithAttributedString:(NSAttributedString *)attributedString; + +- (void) dealloc; + +- (GLuint) texName; // 0 if no texture allocated +- (NSSize) texSize; // actually size of texture generated in texels, (0, 0) if no texture allocated + +- (NSColor *) textColor; // get the pre-multiplied default text color (includes alpha) string attributes could override this +- (NSColor *) boxColor; // get the pre-multiplied box color (includes alpha) alpha of 0.0 means no background box +- (NSColor *) borderColor; // get the pre-multiplied border color (includes alpha) alpha of 0.0 means no border +- (BOOL) staticFrame; // returns whether or not a static frame will be used + +- (NSSize) frameSize; // returns either dynamc frame (text size + margins) or static frame size (switch with staticFrame) + +- (NSSize) marginSize; // current margins for text offset and pads for dynamic frame + +- (void) genTexture; // generates the texture without drawing texture to current context +- (void) drawWithBounds:(NSRect)bounds; // will update the texture if required due to change in settings (note context should be setup to be orthographic scaled to per pixel scale) +- (void) drawAtPoint:(NSPoint)point; + +// these will force the texture to be regenerated at the next draw +- (void) setMargins:(NSSize)size; // set offset size and size to fit with offset +- (void) useStaticFrame:(NSSize)size; // set static frame size and size to frame +- (void) useDynamicFrame; // set static frame size and size to frame + +- (void) setString:(NSAttributedString *)attributedString; // set string after initial creation +- (void) setString:(NSString *)aString withAttributes:(NSDictionary *)attribs; // set string after initial creation + +- (void) setTextColor:(NSColor *)color; // set default text color +- (void) setBoxColor:(NSColor *)color; // set default text color +- (void) setBorderColor:(NSColor *)color; // set default text color + +- (BOOL) antialias; +- (void) setAntialias:(bool)request; + +@end + diff --git a/CocoaGL/GLString.m b/CocoaGL/GLString.m new file mode 100755 index 00000000..bc44a55b --- /dev/null +++ b/CocoaGL/GLString.m @@ -0,0 +1,414 @@ +// +// File: GLString.m +// (Originally StringTexture.m) +// +// Abstract: Uses Quartz to draw a string into an OpenGL texture +// +// Version: 1.1 - Antialiasing option, Rounded Corners to the frame +// self contained OpenGL state, performance enhancements, +// other bug fixes. +// 1.0 - Original release. +// +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") +// in consideration of your agreement to the following terms, and your use, +// installation, modification or redistribution of this Apple software +// constitutes acceptance of these terms. If you do not agree with these +// terms, please do not use, install, modify or redistribute this Apple +// software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non - exclusive +// license, under Apple's copyrights in this original Apple software ( the +// "Apple Software" ), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and / or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following text +// and disclaimers in all such redistributions of the Apple Software. Neither +// the name, trademarks, service marks or logos of Apple Inc. may be used to +// endorse or promote products derived from the Apple Software without specific +// prior written permission from Apple. Except as expressly stated in this +// notice, no other rights or licenses, express or implied, are granted by +// Apple herein, including but not limited to any patent rights that may be +// infringed by your derivative works or by other works in which the Apple +// Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO +// WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED +// WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION +// ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +// CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION +// AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER +// UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR +// OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright ( C ) 2003-2007 Apple Inc. All Rights Reserved. +// + +#import "GLString.h" + +// The following is a NSBezierPath category to allow +// for rounded corners of the border + +#pragma mark - +#pragma mark NSBezierPath Category + +@implementation NSBezierPath (RoundRect) + ++ (NSBezierPath *)bezierPathWithRoundedRect:(NSRect)rect cornerRadius:(float)radius { + NSBezierPath *result = [NSBezierPath bezierPath]; + [result appendBezierPathWithRoundedRect:rect cornerRadius:radius]; + return result; +} + +- (void)appendBezierPathWithRoundedRect:(NSRect)rect cornerRadius:(float)radius { + if (!NSIsEmptyRect(rect)) { + if (radius > 0.0) { + // Clamp radius to be no larger than half the rect's width or height. + float clampedRadius = MIN(radius, 0.5 * MIN(rect.size.width, rect.size.height)); + + NSPoint topLeft = NSMakePoint(NSMinX(rect), NSMaxY(rect)); + NSPoint topRight = NSMakePoint(NSMaxX(rect), NSMaxY(rect)); + NSPoint bottomRight = NSMakePoint(NSMaxX(rect), NSMinY(rect)); + + [self moveToPoint:NSMakePoint(NSMidX(rect), NSMaxY(rect))]; + [self appendBezierPathWithArcFromPoint:topLeft toPoint:rect.origin radius:clampedRadius]; + [self appendBezierPathWithArcFromPoint:rect.origin toPoint:bottomRight radius:clampedRadius]; + [self appendBezierPathWithArcFromPoint:bottomRight toPoint:topRight radius:clampedRadius]; + [self appendBezierPathWithArcFromPoint:topRight toPoint:topLeft radius:clampedRadius]; + [self closePath]; + } else { + // When radius == 0.0, this degenerates to the simple case of a plain rectangle. + [self appendBezierPathWithRect:rect]; + } + } +} + +@end + + +#pragma mark - +#pragma mark GLString + +// GLString follows + +@implementation GLString + +#pragma mark - +#pragma mark Deallocs + +- (void) deleteTexture +{ + if (texName && cgl_ctx) { + (*cgl_ctx->disp.delete_textures)(cgl_ctx->rend, 1, &texName); + texName = 0; // ensure it is zeroed for failure cases + cgl_ctx = 0; + } +} + +- (void) dealloc +{ + [self deleteTexture]; + [textColor release]; + [boxColor release]; + [borderColor release]; + [string release]; + [super dealloc]; +} + +#pragma mark - +#pragma mark Initializers + +// designated initializer +- (id) initWithAttributedString:(NSAttributedString *)attributedString withTextColor:(NSColor *)text withBoxColor:(NSColor *)box withBorderColor:(NSColor *)border +{ + [super init]; + cgl_ctx = NULL; + texName = 0; + texSize.width = 0.0f; + texSize.height = 0.0f; + [attributedString retain]; + string = attributedString; + [text retain]; + [box retain]; + [border retain]; + textColor = text; + boxColor = box; + borderColor = border; + staticFrame = NO; + antialias = YES; + marginSize.width = 4.0f; // standard margins + marginSize.height = 2.0f; + cRadius = 4.0f; + requiresUpdate = YES; + // all other variables 0 or NULL + return self; +} + +- (id) initWithString:(NSString *)aString withAttributes:(NSDictionary *)attribs withTextColor:(NSColor *)text withBoxColor:(NSColor *)box withBorderColor:(NSColor *)border +{ + return [self initWithAttributedString:[[[NSAttributedString alloc] initWithString:aString attributes:attribs] autorelease] withTextColor:text withBoxColor:box withBorderColor:border]; +} + +// basic methods that pick up defaults +- (id) initWithAttributedString:(NSAttributedString *)attributedString; +{ + return [self initWithAttributedString:attributedString withTextColor:[NSColor colorWithDeviceRed:1.0f green:1.0f blue:1.0f alpha:1.0f] withBoxColor:[NSColor colorWithDeviceRed:1.0f green:1.0f blue:1.0f alpha:0.0f] withBorderColor:[NSColor colorWithDeviceRed:1.0f green:1.0f blue:1.0f alpha:0.0f]]; +} + +- (id) initWithString:(NSString *)aString withAttributes:(NSDictionary *)attribs +{ + return [self initWithAttributedString:[[[NSAttributedString alloc] initWithString:aString attributes:attribs] autorelease] withTextColor:[NSColor colorWithDeviceRed:1.0f green:1.0f blue:1.0f alpha:1.0f] withBoxColor:[NSColor colorWithDeviceRed:1.0f green:1.0f blue:1.0f alpha:0.0f] withBorderColor:[NSColor colorWithDeviceRed:1.0f green:1.0f blue:1.0f alpha:0.0f]]; +} + +- (void) genTexture; // generates the texture without drawing texture to current context +{ + NSImage * image; + NSBitmapImageRep * bitmap; + + NSSize previousSize = texSize; + + if ((NO == staticFrame) && (0.0f == frameSize.width) && (0.0f == frameSize.height)) { // find frame size if we have not already found it + frameSize = [string size]; // current string size + frameSize.width += marginSize.width * 2.0f; // add padding + frameSize.height += marginSize.height * 2.0f; + } + image = [[NSImage alloc] initWithSize:frameSize]; + + [image lockFocus]; + [[NSGraphicsContext currentContext] setShouldAntialias:antialias]; + + if ([boxColor alphaComponent]) { // this should be == 0.0f but need to make sure + [boxColor set]; + NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(NSMakeRect (0.0f, 0.0f, frameSize.width, frameSize.height) , 0.5, 0.5) + cornerRadius:cRadius]; + [path fill]; + } + + if ([borderColor alphaComponent]) { + [borderColor set]; + NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(NSMakeRect (0.0f, 0.0f, frameSize.width, frameSize.height), 0.5, 0.5) + cornerRadius:cRadius]; + [path setLineWidth:1.0f]; + [path stroke]; + } + + [textColor set]; + [string drawAtPoint:NSMakePoint (marginSize.width, marginSize.height)]; // draw at offset position + bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect (0.0f, 0.0f, frameSize.width, frameSize.height)]; + [image unlockFocus]; + texSize.width = [bitmap pixelsWide]; + texSize.height = [bitmap pixelsHigh]; + + if (cgl_ctx = CGLGetCurrentContext ()) { // if we successfully retrieve a current context (required) + glPushAttrib(GL_TEXTURE_BIT); + if (0 == texName) glGenTextures (1, &texName); + glBindTexture (GL_TEXTURE_RECTANGLE_EXT, texName); + if (NSEqualSizes(previousSize, texSize)) { + glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT,0,0,0,texSize.width,texSize.height,[bitmap hasAlpha] ? GL_RGBA : GL_RGB,GL_UNSIGNED_BYTE,[bitmap bitmapData]); + } else { + glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA, texSize.width, texSize.height, 0, [bitmap hasAlpha] ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, [bitmap bitmapData]); + } + glPopAttrib(); + } else + NSLog (@"StringTexture -genTexture: Failure to get current OpenGL context\n"); + + [bitmap release]; + [image release]; + + requiresUpdate = NO; +} + +#pragma mark - +#pragma mark Accessors + +- (GLuint) texName +{ + return texName; +} + +- (NSSize) texSize +{ + return texSize; +} + +#pragma mark Text Color + +- (void) setTextColor:(NSColor *)color // set default text color +{ + [color retain]; + [textColor release]; + textColor = color; + requiresUpdate = YES; +} + +- (NSColor *) textColor +{ + return textColor; +} + +#pragma mark Box Color + +- (void) setBoxColor:(NSColor *)color // set default text color +{ + [color retain]; + [boxColor release]; + boxColor = color; + requiresUpdate = YES; +} + +- (NSColor *) boxColor +{ + return boxColor; +} + +#pragma mark Border Color + +- (void) setBorderColor:(NSColor *)color // set default text color +{ + [color retain]; + [borderColor release]; + borderColor = color; + requiresUpdate = YES; +} + +- (NSColor *) borderColor +{ + return borderColor; +} + +#pragma mark Margin Size + +// these will force the texture to be regenerated at the next draw +- (void) setMargins:(NSSize)size // set offset size and size to fit with offset +{ + marginSize = size; + if (NO == staticFrame) { // ensure dynamic frame sizes will be recalculated + frameSize.width = 0.0f; + frameSize.height = 0.0f; + } + requiresUpdate = YES; +} + +- (NSSize) marginSize +{ + return marginSize; +} + +#pragma mark Antialiasing +- (BOOL) antialias +{ + return antialias; +} + +- (void) setAntialias:(bool)request +{ + antialias = request; + requiresUpdate = YES; +} + + +#pragma mark Frame + +- (NSSize) frameSize +{ + if ((NO == staticFrame) && (0.0f == frameSize.width) && (0.0f == frameSize.height)) { // find frame size if we have not already found it + frameSize = [string size]; // current string size + frameSize.width += marginSize.width * 2.0f; // add padding + frameSize.height += marginSize.height * 2.0f; + } + return frameSize; +} + +- (BOOL) staticFrame +{ + return staticFrame; +} + +- (void) useStaticFrame:(NSSize)size // set static frame size and size to frame +{ + frameSize = size; + staticFrame = YES; + requiresUpdate = YES; +} + +- (void) useDynamicFrame +{ + if (staticFrame) { // set to dynamic frame and set to regen texture + staticFrame = NO; + frameSize.width = 0.0f; // ensure frame sizes will be recalculated + frameSize.height = 0.0f; + requiresUpdate = YES; + } +} + +#pragma mark String + +- (void) setString:(NSAttributedString *)attributedString // set string after initial creation +{ + [attributedString retain]; + [string release]; + string = attributedString; + if (NO == staticFrame) { // ensure dynamic frame sizes will be recalculated + frameSize.width = 0.0f; + frameSize.height = 0.0f; + } + requiresUpdate = YES; +} + +- (void) setString:(NSString *)aString withAttributes:(NSDictionary *)attribs; // set string after initial creation +{ + [self setString:[[[NSAttributedString alloc] initWithString:aString attributes:attribs] autorelease]]; +} + + +#pragma mark - +#pragma mark Drawing + +- (void) drawWithBounds:(NSRect)bounds +{ + if (requiresUpdate) + [self genTexture]; + if (texName) { + glPushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT); // GL_COLOR_BUFFER_BIT for glBlendFunc, GL_ENABLE_BIT for glEnable / glDisable + + glDisable (GL_DEPTH_TEST); // ensure text is not remove by depth buffer test. + glEnable (GL_BLEND); // for text fading + glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // ditto + glEnable (GL_TEXTURE_RECTANGLE_EXT); + + glBindTexture (GL_TEXTURE_RECTANGLE_EXT, texName); + glBegin (GL_QUADS); + glTexCoord2f (0.0f, 0.0f); // draw upper left in world coordinates + glVertex2f (bounds.origin.x, bounds.origin.y); + + glTexCoord2f (0.0f, texSize.height); // draw lower left in world coordinates + glVertex2f (bounds.origin.x, bounds.origin.y + bounds.size.height); + + glTexCoord2f (texSize.width, texSize.height); // draw upper right in world coordinates + glVertex2f (bounds.origin.x + bounds.size.width, bounds.origin.y + bounds.size.height); + + glTexCoord2f (texSize.width, 0.0f); // draw lower right in world coordinates + glVertex2f (bounds.origin.x + bounds.size.width, bounds.origin.y); + glEnd (); + + glPopAttrib(); + } +} + +- (void) drawAtPoint:(NSPoint)point +{ + if (requiresUpdate) + [self genTexture]; // ensure size is calculated for bounds + if (texName) // if successful + [self drawWithBounds:NSMakeRect (point.x, point.y, texSize.width, texSize.height)]; +} + +@end diff --git a/CocoaGL/Info.plist b/CocoaGL/Info.plist new file mode 100644 index 00000000..98d7bd3e --- /dev/null +++ b/CocoaGL/Info.plist @@ -0,0 +1,28 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIconFile + Cocoa GL + CFBundleIdentifier + com.apple.Cocoa OpenGL + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleSignature + ???? + CFBundleVersion + 1.1 + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/CocoaGL/ReadMe.rtfd/CocoaGL.jpg b/CocoaGL/ReadMe.rtfd/CocoaGL.jpg new file mode 100644 index 00000000..c8754674 Binary files /dev/null and b/CocoaGL/ReadMe.rtfd/CocoaGL.jpg differ diff --git a/CocoaGL/ReadMe.rtfd/TXT.rtf b/CocoaGL/ReadMe.rtfd/TXT.rtf new file mode 100644 index 00000000..98ef41ad --- /dev/null +++ b/CocoaGL/ReadMe.rtfd/TXT.rtf @@ -0,0 +1,230 @@ +{\rtf1\ansi\ansicpg1252\cocoartf949 +{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fnil\fcharset0 Monaco;} +{\colortbl;\red255\green255\blue255;} +{\*\listtable{\list\listtemplateid1\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid1} +{\list\listtemplateid2\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{hyphen\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid1\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid2} +{\list\listtemplateid3\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid3} +{\list\listtemplateid4\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{hyphen\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid1\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid4} +{\list\listtemplateid5\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid5} +{\list\listtemplateid6\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{hyphen\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid1\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid6} +{\list\listtemplateid7\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid1\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid7} +{\list\listtemplateid8\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid8} +{\list\listtemplateid9\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{hyphen\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid1\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid9} +{\list\listtemplateid10\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid10} +{\list\listtemplateid11\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{hyphen\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid1\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid11} +{\list\listtemplateid12\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid12} +{\list\listtemplateid13\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{hyphen\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid1\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid13} +{\list\listtemplateid14\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid14} +{\list\listtemplateid15\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{hyphen\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid1\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid15} +{\list\listtemplateid16\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid16} +{\list\listtemplateid17\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid17} +{\list\listtemplateid18\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid18} +{\list\listtemplateid19\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc2\leveljcn2\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid0\'02\'05.;}{\levelnumbers\'01;}}{\listname ;}\listid19}} +{\*\listoverridetable{\listoverride\listid1\listoverridecount0\ls1}{\listoverride\listid2\listoverridecount0\ls2}{\listoverride\listid3\listoverridecount0\ls3}{\listoverride\listid4\listoverridecount0\ls4}{\listoverride\listid5\listoverridecount0\ls5}{\listoverride\listid6\listoverridecount0\ls6}{\listoverride\listid7\listoverridecount0\ls7}{\listoverride\listid8\listoverridecount0\ls8}{\listoverride\listid9\listoverridecount0\ls9}{\listoverride\listid10\listoverridecount0\ls10}{\listoverride\listid11\listoverridecount0\ls11}{\listoverride\listid12\listoverridecount0\ls12}{\listoverride\listid13\listoverridecount0\ls13}{\listoverride\listid14\listoverridecount0\ls14}{\listoverride\listid15\listoverridecount0\ls15}{\listoverride\listid16\listoverridecount0\ls16}{\listoverride\listid17\listoverridecount0\ls17}{\listoverride\listid18\listoverridecount0\ls18}{\listoverride\listid19\listoverridecount0\ls19}} +\margl1440\margr1440\vieww17320\viewh20620\viewkind0 +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural + +\f0\fs24 \cf0 {{\NeXTGraphic CocoaGL.jpg \width3080 \height2460 +}¬}\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural +\cf0 +\b Cocoa OpenGL +\b0 \ +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural +\cf0 \ + This sample application shows the basics of rendering with OpenGL using the Cocoa interface. The +\f1 BasicOpenGLView +\f0 class is the highlight of this sample application.\ +\ + +\b The BasicOpenGLView Class:\ + +\b0 \ + The +\f1 BasicOpenGLView +\f0 class a subclass of +\f1 NSOpenGLView +\f0 , which is instantiated on the main window in the nib file, manages the content, input and events of a colorful cube which rotates over time. \ +\ + Here are 4 distinct areas of the class:\ +\ +\pard\tx220\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li720\fi-720\ql\qnatural\pardirnatural +\ls1\ilvl0 +\b \cf0 {\listtext \'95 }Initialization\ +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural + +\i\b0 \cf0 \ +\pard\tx940\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li1440\fi-1440\ql\qnatural\pardirnatural +\ls2\ilvl1\cf0 {\listtext \'95 } +\i0 The +\f1 initWithFrame +\f0\i +\i0 method, which is overridden from the default +\f1 NSOpenGLView +\f0\i class +\i0 , creates a +\f1 NSOpenGLPixelformat +\f0 by calling the +\f1 BasicOpenGLView's +\f0\i +\f1\i0 basicPixelFormat +\f0\i +\i0 which will request a double buffer color buffer, and a 16 bits wide depth buffer. A call is made to the super class ( +\f1 NSOpenGLView +\f0\i ) +\i0 to create an OpenGL context using the requested pixel format .\ +{\listtext \'95 }The +\f1 awakeFromNib +\f0\i +\i0 method is then called to initialize some variables, check the OpenGL capabilities (extensions present, limits, etc), and sets a +\f1 NSTimer +\f0\i +\i0 which will call the +\f1 animationTimer +\f0\i +\i0 every 1/60 of a second\ +{\listtext \'95 }The +\f1 prepareOpenGL +\f0 method is then called before rendering starts. This method first sets the OpenGL context's swaps of the color buffers to be synchronized to the vertical retrace period of the display. It sets some initial OpenGL state, initializes our camera, the font to be used for our +\f1 GLString +\f0 textures, and finally creates the initial strings. \ +{\listtext \'95 }\ +\pard\tx220\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li720\fi-720\ql\qnatural\pardirnatural +\ls3\ilvl0 +\b \cf0 {\listtext \'95 }Rendering Loop\ +\pard\tx220\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li720\fi-720\ql\qnatural\pardirnatural +\ls3\ilvl0 +\b0 \cf0 \ +\pard\tx940\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li1440\fi-1440\ql\qnatural\pardirnatural +\ls4\ilvl1\cf0 {\listtext \'95 }The +\f1 drawRect +\f0 method is called for the first time. This method is where the rendering actually happens. The viewport, projection, camera, +\f1 modelview +\f0 , matrices and strings are adjusted the cube and information string are rendered. Finally the time is checked and possible OpenGL errors are checked and reported if needed. If multiple OpenGL contexts were present on your application, the OpenGL context would have to be made the current context as well.\ +{\listtext \'95 }As the +\f1 NSTimer +\f0 fires, the +\f1 animationTimer +\f0 gets executed which updates the rotation based on elapsed time and calls the +\f1 drawRect +\f0 method to render again.\ +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural +\cf0 \ +\pard\tx220\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li720\fi-720\ql\qnatural\pardirnatural +\ls5\ilvl0 +\b \cf0 {\listtext \'95 }Event Handling\ +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural + +\b0 \cf0 \ +\pard\tx940\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li1440\fi-1440\ql\qnatural\pardirnatural +\ls6\ilvl1\cf0 {\listtext \'95 }The +\f1 acceptsFirstResponder +\f0 and +\f1 becomeFirstResponder +\f0 methods returning YES allow +\f1 BasicOpenGLView +\f0\i +\i0 to receive events.\ +{\listtext \'95 }Several methods of the +\f1 BasicOpenGLView +\f0 are dedicated to receiving events from the mouse or keyboard: +\f1 \CocoaLigature0 keyDown, mouseDown, rightMouseDown, otherMouseDown, mouseUp, rightMouseUp, otherMouseUp, mouseDragged, scrollWheel, rightMouseDragged +\f0 \CocoaLigature1 and +\f1 \CocoaLigature0 otherMouseDragged.\ +\pard\tx940\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li1440\fi-1440\ql\qnatural\pardirnatural + +\f0 \cf0 \CocoaLigature1 \'95 This methods act on what their name describe to update the camera which affect the projection and modelview matrices. \ +\pard\tx220\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li720\fi-720\ql\qnatural\pardirnatural +\ls7\ilvl0 +\b \cf0 {\listtext \'95 }Main Menu Interaction\ +\pard\tx220\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li720\fi-720\ql\qnatural\pardirnatural +\ls7\ilvl0 +\b0 \cf0 \ +\pard\tx940\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li1440\fi-1440\ql\qnatural\pardirnatural +\ls7\ilvl1\cf0 {\listtext \'95 }The +\f1 \CocoaLigature0 animate +\f0 \CocoaLigature1 and +\f1 \CocoaLigature0 info +\f0 \CocoaLigature1 methods are called from the Main menu Animate and Info choices. The menu choices are "wired" to these methods with Interface Builder and this information is stored and restored from the MainMenu.nib file.\ +\ +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural + +\b \cf0 The GL Utilities group:\ + +\b0 \ +\pard\tx220\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li720\fi-720\ql\qnatural\pardirnatural +\ls8\ilvl0 +\b \cf0 {\listtext \'95 }GLString.m\ +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural + +\i\b0 \cf0 \ +\pard\tx940\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li1440\fi-1440\ql\qnatural\pardirnatural +\ls9\ilvl1\cf0 {\listtext \'95 } +\i0 This class manages string textures generated with Quartz. A particular string can be initialized via +\f1 \CocoaLigature0 initWithString:withAttributes:withTextColor:withBoxColor:withBorderColor: +\f0 \CocoaLigature1 and can be drawn using +\f1 \CocoaLigature0 drawAtPoint: +\f0 \CocoaLigature1 which takes a single 2D point as the origin of the quad that contains the texture\ +\ +\pard\tx220\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li720\fi-720\ql\qnatural\pardirnatural +\ls10\ilvl0 +\b \cf0 {\listtext \'95 }Trackball.c\ +\ +\pard\tx940\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li1440\fi-1440\ql\qnatural\pardirnatural +\ls11\ilvl1 +\i\b0 \cf0 {\listtext \'95 } +\i0 \CocoaLigature0 This code implements a trackball as the camera system. The trackball works by pretending that a ball encloses the 3D view. You roll this pretend ball with the mouse. For example, if you click on the center of the ball and move the mouse straight to the right, you roll the ball around its Y-axis. This produces a Y-axis rotation. You can click on the "edge" of the ball and roll it around in a circle to get a Z-axis rotation.\CocoaLigature1 \ +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural +\cf0 \ +\pard\tx220\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li720\fi-720\ql\qnatural\pardirnatural +\ls12\ilvl0 +\b \cf0 {\listtext \'95 }GLCheck.c\ +\ +\pard\tx940\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li1440\fi-1440\ql\qnatural\pardirnatural +\ls13\ilvl1 +\i\b0 \cf0 {\listtext \'95 } +\i0 \CocoaLigature0 GLCheck allows developer to check the hardware capabilities of all GPU's returning an array of records reflecting the attached hardware. This list can be regenerated on Display Manager notifications to keep the client update to on capabilities and setup changes. This is provided as sample to allow developers the freedom to check as few or as many conditions and capabilities as they would like or add their own checks\ +\pard\tx220\tx720\tx1120\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li720\fi-720\ql\qnatural\pardirnatural +\ls13\ilvl0\cf0 \CocoaLigature1 \ +\pard\tx220\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li720\fi-720\ql\qnatural\pardirnatural +\ls14\ilvl0 +\b \cf0 {\listtext \'95 }drawInfo.m\ +\ +\pard\tx940\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li1440\fi-1440\ql\qnatural\pardirnatural +\ls15\ilvl1 +\i\b0 \cf0 {\listtext \'95 } +\i0 \CocoaLigature0 This class makes use of both GLCheck and GLString to creates and maintain a texture with the strings describing the capabilities of the graphics card.\ +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural +\cf0 \CocoaLigature1 \ + +\b References:\ +\ +\pard\tx220\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li720\fi-720\ql\qnatural\pardirnatural +\ls16\ilvl0\cf0 OpenGL and Cocoa:\ +\ +{\listtext \'95 }{\field{\*\fldinst{HYPERLINK "http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/"}}{\fldrslt OpenGL Programming Guide for Mac OS X}}\ +\pard\tx220\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li720\fi-720\ql\qnatural\pardirnatural +\ls16\ilvl0 +\b0 \cf0 {\listtext \'95 }{\field{\*\fldinst{HYPERLINK "http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSOpenGLView_Class/index.html"}}{\fldrslt NSOpenGLView Class Reference}}\ +{\listtext \'95 }{\field{\*\fldinst{HYPERLINK "http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSOpenGLPixelFormat_Class/index.html"}}{\fldrslt NSOpenGLPixelFormat Class Reference}}\ +{\listtext \'95 }{\field{\*\fldinst{HYPERLINK "http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSOpenGLContext_Class/index.html"}}{\fldrslt NSOpenGLContext Class Reference}}\ +\ +\pard\tx220\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li720\fi-720\ql\qnatural\pardirnatural +\ls16\ilvl0 +\b \cf0 Events and the Run Loop: +\b0 \ +\ +\pard\tx220\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li720\fi-720\ql\qnatural\pardirnatural +\ls17\ilvl0\cf0 {\listtext \'95 }{\field{\*\fldinst{HYPERLINK "http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/index.html"}}{\fldrslt Cocoa Event-Handling Guide}}\ +{\listtext \'95 }{\field{\*\fldinst{HYPERLINK "http://developer.apple.com/documentation/Cocoa/Conceptual/InputControl/index.html"}}{\fldrslt Run Loops}}\ +\ +\pard\tx220\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li720\fi-720\ql\qnatural\pardirnatural +\ls18\ilvl0 +\b \cf0 Objective-C: +\b0 \ +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural +\cf0 \ +\pard\tx220\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li720\fi-720\ql\qnatural\pardirnatural +\ls19\ilvl0\cf0 {\listtext \'95 }{\field{\*\fldinst{HYPERLINK "http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/index.html"}}{\fldrslt The Objective-C Programming Language}}\ +\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural +\cf0 \ +} \ No newline at end of file diff --git a/CocoaGL/drawInfo.h b/CocoaGL/drawInfo.h new file mode 100755 index 00000000..96a5f60f --- /dev/null +++ b/CocoaGL/drawInfo.h @@ -0,0 +1,58 @@ +// +// File: drawInfo.h +// +// Abstract: Creates and maintains the texture with the strings describing +// the capabilities of the graphics card. +// +// Version: 1.1 - updated list of extensions and minor mostly cosmetic fixes. +// 1.0 - Original release. +// +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") +// in consideration of your agreement to the following terms, and your use, +// installation, modification or redistribution of this Apple software +// constitutes acceptance of these terms. If you do not agree with these +// terms, please do not use, install, modify or redistribute this Apple +// software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non - exclusive +// license, under Apple's copyrights in this original Apple software ( the +// "Apple Software" ), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and / or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following text +// and disclaimers in all such redistributions of the Apple Software. Neither +// the name, trademarks, service marks or logos of Apple Inc. may be used to +// endorse or promote products derived from the Apple Software without specific +// prior written permission from Apple. Except as expressly stated in this +// notice, no other rights or licenses, express or implied, are granted by +// Apple herein, including but not limited to any patent rights that may be +// infringed by your derivative works or by other works in which the Apple +// Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO +// WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED +// WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION +// ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +// CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION +// AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER +// UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR +// OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright ( C ) 2003-2007 Apple Inc. All Rights Reserved. +// + + +#import + +// call after OpenGL caps are found +void initCapsTexture (GLCaps * displayCaps, CGDisplayCount numDisplays); + +// get NSString with caps for this renderer +void drawCaps (GLCaps * displayCaps, CGDisplayCount numDisplays, long renderer, GLfloat width); // view width for drawing location diff --git a/CocoaGL/drawInfo.m b/CocoaGL/drawInfo.m new file mode 100755 index 00000000..91413dcb --- /dev/null +++ b/CocoaGL/drawInfo.m @@ -0,0 +1,729 @@ +// +// File: drawInfo.m +// +// Abstract: Creates and maintains the texture with the strings describing +// the capabilities of the graphics card. +// +// Version: 1.1 - updated list of extensions and minor mostly cosmetic fixes. +// 1.0 - Original release. +// +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") +// in consideration of your agreement to the following terms, and your use, +// installation, modification or redistribution of this Apple software +// constitutes acceptance of these terms. If you do not agree with these +// terms, please do not use, install, modify or redistribute this Apple +// software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non - exclusive +// license, under Apple's copyrights in this original Apple software ( the +// "Apple Software" ), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and / or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following text +// and disclaimers in all such redistributions of the Apple Software. Neither +// the name, trademarks, service marks or logos of Apple Inc. may be used to +// endorse or promote products derived from the Apple Software without specific +// prior written permission from Apple. Except as expressly stated in this +// notice, no other rights or licenses, express or implied, are granted by +// Apple herein, including but not limited to any patent rights that may be +// infringed by your derivative works or by other works in which the Apple +// Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO +// WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED +// WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION +// ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +// CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION +// AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER +// UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR +// OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright ( C ) 2003-2007 Apple Inc. All Rights Reserved. +// + +#import "GLCheck.h" +#import "GLString.h" +#import "drawInfo.h" + +NSMutableArray *capsTextures; + +void initCapsTexture (GLCaps * displayCaps, CGDisplayCount numDisplays) +{ + short theIndex; + [capsTextures release]; + capsTextures = NULL; + capsTextures = [NSMutableArray arrayWithCapacity: numDisplays]; + [capsTextures retain]; + + // draw info + NSMutableDictionary *bold12Attribs = [NSMutableDictionary dictionary]; + [bold12Attribs setObject: [NSFont fontWithName: @"Helvetica-Bold" size: 12.0f] forKey: NSFontAttributeName]; + [bold12Attribs setObject: [NSColor whiteColor] forKey: NSForegroundColorAttributeName]; + + NSMutableDictionary *bold9Attribs = [NSMutableDictionary dictionary]; + [bold9Attribs setObject: [NSFont fontWithName: @"Helvetica-Bold" size: 9.0f] forKey: NSFontAttributeName]; + [bold9Attribs setObject: [NSColor whiteColor] forKey: NSForegroundColorAttributeName]; + + NSMutableDictionary *normal9Attribs = [NSMutableDictionary dictionary]; + [normal9Attribs setObject: [NSFont fontWithName: @"Helvetica" size: 9.0f] forKey: NSFontAttributeName]; + [normal9Attribs setObject: [NSColor whiteColor] forKey: NSForegroundColorAttributeName]; + + for (theIndex = 0; theIndex < numDisplays; theIndex++) { + NSMutableAttributedString * outString, * appendString; + GLString *capsTexture; + + // draw caps string + outString = [[[NSMutableAttributedString alloc] initWithString:@"GL Capabilities:" attributes:bold12Attribs] autorelease]; + + appendString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"\n Max VRAM- %ld MB (%ld MB free)", displayCaps[theIndex].deviceVRAM / 1024 / 1024, displayCaps[theIndex].deviceTextureRAM / 1024 / 1024] attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + + appendString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"\n Max Texture Size- 1D/2D: %ld, 3D: %ld, Cube: %ld, Rect: %ld (%ld texture units)", displayCaps[theIndex].maxTextureSize, displayCaps[theIndex].max3DTextureSize, displayCaps[theIndex].maxCubeMapTextureSize, displayCaps[theIndex].maxRectTextureSize, displayCaps[theIndex].textureUnits] attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Features:" attributes:bold9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + + if (displayCaps[theIndex].fAuxDeptStencil) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Aux depth and stencil (GL_APPLE_aux_depth_stencil)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fClientStorage) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Client Storage (GL_APPLE_client_storage)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fElementArray) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Element Array (GL_APPLE_element_array)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fFence) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Fence (GL_APPLE_fence)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fFloatPixels) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Floating Point Pixels (GL_APPLE_float_pixels)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fFlushBufferRange) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Selective VBO flushing (GL_APPLE_flush_buffer_range)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fFlushRenderer) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Flush Renderer (GL_APPLE_flush_render)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fObjectPurgeable) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Object Purgeability (GL_APPLE_object_purgeable)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fPackedPixels) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Packed Pixels (GL_APPLE_packed_pixels or OpenGL 1.2+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fPixelBuffer) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Pixel Buffers (GL_APPLE_pixel_buffer)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fSpecularVector) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Specular Vector (GL_APPLE_specular_vector)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTextureRange) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Range (AGP Texturing) (GL_APPLE_texture_range)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTransformHint) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Transform Hint (GL_APPLE_transform_hint)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fVAO) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Vertex Array Object (GL_APPLE_vertex_array_object)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fVAR) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Vertex Array Range (GL_APPLE_vertex_array_range)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fVPEvals) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Vertex Program Evaluators (GL_APPLE_vertex_program_evaluators)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fYCbCr) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n YCbCr Textures (GL_APPLE_ycbcr_422)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fDepthTex) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Depth Texture (GL_ARB_depth_texture or OpenGL 1.4+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fDrawBuffers) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Multiple Render Targets (GL_ARB_draw_buffers or OpenGL 2.0+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fFragmentProg) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Fragment Program (GL_ARB_fragment_program)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fFragmentProgShadow) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Fragment Program Shadows (GL_ARB_fragment_program_shadow)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fFragmentShader) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Fragment Shaders (GL_ARB_fragment_shader or OpenGL 2.0+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fHalfFloatPixel) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Half Float Pixels (GL_ARB_half_float_pixel)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fImaging) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Imaging Subset (GL_ARB_imaging)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fMultisample) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Multisample (Anti-aliasing) (GL_ARB_multisample or OpenGL 1.3+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fMultitexture) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Multitexture (GL_ARB_multitexture or OpenGL 1.3+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fOcclusionQuery) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Occlusion Queries (GL_ARB_occlusion_query or OpenGL 1.5+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fPBO) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Pixel Buffer Objects (GL_ARB_pixel_buffer_object or OpenGL 2.1+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fPointParam) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Point Parameters (GL_ARB_point_parameters or OpenGL 1.4+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fPointSprite) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Point Sprites (GL_ARB_point_sprite or OpenGL 2.0+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fShaderObjects) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Shader Objects (GL_ARB_shader_objects or OpenGL 2.0+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fShaderTextureLOD) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Shader Texture LODs (GL_ARB_shader_texture_lod)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fShadingLanguage100) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Shading Language 1.0 (GL_ARB_shading_language_100 or OpenGL 2.0+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fShadow) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Shadow Support (GL_ARB_shadow or OpenGL 1.4+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fShadowAmbient) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Shadow Ambient (GL_ARB_shadow_ambient)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexBorderClamp) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Border Clamp (GL_ARB_texture_border_clamp or OpenGL 1.3+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexCompress) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Compression (GL_ARB_texture_compression or OpenGL 1.3+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexCubeMap) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Env Cube Map (GL_ARB_texture_cube_map or OpenGL 1.4+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexEnvAdd) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Env Add (GL_ARB_texture_env_add, GL_EXT_texture_env_add or OpenGL 1.3+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexEnvCombine) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Env Combine (GL_ARB_texture_env_combine or OpenGL 1.3+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexEnvCrossbar) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Env Crossbar (GL_ARB_texture_env_crossbar or OpenGL 1.4+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexEnvDot3) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Env Dot3 (GL_ARB_texture_env_dot3 or OpenGL 1.3+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexFloat) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Floating Point Textures (GL_ARB_texture_float)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexMirrorRepeat) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Mirrored Repeat (GL_ARB_texture_mirrored_repeat or OpenGL 1.4+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexNPOT) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Non Power of Two Textures (GL_ARB_texture_non_power_of_two or OpenGL 2.0+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexRectARB) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Rectangle (GL_ARB_texture_rectangle)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTransposeMatrix) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Transpose Matrix (GL_ARB_transpose_matrix or OpenGL 1.3+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fVertexBlend) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Vertex Blend (GL_ARB_vertex_blend)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fVBO) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Vertex Buffer Objects (GL_ARB_vertex_buffer_object or OpenGL 1.5+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fVertexProg) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Vertex Program (GL_ARB_vertex_program)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fVertexShader) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Vertex Shaders (GL_ARB_vertex_shader or OpenGL 2.0+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fWindowPos) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Window Position (GL_ARB_window_pos or OpenGL 1.4+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fArrayRevComps4Byte) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Reverse 4 Byte Array Components (GL_ATI_array_rev_comps_in_4_bytes)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fATIBlendEqSep) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Separate Blend Equations (GL_ATI_blend_equation_separate)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fBlendWeightMinMax) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Blend Weighted Min/Max (GL_ATI_blend_weighted_minmax)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fPNtriangles) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n PN Triangles (GL_ATI_pn_triangles or GL_ATIX_pn_triangles)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fPointCull) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Point Culling (GL_ATI_point_cull_mode)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fSepStencil) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Separate Stencil (GL_ATI_separate_stencil)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTextFragShader) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Text Fragment Shader (GL_ATI_text_fragment_shader)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexComp3dc) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n ATI 3dc Compressed Textures (GL_ATI_texture_compression_3dc)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fCombine3) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Env Combine 3 (GL_ATI_texture_env_combine3)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexATIfloat) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n ATI Floating Point Textures (GL_ATI_texture_float)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexMirrorOnce) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Mirror Once (GL_ATI_texture_mirror_once)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fABGR) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n ABGR Texture Support (GL_EXT_abgr)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fBGRA) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n BGRA Texture Support (GL_EXT_bgra or OpenGL 1.2+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fBlendColor) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Blend Color (GL_EXT_blend_color or GL_ARB_imaging)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fBlendEqSep) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Separate Blending Equations for RGB and Alpha (GL_EXT_blend_equation_separate or OpenGL 2.0+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fBlendFuncSep) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Separate Blend Function (GL_EXT_blend_func_separate or OpenGL 1.4+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fBlendMinMax) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Blend Min/Max (GL_EXT_blend_minmax or GL_ARB_imaging)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fBlendSub) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Blend Subtract (GL_EXT_blend_subtract or GL_ARB_imaging)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fClipVolHint) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Clip Volume Hint (GL_EXT_clip_volume_hint)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fColorSubtable) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Color Subtable ( GL_EXT_color_subtable or GL_ARB_imaging)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fCVA) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Compiled Vertex Array (GL_EXT_compiled_vertex_array)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fDepthBounds) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Depth Boundary Test (GL_EXT_depth_bounds_test)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fConvolution) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Convolution ( GL_EXT_convolution or GL_ARB_imaging)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fDrawRangeElements) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Draw Range Elements (GL_EXT_draw_range_elements)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fFogCoord) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Fog Coordinate (GL_EXT_fog_coord)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fFBOblit) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n FBO Blit (GL_EXT_framebuffer_blit)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fFBO) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Framebuffer Objects or FBOs (GL_EXT_framebuffer_object)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fGeometryShader4) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n 4th Gen Geometry Shader (GL_EXT_geometry_shader4)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fGPUProgParams) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n GPU Program Parameters (GL_EXT_gpu_program_parameters)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fGPUShader4) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n 4th Gen GPU Shaders (GL_EXT_gpu_shader4)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fHistogram) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Histogram ( GL_EXT_histogram or GL_ARB_imaging)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fDepthStencil) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Packed Depth and Stencil (GL_EXT_packed_depth_stencil)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fMultiDrawArrays) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Multi-Draw Arrays (GL_EXT_multi_draw_arrays or OpenGL 1.4+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fPaletteTex) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Paletted Textures (GL_EXT_paletted_texture)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fRescaleNorm) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Rescale Normal (GL_EXT_rescale_normal or OpenGL 1.2+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fSecColor) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Secondary Color (GL_EXT_secondary_color or OpenGL 1.4+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fSepSpecColor) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Separate Specular Color (GL_EXT_separate_specular_color or OpenGL 1.2+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fShadowFunc) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Shadow Function (GL_EXT_shadow_funcs)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fShareTexPalette) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Shared Texture Palette (GL_EXT_shared_texture_palette)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fStencil2Side) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n 2-Sided Stencil (GL_EXT_stencil_two_side)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fStencilWrap) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Stencil Wrap (GL_EXT_stencil_wrap or OpenGL 1.4+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexCompDXT1) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n DXT Compressed Textures (GL_EXT_texture_compression_dxt1)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTex3D) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n 3D Texturing (GL_EXT_texture3D or OpenGL 1.2+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexCompressS3TC) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Compression S3TC (GL_EXT_texture_compression_s3tc)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexFilterAniso) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Anisotropic Texture Filtering (GL_EXT_texture_filter_anisotropic)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexLODBias) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Level Of Detail Bias (GL_EXT_texture_lod_bias or OpenGL 1.4+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexMirrorClamp) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture mirror clamping (GL_EXT_texture_mirror_clamp)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexRect) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Rectangle (GL_EXT_texture_rectangle)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexSRGB) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n sRGB Textures (GL_EXT_texture_sRGB or OpenGL 2.1+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTransformFeedback) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Transform Feedback (GL_EXT_transform_feedback)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fConvBorderModes) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Convolution Border Modes (GL_HP_convolution_border_modes or GL_ARB_imaging)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fRasterPosClip) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Raster Position Clipping (GL_IBM_rasterpos_clip)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fBlendSquare) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Blend Square (GL_NV_blend_square or OpenGL 1.4+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fDepthClamp) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Depth Clamp (GL_NV_depth_clamp)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fFogDist) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Eye Radial Fog Distance (GL_NV_fog_distance)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fLightMaxExp) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Light Max Exponent (GL_NV_light_max_exponent)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fMultisampleFilterHint) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Multi-Sample Filter Hint (GL_NV_multisample_filter_hint)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fNVPointSprite) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n NV Point Sprites (GL_NV_point_sprite)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fRegCombiners) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Register Combiners (GL_NV_register_combiners)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fRegCombiners2) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Register Combiners 2 (GL_NV_register_combiners2)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexGenReflect) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n TexGen Reflection (GL_NV_texgen_reflection)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexEnvCombine4) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Env Combine 4 (GL_NV_texture_env_combine4)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexShader) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Shader (GL_NV_texture_shader)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexShader2) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Shader 2 (GL_NV_texture_shader2)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexShader3) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Shader 3 (GL_NV_texture_shader3)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fGenMipmap) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n MipMap Generation (GL_SGIS_generate_mipmap or OpenGL 1.4+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexEdgeClamp) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Edge Clamp (GL_SGIS_texture_edge_clamp or OpenGL 1.2+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fTexLOD) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Texture Level Of Detail (GL_SGIS_texture_lod or OpenGL 1.2+)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fColorMatrix) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Color Matrix ( GL_SGI_color_matrix or GL_ARB_imaging)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + if (displayCaps[theIndex].fColorTable) { + appendString = [[NSMutableAttributedString alloc] initWithString:@"\n Color Table ( GL_SGI_color_table or GL_ARB_imaging)" attributes:normal9Attribs]; + [outString appendAttributedString:appendString]; + [appendString release]; + } + + capsTexture = [[GLString alloc] initWithAttributedString:outString withTextColor:[NSColor colorWithDeviceRed:1.0f green:1.0f blue:1.0f alpha:1.0f] withBoxColor:[NSColor colorWithDeviceRed:0.4f green:0.4f blue:0.0f alpha:0.4f] withBorderColor:[NSColor colorWithDeviceRed:0.8f green:0.8f blue:0.0f alpha:0.8f]]; + [capsTextures addObject:capsTexture]; + [capsTexture release]; + } +} + +// get NSString with caps for this renderer +void drawCaps (GLCaps * displayCaps, CGDisplayCount numDisplays, long renderer, GLfloat width) // view width for drawing location +{ // we are already in an orthographic per pixel projection + short i; + // match display in caps list + for (i = 0; i < numDisplays; i++) { + if (renderer == displayCaps[i].rendererID) { + GLString *capsTexture = [capsTextures objectAtIndex:i]; + [capsTexture drawAtPoint:NSMakePoint (width - 10.0f - [capsTexture frameSize].width, 10.0f)]; + break; + } + } +} + /* + return outString; + */ diff --git a/CocoaGL/main.m b/CocoaGL/main.m new file mode 100644 index 00000000..45853498 --- /dev/null +++ b/CocoaGL/main.m @@ -0,0 +1,51 @@ +// +// File: main.m +// +// Version: 1.0 - Original release. +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") +// in consideration of your agreement to the following terms, and your use, +// installation, modification or redistribution of this Apple software +// constitutes acceptance of these terms. If you do not agree with these +// terms, please do not use, install, modify or redistribute this Apple +// software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non - exclusive +// license, under Apple's copyrights in this original Apple software ( the +// "Apple Software" ), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and / or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following text +// and disclaimers in all such redistributions of the Apple Software. Neither +// the name, trademarks, service marks or logos of Apple Inc. may be used to +// endorse or promote products derived from the Apple Software without specific +// prior written permission from Apple. Except as expressly stated in this +// notice, no other rights or licenses, express or implied, are granted by +// Apple herein, including but not limited to any patent rights that may be +// infringed by your derivative works or by other works in which the Apple +// Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO +// WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED +// WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION +// ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +// CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION +// AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER +// UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR +// OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright ( C ) 2003-2007 Apple Inc. All Rights Reserved. +// + +#import + +int main(int argc, char *argv[]) +{ + return NSApplicationMain(argc, (const char **) argv); +} diff --git a/CocoaGL/trackball.c b/CocoaGL/trackball.c new file mode 100755 index 00000000..3d34ade7 --- /dev/null +++ b/CocoaGL/trackball.c @@ -0,0 +1,214 @@ +// +// File: trackball.c +// +// Abstract: Implements a trackball like camera system +// +// Version: 1.1 - minor fixes. +// 1.0 - Original release. +// +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") +// in consideration of your agreement to the following terms, and your use, +// installation, modification or redistribution of this Apple software +// constitutes acceptance of these terms. If you do not agree with these +// terms, please do not use, install, modify or redistribute this Apple +// software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non - exclusive +// license, under Apple's copyrights in this original Apple software ( the +// "Apple Software" ), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and / or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following text +// and disclaimers in all such redistributions of the Apple Software. Neither +// the name, trademarks, service marks or logos of Apple Inc. may be used to +// endorse or promote products derived from the Apple Software without specific +// prior written permission from Apple. Except as expressly stated in this +// notice, no other rights or licenses, express or implied, are granted by +// Apple herein, including but not limited to any patent rights that may be +// infringed by your derivative works or by other works in which the Apple +// Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO +// WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED +// WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION +// ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +// CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION +// AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER +// UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR +// OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright ( C ) 2000-2007 Apple Inc. All Rights Reserved. +// + +#include "trackball.h" + +#include + +static const float kTol = 0.001; +static const float kRad2Deg = 180. / 3.1415927; +static const float kDeg2Rad = 3.1415927 / 180.; + +float gRadiusTrackball; +float gStartPtTrackball[3]; +float gEndPtTrackball[3]; +long gXCenterTrackball = 0, gYCenterTrackball = 0; + +// mouse positon and view size as inputs +void startTrackball (long x, long y, long originX, long originY, long width, long height) +{ + float xxyy; + float nx, ny; + + /* Start up the trackball. The trackball works by pretending that a ball + encloses the 3D view. You roll this pretend ball with the mouse. For + example, if you click on the center of the ball and move the mouse straight + to the right, you roll the ball around its Y-axis. This produces a Y-axis + rotation. You can click on the "edge" of the ball and roll it around + in a circle to get a Z-axis rotation. + + The math behind the trackball is simple: start with a vector from the first + mouse-click on the ball to the center of the 3D view. At the same time, set the radius + of the ball to be the smaller dimension of the 3D view. As you drag the mouse + around in the 3D view, a second vector is computed from the surface of the ball + to the center. The axis of rotation is the cross product of these two vectors, + and the angle of rotation is the angle between the two vectors. + */ + nx = width; + ny = height; + if (nx > ny) + gRadiusTrackball = ny * 0.5; + else + gRadiusTrackball = nx * 0.5; + // Figure the center of the view. + gXCenterTrackball = originX + width * 0.5; + gYCenterTrackball = originY + height * 0.5; + + // Compute the starting vector from the surface of the ball to its center. + gStartPtTrackball [0] = x - gXCenterTrackball; + gStartPtTrackball [1] = y - gYCenterTrackball; + xxyy = gStartPtTrackball [0] * gStartPtTrackball[0] + gStartPtTrackball [1] * gStartPtTrackball [1]; + if (xxyy > gRadiusTrackball * gRadiusTrackball) { + // Outside the sphere. + gStartPtTrackball[2] = 0.; + } else + gStartPtTrackball[2] = sqrt (gRadiusTrackball * gRadiusTrackball - xxyy); + +} + +// update to new mouse position, output rotation angle +void rollToTrackball (long x, long y, float rot [4]) // rot is output rotation angle +{ + float xxyy; + float cosAng, sinAng; + float ls, le, lr; + + gEndPtTrackball[0] = x - gXCenterTrackball; + gEndPtTrackball[1] = y - gYCenterTrackball; + if (fabs (gEndPtTrackball [0] - gStartPtTrackball [0]) < kTol && fabs (gEndPtTrackball [1] - gStartPtTrackball [1]) < kTol) + return; // Not enough change in the vectors to have an action. + + // Compute the ending vector from the surface of the ball to its center. + xxyy = gEndPtTrackball [0] * gEndPtTrackball [0] + gEndPtTrackball [1] * gEndPtTrackball [1]; + if (xxyy > gRadiusTrackball * gRadiusTrackball) { + // Outside the sphere. + gEndPtTrackball [2] = 0.; + } else + gEndPtTrackball[ 2] = sqrt (gRadiusTrackball * gRadiusTrackball - xxyy); + + // Take the cross product of the two vectors. r = s X e + rot[1] = gStartPtTrackball[1] * gEndPtTrackball[2] - gStartPtTrackball[2] * gEndPtTrackball[1]; + rot[2] = -gStartPtTrackball[0] * gEndPtTrackball[2] + gStartPtTrackball[2] * gEndPtTrackball[0]; + rot[3] = gStartPtTrackball[0] * gEndPtTrackball[1] - gStartPtTrackball[1] * gEndPtTrackball[0]; + + // Use atan for a better angle. If you use only cos or sin, you only get + // half the possible angles, and you can end up with rotations that flip around near + // the poles. + + // cos(a) = (s . e) / (||s|| ||e||) + cosAng = gStartPtTrackball[0] * gEndPtTrackball[0] + gStartPtTrackball[1] * gEndPtTrackball[1] + gStartPtTrackball[2] * gEndPtTrackball[2]; // (s . e) + ls = sqrt(gStartPtTrackball[0] * gStartPtTrackball[0] + gStartPtTrackball[1] * gStartPtTrackball[1] + gStartPtTrackball[2] * gStartPtTrackball[2]); + ls = 1. / ls; // 1 / ||s|| + le = sqrt(gEndPtTrackball[0] * gEndPtTrackball[0] + gEndPtTrackball[1] * gEndPtTrackball[1] + gEndPtTrackball[2] * gEndPtTrackball[2]); + le = 1. / le; // 1 / ||e|| + cosAng = cosAng * ls * le; + + // sin(a) = ||(s X e)|| / (||s|| ||e||) + sinAng = lr = sqrt(rot[1] * rot[1] + rot[2] * rot[2] + rot[3] * rot[3]); // ||(s X e)||; + // keep this length in lr for normalizing the rotation vector later. + sinAng = sinAng * ls * le; + rot[0] = (float) atan2 (sinAng, cosAng) * kRad2Deg; // GL rotations are in degrees. + + // Normalize the rotation axis. + lr = 1. / lr; + rot[1] *= lr; rot[2] *= lr; rot[3] *= lr; + + // returns rotate +} + +static void rotation2Quat (float *A, float *q) +{ + float ang2; // The half-angle + float sinAng2; // sin(half-angle) + + // Convert a GL-style rotation to a quaternion. The GL rotation looks like this: + // {angle, x, y, z}, the corresponding quaternion looks like this: + // {{v}, cos(angle/2)}, where {v} is {x, y, z} / sin(angle/2). + + ang2 = A[0] * kDeg2Rad * 0.5; // Convert from degrees ot radians, get the half-angle. + sinAng2 = sin(ang2); + q[0] = A[1] * sinAng2; q[1] = A[2] * sinAng2; q[2] = A[3] * sinAng2; + q[3] = cos(ang2); +} + +void addToRotationTrackball (float * dA, float * A) +{ + float q0[4], q1[4], q2[4]; + float theta2, sinTheta2; + + // Figure out A' = A . dA + // In quaternions: let q0 <- A, and q1 <- dA. + // Figure out q2 = q1 + q0 (note the order reversal!). + // A' <- q3. + + rotation2Quat(A, q0); + rotation2Quat(dA, q1); + + // q2 = q1 + q0; + q2[0] = q1[1]*q0[2] - q1[2]*q0[1] + q1[3]*q0[0] + q1[0]*q0[3]; + q2[1] = q1[2]*q0[0] - q1[0]*q0[2] + q1[3]*q0[1] + q1[1]*q0[3]; + q2[2] = q1[0]*q0[1] - q1[1]*q0[0] + q1[3]*q0[2] + q1[2]*q0[3]; + q2[3] = q1[3]*q0[3] - q1[0]*q0[0] - q1[1]*q0[1] - q1[2]*q0[2]; + // Here's an excersize for the reader: it's a good idea to re-normalize your quaternions + // every so often. Experiment with different frequencies. + + // An identity rotation is expressed as rotation by 0 about any axis. + // The "angle" term in a quaternion is really the cosine of the half-angle. + // So, if the cosine of the half-angle is one (or, 1.0 within our tolerance), + // then you have an identity rotation. + if (fabs(fabs(q2[3] - 1.)) < 1.0e-7) { + // Identity rotation. + A[0] = 0.0f; + A[1] = 1.0f; + A[2] = A[3] = 0.0f; + return; + } + + // If you get here, then you have a non-identity rotation. In non-identity rotations, + // the cosine of the half-angle is non-0, which means the sine of the angle is also + // non-0. So we can safely divide by sin(theta2). + + // Turn the quaternion back into an {angle, {axis}} rotation. + theta2 = (float) acos (q2[3]); + sinTheta2 = (float) (1.0 / sin ((double) theta2)); + A[0] = theta2 * 2.0f * kRad2Deg; + A[1] = q2[0] * sinTheta2; + A[2] = q2[1] * sinTheta2; + A[3] = q2[2] * sinTheta2; +} diff --git a/CocoaGL/trackball.h b/CocoaGL/trackball.h new file mode 100755 index 00000000..999f9fce --- /dev/null +++ b/CocoaGL/trackball.h @@ -0,0 +1,70 @@ +// +// File: trackball.h +// +// Abstract: Implements a trackball like camera system +// +// Version: 1.1 - minor fixes. +// 1.0 - Original release. +// +// +// Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") +// in consideration of your agreement to the following terms, and your use, +// installation, modification or redistribution of this Apple software +// constitutes acceptance of these terms. If you do not agree with these +// terms, please do not use, install, modify or redistribute this Apple +// software. +// +// In consideration of your agreement to abide by the following terms, and +// subject to these terms, Apple grants you a personal, non - exclusive +// license, under Apple's copyrights in this original Apple software ( the +// "Apple Software" ), to use, reproduce, modify and redistribute the Apple +// Software, with or without modifications, in source and / or binary forms; +// provided that if you redistribute the Apple Software in its entirety and +// without modifications, you must retain this notice and the following text +// and disclaimers in all such redistributions of the Apple Software. Neither +// the name, trademarks, service marks or logos of Apple Inc. may be used to +// endorse or promote products derived from the Apple Software without specific +// prior written permission from Apple. Except as expressly stated in this +// notice, no other rights or licenses, express or implied, are granted by +// Apple herein, including but not limited to any patent rights that may be +// infringed by your derivative works or by other works in which the Apple +// Software may be incorporated. +// +// The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO +// WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED +// WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A +// PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION +// ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +// CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION +// AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER +// UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR +// OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Copyright ( C ) 2000-2007 Apple Inc. All Rights Reserved. +// + +#ifndef __trackball_h__ +#define __trackball_h__ + +#ifdef __cplusplus +extern "C" { +#endif + +// called with the start position and the window origin + size +void startTrackball (long x, long y, long originX, long originY, long width, long height); + +// calculated rotation based on current mouse position +void rollToTrackball (long x, long y, float rot [4]); // rot is output rotation angle + +// add a GL rotation (dA) to an existing GL rotation (A) +void addToRotationTrackball (float * dA, float * A); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file