// // MyOpenGLView.m // cfep // // Created by Nobuki Takayama on 06/02/18. // Copyright 2006 OpenXM.org. All rights reserved. // #import "MyOpenGLView.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; } -(IBAction) setXeye: (id) sender { xeye=([sender floatValue]-50)*0.1; initGl = 1; NSLog(@"xeye=%f\n",xeye); [self setNeedsDisplay: YES]; } -(IBAction) setYeye: (id) sender { float y; y=([sender floatValue]-50)*0.1; initGl = 1; yeye=y; //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; //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) 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]; } // 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; i