diff options
-rw-r--r-- | src/AGL_DSp.cpp | 235 | ||||
-rw-r--r-- | src/AGL_DSp.h | 36 | ||||
-rw-r--r-- | src/Alerts.cpp | 89 | ||||
-rw-r--r-- | src/Alerts.h | 40 |
4 files changed, 0 insertions, 400 deletions
diff --git a/src/AGL_DSp.cpp b/src/AGL_DSp.cpp deleted file mode 100644 index 8e86b0a..0000000 --- a/src/AGL_DSp.cpp +++ /dev/null @@ -1,235 +0,0 @@ -/**> HEADER FILES <**/ -#include "AGL_DSp.h" -#include "Alerts.h" - -/**> GLOBAL VARIABLES <**/ -DSpContextAttributes gDSpContextAttributes; // Global DrawSprocket context attributes -DSpContextReference gDSpContext; // The global DrawSprocket context -AGLContext gOpenGLContext; // The global OpenGL (AGL) context - -/********************> ToolboxInit() <*****/ -void ToolboxInit( void ) -{ - MaxApplZone(); - - InitGraf( &qd.thePort ); - InitFonts(); - InitWindows(); - InitMenus(); - TEInit(); - InitDialogs( 0L ); - InitCursor(); -} - -/********************> HasAppearance() <*****/ -Boolean HasAppearance( void ) -{ - - OSErr error; - SInt32 response; - Boolean appearancePresent = false; - Boolean appearance101present = false; - Boolean appearance110present = false; - Boolean inCompatibilityMode = false; - - error = Gestalt( gestaltAppearanceAttr, &response ); - - // If Gestalt returns no error and the bit in response represented by the constant - // gestaltAppearanceExists is set, proceed, otherwise exit with an error message. - - if ( error == noErr && ( BitTst( &response, 31 - gestaltAppearanceExists ) ) ) - { - // At least Version 1.0 is present. Set a flag. - appearancePresent = true; - - // If the bit in response represented by the constant gestaltAppearanceCompatMode - // is set, system-wide Appearance is off. The result of this check will be - // relevant only where Versions 1.0 through 1.0.3 are present. - if( BitTst( &response, 31 - gestaltAppearanceCompatMode ) ) - inCompatibilityMode = true; - - // Call Gestalt again with the gestaltAppearanceVersion selector. - Gestalt( gestaltAppearanceVersion, &response ); - - // If the low order word in response is 0x0101, Version 1.0.1, 1.0.2, or 1.0.3 is - // present. If the low order word in response is 0x0110, Version 1.1 is available. - if( response == 0x00000101 ) - appearance101present = true; - else if( response == 0x00000110 ) - appearance110present = true; - } - /*else - { - StopAlert( kNoAppearanceAlert, nil ); - ExitToShell(); - }*/ - - // Register this app as an Appearance Client - //RegisterAppearanceClient(); - - return appearancePresent; - -} - -/********************> SetupScreen() <*****/ -CGrafPtr SetupScreen( int width, int height ) -{ - - OSStatus theError; - CGrafPtr theFrontBuffer; - - // Start DrawSprocket - theError = DSpStartup(); - if( theError ) - FatalErrorAlert( kErr_DSpStartupFailed, theError ); - - // Set the Context Attributes - gDSpContextAttributes.displayWidth = width; - gDSpContextAttributes.displayHeight = height; - gDSpContextAttributes.colorNeeds = kDSpColorNeeds_Require; - gDSpContextAttributes.displayDepthMask = kDSpDepthMask_32; - gDSpContextAttributes.backBufferDepthMask = kDSpDepthMask_32; - gDSpContextAttributes.displayBestDepth = 32; - gDSpContextAttributes.backBufferBestDepth = 32; - gDSpContextAttributes.pageCount = 1; - - // Find the best context for our attributes - theError = DSpFindBestContext( &gDSpContextAttributes, &gDSpContext ); - if( theError != noErr ) - FatalErrorAlert( kErr_DSpFindBestContextFailed, theError ); // This function is in my Alerts.cpp - - // Reserve that context - theError = DSpContext_Reserve( gDSpContext, &gDSpContextAttributes ); - if( theError != noErr ) - FatalErrorAlert( kErr_DSpContext_ReserveFailed, theError ); - - // Fade out - theError = DSpContext_FadeGammaOut( NULL, NULL ); - if( theError != noErr ) - FatalErrorAlert( kErr_DSpFadeFailed, theError ); - - // Activate the context - theError = DSpContext_SetState( gDSpContext, kDSpContextState_Active ); - if( theError != noErr ) - { - // Fade back in the display before dying - theError = DSpContext_FadeGammaIn( NULL, NULL ); - - // Now do the fatal error alert - FatalErrorAlert( kErr_ActivateContextFailed, theError ); - } - - // Fade in - theError = DSpContext_FadeGammaIn( NULL, NULL ); - if( theError != noErr ) - FatalErrorAlert( kErr_DSpFadeFailed, theError ); - - // Create a window to draw in - CreateWindow( theFrontBuffer, width, height ); - - return theFrontBuffer; - -} - -/********************> CreateWindow() <*****/ -void CreateWindow( CGrafPtr &theFrontBuffer, int width, int height ) -{ - - Rect rect; - AuxWinHandle awh; - CTabHandle theColorTable; - OSErr error; - RGBColor backColor = { 0xFFFF, 0xFFFF, 0xFFFF }; - RGBColor foreColor = { 0x0000, 0x0000, 0x0000 }; - - // Set the window rect - rect.top = rect.left = 0; - DSpContext_LocalToGlobal( gDSpContext, ( Point* )&rect ); - rect.right = rect.left + width; - rect.bottom = rect.top + height; - - // Create a new color window - theFrontBuffer = ( CGrafPtr )NewCWindow( NULL, &rect, "\p", 0, plainDBox, kMoveToFront, 0, 0 ); - - // set the content color of the window to black to avoid a white flash when the window appears. - if ( GetAuxWin( ( WindowPtr )theFrontBuffer, &awh ) ) - { - theColorTable = ( **awh ).awCTable; - error = HandToHand( ( Handle* )&theColorTable ); - if ( error ) - DebugStr( "\pOut of memory!" ); - - ( **theColorTable ).ctTable[wContentColor].rgb.red = 0; - ( **theColorTable ).ctTable[wContentColor].rgb.green = 0; - ( **theColorTable ).ctTable[wContentColor].rgb.blue = 0; - - CTabChanged( theColorTable ); - - // the color table will be disposed by the window manager when the window is disposed - SetWinColor( ( WindowPtr )theFrontBuffer, ( WCTabHandle )theColorTable ); - } - - // Show the window - ShowWindow( ( GrafPtr )theFrontBuffer ); - SetPort( ( GrafPtr )theFrontBuffer ); - - // Set current pen colors - RGBForeColor( &foreColor ); - RGBBackColor( &backColor ); - -} - -/********************> ShutdownScreen() <*****/ -void ShutdownScreen( CGrafPtr theFrontBuffer ) -{ - - DSpContext_FadeGammaOut( NULL, NULL ); - DisposeWindow( ( WindowPtr )theFrontBuffer ); - DSpContext_SetState( gDSpContext, kDSpContextState_Inactive ); - DSpContext_FadeGammaIn( NULL, NULL ); - DSpContext_Release( gDSpContext ); - DSpShutdown(); - -} - -/********************> SetupAGL() <*****/ -AGLContext SetupAGL( AGLDrawable window ) -{ - GLint attrib[] = { AGL_RGBA, AGL_DEPTH_SIZE, 24, AGL_DOUBLEBUFFER, AGL_NONE }; - AGLPixelFormat format; - AGLContext context; - GLboolean ok; - - // Choose an rgb pixel format - format = aglChoosePixelFormat( NULL, 0, attrib ); - if ( format == NULL ) - return NULL; - - // Create an AGL context - context = aglCreateContext( format, NULL ); - if ( context == NULL ) - return NULL; - - // Attach the window to the context - ok = aglSetDrawable( context, window ); - if ( !ok ) - return NULL; - - // Make the context the current context - ok = aglSetCurrentContext( context ); - if ( !ok ) - return NULL; - - // The pixel format is no longer needed so get rid of it - aglDestroyPixelFormat( format ); - - return context; -} - -/********************> CleanupAGL() <*****/ -void CleanupAGL( AGLContext context ) -{ - aglSetCurrentContext( NULL ); - aglSetDrawable( context, NULL ); - aglDestroyContext( context ); -} diff --git a/src/AGL_DSp.h b/src/AGL_DSp.h deleted file mode 100644 index f001017..0000000 --- a/src/AGL_DSp.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#ifndef _AGL_DSP_H_ -#define _AGL_DSP_H_ - -/**> HEADER FILES <**/ -#include <stdlib.h> // ANSI C cross platform headers -#include <stdio.h> -#include <DrawSprocket.h> // DrawSprocket -#include <agl.h> // Apple's OpenGL -#include <glu.h> // Used for setting perspective and making objects -#include <tk.h> // Used for loading images - -/**> CONSTANT DECLARATIONS <**/ -#define kMoveToFront kFirstWindowOfClass - -// Screen Dimensions -#define SCREEN_WIDTH 640 -#define SCREEN_HEIGHT 480 - -/**> GLOBAL VARIABLES <**/ -extern DSpContextAttributes gDSpContextAttributes; // Global DrawSprocket context attributes -extern DSpContextReference gDSpContext; // The global DrawSprocket context -extern AGLContext gOpenGLContext; // The global OpenGL (AGL) context - // Note: These are actually defined in AGL_DSp.cpp - -/**> FUNCTION PROTOTYPES <**/ -void ToolboxInit( void ); -Boolean HasAppearance( void ); -CGrafPtr SetupScreen( int width, int height ); -void CreateWindow( CGrafPtr &theFrontBuffer, int width, int height ); -void ShutdownScreen( CGrafPtr theFrontBuffer ); -AGLContext SetupAGL( AGLDrawable window ); -void CleanupAGL( AGLContext context ); - -#endif \ No newline at end of file diff --git a/src/Alerts.cpp b/src/Alerts.cpp deleted file mode 100644 index 2e01ca9..0000000 --- a/src/Alerts.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/**> HEADER FILES <**/ -#include "Alerts.h" - -/********************> SelectResolution() <*****/ -int SelectResolution( void ) -{ - DialogPtr dialog; - Boolean dialogDone = false; - short itemHit, itemType; - Handle okItem; - Handle resolutionItem; - Rect itemRect; - int selectionNum; - - // Load the dialog - dialog = GetNewDialog( kResID_DLOG_SelectResolution, nil, kMoveToFront ); - - // Display the dialog - ShowWindow( dialog ); - SetPort( dialog ); - - // Load dialog items - SetDialogDefaultItem( dialog, iOK ); - SetDialogTracksCursor( dialog, true ); - GetDialogItem( dialog, iOK, &itemType, &okItem, &itemRect ); - GetDialogItem( dialog, iResolutionPopUp, &itemType, &resolutionItem, &itemRect ); - - // Set item values - SetControlValue( ( ControlHandle )resolutionItem, i640x480 ); - - while ( !dialogDone ) - { - - ModalDialog( nil, &itemHit ); - - switch( itemHit ) - { - case iOK: - dialogDone = true; - // Get the item number selected int the popup - selectionNum = GetControlValue( ( ControlHandle )resolutionItem ); - break; - case iResolutionPopUp: - // We don't actually need to do anything here - break; - } - - } - - DisposeDialog( dialog ); - - // Return the item selected in the popup menu - return selectionNum; -} - -/********************> MessageAlert() <*****/ -void MessageAlert( unsigned char *theMessage ) -{ - - // Set parameter ^0 to our message (I could set up to three, but for simplicity's sake I won't) - ParamText( ( unsigned char * )theMessage, NULL, NULL, NULL ); - - // Do the Alert - NoteAlert( kResID_ALRT_MessageAlert, nil ); - -} - -/********************> FatalErrorAlert() <*****/ -void FatalErrorAlert( UInt16 errorNum, OSErr osError ) -{ - - Str15 errNumStr; - Str255 mainMessage; - - // Convert the OSErr to a string - NumToString( osError, errNumStr ); - - // Get the error description (inErrorDesc) from the STR# resource - GetIndString( mainMessage, kResID_STRn_ErrorStrings, errorNum ); - - // Set the parameters (^0 and ^1) in the ALRT to our error messages - ParamText( mainMessage, errNumStr, NULL, NULL ); - - // Do the alert (which now has our messages in it) - StopAlert( kResID_ALRT_ErrorAlert, NULL ); - - // Quit - exit( EXIT_SUCCESS ); -} diff --git a/src/Alerts.h b/src/Alerts.h deleted file mode 100644 index 02cad9f..0000000 --- a/src/Alerts.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef _MYALERTS_H_ -#define _MYALERTS_H_ - -/**> HEADER FILES <**/ -#include <string.h> -#include <stdlib.h> - -/**> CONSTANT DECLARATIONS <**/ -#define kMoveToFront kFirstWindowOfClass -// Alerts -#define kResID_ALRT_MessageAlert 128 -#define kResID_ALRT_ErrorAlert 129 -// Dialogs -#define kResID_DLOG_SelectResolution 130 -#define iOK 1 -#define iResolutionPopUp 2 -// Menus -#define mResolution 128 -#define i640x480 1 -#define i800x600 2 -#define i1024x768 3 -// String resources -#define kResID_STRn_ErrorStrings 128 -// Misc -#define kInsignificantConstant7454955 0 - -// Error numbers -#define kErr_DSpFindBestContextFailed 1 -#define kErr_DSpContext_ReserveFailed 2 -#define kErr_ActivateContextFailed 3 -#define kErr_DSpStartupFailed 4 -#define kErr_DSpFadeFailed 5 -#define kErr_AGLContext_CreationFailed 6 - -/**> FUNCTION PROTOTYPES <**/ -int SelectResolution( void ); -void MessageAlert( unsigned char *theMessage ); -void FatalErrorAlert( UInt16 errorNum, OSErr osError ); - -#endif \ No newline at end of file |