// // MyOpenGLController.m // cfep // // Created by Nobuki Takayama on 06/02/18. // Copyright 2006 OpenXM.org. All rights reserved. // #import "MyOpenGLController.h" // MyOpenGL window id (gid) is an indeger. static MyOpenGLController *oglWindow[GID_MAX]; // gid --> MyOpenGLController instance. static MyDocument *oglParent[GID_MAX]; // gid --> parent MyDocument. static int MyOpenGLControllerInitialized = 0; static int Gid=0; @implementation MyOpenGLController +(void) initMyOpenGLController { int i; if (MyOpenGLControllerInitialized) return; for (i=0; i= 0) && (tid gtest.rr [MyOpenGLController addOglComm: @"[glColor4f,1.0,0.0,0.0,1.0]" to: 0 from: self]; [MyOpenGLController addOglComm: @"[glRectf,-0.5,-0.5,0.5,0.5]" to: 0 from: self]; [MyOpenGLController addOglComm: @"[glib_flush0]" to: 0 from: self]; */ +(void) addOglComm: (NSString *)comm to: (int) tid from: (MyDocument *) owner { if ((0<=tid) && (tid= 0) [oglWindow[tid] addOglComm: comm]; }else ; } +(void) addOglInitComm: (NSString *)comm to: (int) tid from: (MyDocument *) owner { if ((0<=tid) && (tid= 0) [oglWindow[tid] addOglInitComm: comm]; }else ; } -(id) init { self = [self initWithWindowNibName: @"MyOpenGL"]; if (self) [self setWindowFrameAutosaveName: @"cfep OpenGLView"]; return self; } -(void) setGid: (int) mygid { gid = mygid; } -(int)getGid { return gid; } -(void) windowDidLoad { [super windowDidLoad]; [myogl setGid: gid]; // [self showCount]; } -(void) dealloc { NSLog(@"dealloc of MyOpenGL instance.\n"); // [[NSNotificationCenter defaultCenter] removeObserver: self]; [super dealloc]; } -(void) closeMyOpenGL: (MyDocument *) md { NSLog(@"closeMyOpenGL. \n"); [self close]; } -(BOOL) windowShouldClose: (NSWindow *)sender { // p.299 of O'reilly book. Connect "Window --> file's owner" to connect the delegate outlet of the window // to MyOpenGLController. NSLog(@"x is clicked.\n"); [MyOpenGLController removeMyOpenGLControllerWithGid: [self getGid]]; return YES; } -(void) addOglComm: (NSString *)comm { [myogl addOglComm: comm by: self]; } -(void) addOglInitComm: (NSString *)comm { [myogl addOglInitComm: comm by: self]; } -(int) countOfOglComm {return [myogl countOfOglComm];} -(int) countOfOglInitComm {return [myogl countOfOglInitComm];} -(int) removeLastOfOglComm {return [myogl removeLastOfOglComm];} -(int) removeLastOfOglInitComm {return [myogl removeLastOfOglInitComm];} -(int) removeAllOfOglComm { return [myogl removeAllOfOglComm];} -(int) removeAllOfOglInitComm {return [myogl removeAllOfOglInitComm];} -(NSMutableArray *) getListOfOglComm { return [myogl getListOfOglComm];} -(NSMutableArray *) getListOfOglInitComm { return [myogl getListOfOglInitComm]; } -(void) showEyeX: (float) x Y: (float) y Z: (float) z { [self clearOutput]; [self output: [NSString stringWithFormat: @"gid=%d, n=%d, position of your eye:(%1.2f,%1.2f,%1.2f), nc=%d, ni=%d",gid,[self countOfOglComm],x,y,z,[myogl getOglCommSize],[myogl getOglInitCommSize]]]; } -(void) showCount { [self clearOutput]; [self output: [NSString stringWithFormat: @"gid=%d, number of OpenGL commands=%d, init=%d", gid, [self countOfOglComm], [self countOfOglInitComm]]]; } -(void) clearOutput { [mymessage setBackgroundColor: [NSColor whiteColor]]; } //does it work? -(void) output: (NSString *)msg { [mymessage setStringValue: msg]; } @end