// // MyOpenGLView.m // cfep // // Created by Nobuki Takayama on 06/02/18. // Copyright 2006 OpenXM.org. All rights reserved. // #import "MyOpenGLView.h" #import "MyOpenGLController.h" #include "mygl.h" @implementation MyOpenGLView -(id) initWithFrame: (NSRect) frame { NSLog(@"initWithFrame\n"); oglComm = [NSMutableArray arrayWithCapacity: 100]; [oglComm retain]; oglInitComm = [NSMutableArray arrayWithCapacity: 1]; [oglInitComm retain]; xeye = 0.0; yeye = 0.0; zeye = 2.0; initGl = 1; [super initWithFrame: frame]; if (self) { NSOpenGLPixelFormatAttribute attributes[]={ NSOpenGLPFAAccelerated, NSOpenGLPFADepthSize,16, // We need this, otherwise depth buffer will no be enabled. NSOpenGLPFAMinimumPolicy, NSOpenGLPFAClosestPolicy, 0}; NSOpenGLPixelFormat *format; format = [[[NSOpenGLPixelFormat alloc] initWithAttributes: attributes] autorelease]; [self initWithFrame: frame pixelFormat: format]; } return self; } -(void) showEyePos {[[MyOpenGLController getOglWindow: gid] showEyeX: xeye Y: yeye Z: zeye];} -(IBAction) setXeye: (id) sender { xeye=([sender floatValue]-50)*0.1; initGl = 1; NSLog(@"xeye=%f\n",xeye); [self showEyePos]; [self setNeedsDisplay: YES]; } -(IBAction) setYeye: (id) sender { float y; y=([sender floatValue]-50)*0.1; initGl = 1; yeye=y; [self showEyePos]; //NSLog(@"yeye=%f\n",yeye); [self setNeedsDisplay: YES]; } -(IBAction) setZeye: (id) sender { float z; z=([sender floatValue]-50)*0.1+2.0; initGl = 1; zeye=z; [self showEyePos]; //NSLog(@"zeye=%f\n",zeye); [self setNeedsDisplay: YES]; } -(void) drawRect: (NSRect) rect { if (initGl) { [self initGL]; initGl = 0;} [self drawOglComm]; //For testing. [self drawRectSimple: rect withColor: 0.0]; } -(void) setFrameSize: (NSSize) newSize { [super setFrameSize: newSize]; //[[self openGLContext] makeCurrentContext]; glViewport(0,0,(GLsizei)newSize.width,(GLsizei) newSize.height); initGl=1; [self setNeedsDisplay: YES]; } -(void) setGid: (int) p{ gid = p; } -(void) initGL { // Initialization codes are here. glClearColor(1.0,1.0,1.0,1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); [self drawOglInitComm]; } -(void) setInitGL: (id) sender { initGl = 1; } // It was for a test. -(void) drawRectSimple: (NSRect) rect withColor: (double) c { glClearColor(1.0,1.0,1.0,1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor4f(1.0,1.0,c,1.0); glRectf(-0.6,-0.6,0.6,0.6); glFlush(); [[self openGLContext] flushBuffer]; } -(void) drawOglComm { int i,n; MyOpenGLCommand *gc; // Execute oglComm. n = [oglComm count]; NSLog(@"drawRect is called with n=%d, oglComSize=%d\n",n,oglCommSize); for (i=0; i0) [oglComm removeLastObject]; [self updateOglCommSize]; return [self countOfOglComm];} -(int) removeLastOfOglInitComm {if ([oglInitComm count]>0) [oglInitComm removeLastObject]; [self updateOglInitCommSize]; return [self countOfOglInitComm];} -(int) removeAllOfOglComm { if ([oglComm count]>0) [oglComm removeAllObjects]; oglCommSize = 0; return 0; } -(int) removeAllOfOglInitComm {if ([oglInitComm count]>0) [oglInitComm removeAllObjects]; oglInitCommSize = 0; return 0; } -(void) updateOglCommSize { int n,i; MyOpenGLCommand *cc; n = [oglComm count]; for (i=n-1; i>=0; i--) { cc = [oglComm objectAtIndex: i]; if ([cc isEndGroup]) { oglCommSize = i+1; return ; } } oglCommSize = 0; } -(void) updateOglInitCommSize { int n,i; MyOpenGLCommand *cc; n = [oglInitComm count]; for (i=n-1; i>=0; i--) { cc = [oglInitComm objectAtIndex: i]; if ([cc isEndGroup]) { oglInitCommSize = i+1; return ; } } oglInitCommSize = 0; } -(void) drawOglInitComm { int i,n; MyOpenGLCommand *gc; // Execute oglComm. n = [oglInitComm count]; NSLog(@"drawOglInitComm is called with n=%d, oglInitComSize=%d\n",n,oglInitCommSize); for (i=0; i