import pt.ipb . esact .cg.gl. CGEngine ;import pt.ipb . esact .cg.gl. GLKeyboardAdapter ;import pt.ipb . esact .cg.gl. GLVector ;import pt.ipb . esact .cg.gl. tools . GlTools ;import com . jogamp . opengl . util . FPSAnimator ;import com . jogamp . opengl . util . gl2 . GLUT ;import com . jogamp . opengl . util . texture . spi . TGAImage ;@SuppressWarnings (" serial ")public class TexGen extends JFrame implements GLEventListener {private GLU glu = new GLU ();private GLUT glut = new GLUT ();private GLCanvas canvas ;FPSAnimator animator ;private float bgColor [] = { 0f, 0f, 0f, 0f };private GLVector location = new GLVector (0f, 0f, 5f);private GLVector lookAt = new GLVector (0f, 0f, 0f);private IntBuffer textures = IntBuffer . allocate (2);private CGEngine e;// I<strong>de</strong>ntificadores das Texturaspublic static final int Stripes = 0, Environment = 1;public static final int ObjectLinear = 0, EyeLinear = 1, SphereMap = 2;private int ren<strong>de</strong>rMo<strong>de</strong> = SphereMap ;private TGAImage environment ;public static void main ( String [] args ) {new TexGen ();}public TexGen () {super (" TexGen ");setDefaultCloseOperation ( JFrame . EXIT_ON_CLOSE );setSize (600 , 600);Container p = getContentPane ();Bor<strong>de</strong>rLayout l = new Bor<strong>de</strong>rLayout (5 , 5);p. setLayout (l);canvas = new GLCanvas ();canvas . addGLEventListener ( this );p. add ( canvas , Bor<strong>de</strong>rLayout . CENTER );e = new CGEngine ( canvas , location );e. camera (). lookAt ( lookAt );setVisible ( true );canvas . requestFocus ();}animator = new FPSAnimator ( canvas , 25);animator . start ();127
@Overri<strong>de</strong>public void dispose ( GLAutoDrawable drawable ) {}@Overri<strong>de</strong>public void init ( GLAutoDrawable drawable ) {GL2 gl = drawable . getGL (). getGL2 ();gl. glClearColor ( bgColor [0] , bgColor [1] , bgColor [2] , bgColor [3]);// Cull backs of polygonsgl. glFrontFace ( GL2 . GL_CCW );gl. glEnable ( GL2 . GL_CULL_FACE );gl. glEnable ( GL2 . GL_DEPTH_TEST );gl. glEnable ( GL2 . GL_BACK );// As texturas substitem o material da geometriagl. glTexEnvi ( GL2 . GL_TEXTURE_ENV , GL2 . GL_TEXTURE_ENV_MODE , GL2 . GL_DECAL );// 2 Texturasgl. glGenTextures (2 , textures );/*** Carregamento da textura stripes*/environment = loadTexture (" environment . tga ");gl. glBindTexture ( GL2 . GL_TEXTURE_2D , textures . get ( Environment ));gl. glTexImage2D ( GL2 . GL_TEXTURE_2D , 0, GL2 . GL_RGBA ,environment . getWidth () , environment . getHeight () ,0, environment . getGLFormat () , GL2 . GL_UNSIGNED_BYTE ,environment . getData ());gl. glTexParameterf ( GL2 . GL_TEXTURE_2D ,GL2 . GL_TEXTURE_MIN_FILTER , GL2 . GL_LINEAR );gl. glTexParameterf ( GL2 . GL_TEXTURE_2D ,GL2 . GL_TEXTURE_MAG_FILTER , GL2 . GL_LINEAR );gl. glTexParameterf ( GL2 . GL_TEXTURE_2D ,GL2 . GL_TEXTURE_WRAP_S , GL2 . GL_REPEAT );gl. glTexParameterf ( GL2 . GL_TEXTURE_2D ,GL2 . GL_TEXTURE_WRAP_T , GL2 . GL_REPEAT );/*** Carregamento da textura <strong>de</strong> ambiente*/TGAImage sriptes = loadTexture (" stripes . tga ");gl. glBindTexture ( GL2 . GL_TEXTURE_2D , textures . get ( Stripes ));gl. glTexImage2D ( GL2 . GL_TEXTURE_2D , 0, GL2 . GL_RGBA ,sriptes . getWidth () , sriptes . getHeight () ,0, sriptes . getGLFormat () , GL2 . GL_UNSIGNED_BYTE ,sriptes . getData ());gl. glTexParameterf ( GL2 . GL_TEXTURE_2D ,GL2 . GL_TEXTURE_MIN_FILTER , GL2 . GL_LINEAR );gl. glTexParameterf ( GL2 . GL_TEXTURE_2D ,GL2 . GL_TEXTURE_MAG_FILTER , GL2 . GL_LINEAR );gl. glTexParameterf ( GL2 . GL_TEXTURE_2D ,GL2 . GL_TEXTURE_WRAP_S , GL2 . GL_REPEAT );gl. glTexParameterf ( GL2 . GL_TEXTURE_2D ,GL2 . GL_TEXTURE_WRAP_T , GL2 . GL_REPEAT );// Activar o Texture Mapping128