Manual de Apoio 2010
Manual de Apoio 2010
Manual de Apoio 2010
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
public Example0 () {super (" Mo<strong>de</strong>lo OpenGL ");setUn<strong>de</strong>corated ( true );setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE );setSize (600 , 600);canvas = new GLCanvas ();add ( canvas , Bor<strong>de</strong>rLayout . CENTER );canvas . addGLEventListener ( this );GLVector location = new GLVector (0f, .5f, .5f);new CGEngine ( canvas , location );setVisible ( true );canvas . requestFocus ();}FPSAnimator animator = new FPSAnimator ( canvas , 25);animator . start ();public void dispose ( GLAutoDrawable drawable ) {}@Overri<strong>de</strong>public void init ( GLAutoDrawable drawable ) {GL2 gl = drawable . getGL (). getGL2 ();}// Grayish backgroundgl. glClearColor ( fLowLight [0] , fLowLight [1] , fLowLight [2] , fLowLight [3]);// Cull backs of polygonsgl. glCullFace ( GL2 . GL_BACK );gl. glFrontFace ( GL2 . GL_CCW );gl. glEnable ( GL2 . GL_CULL_FACE );gl. glEnable ( GL2 . GL_DEPTH_TEST );spherePositions = GlUtil . generateRandomPositions ( FloorSize , NumSpheres );setupLight (gl );private void setupLight ( GL2 gl) {// Setup light parametersgl. glLightMo<strong>de</strong>lfv ( GL2 . GL_LIGHT_MODEL_AMBIENT , fNoLight , 0);gl. glLightfv ( GL2 . GL_LIGHT0 , GL2 . GL_AMBIENT , fLowLight , 0);gl. glLightfv ( GL2 . GL_LIGHT0 , GL2 . GL_DIFFUSE , fBrightLight , 0);gl. glLightfv ( GL2 . GL_LIGHT0 , GL2 . GL_SPECULAR , fBrightLight , 0);gl. glEnable ( GL2 . GL_LIGHTING );gl. glEnable ( GL2 . GL_LIGHT0 );}// Mostly use material trackinggl. glEnable ( GL2 . GL_COLOR_MATERIAL );gl. glColorMaterial ( GL2 . GL_FRONT , GL2 . GL_AMBIENT_AND_DIFFUSE );gl. glMateriali ( GL2 . GL_FRONT , GL2 . GL_SHININESS , 128);@Overri<strong>de</strong>public void display ( GLAutoDrawable drawable ) {GL2 gl = drawable . getGL (). getGL2 ();gl. glClear ( GL2 . GL_COLOR_BUFFER_BIT | GL2 . GL_DEPTH_BUFFER_BIT );gl. glMaterialfv ( GL2 . GL_FRONT , GL2 . GL_SPECULAR , fBrightLight , 0);117