/////////////////////////////////////////////////// // pngTextureTest in opgl /////////////////////////////////////////////////// // progMaxRheiner /////////////////////////////////////////////////// // 5.12.1999 /////////////////////////////////////////////////// import gl4java.*; import gl4java.awt.*; import gl4java.utils.textures.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.net.*; public class pngTextureTestApplet extends Applet { pngTextureTest canvas = null; boolean isAnApplet = true; public void init() { Dimension d = getSize(); setLayout(new BorderLayout()); if(isAnApplet) canvas = new pngTextureTest (d.width, d.height, getCodeBase()); else canvas = new pngTextureTest (d.width, d.height, null); add("Center", canvas); } public static void main( String args[] ) { pngTextureTestApplet applet = new pngTextureTestApplet(); Frame f = new Frame("pngTextureTestApplet"); f.addWindowListener( new WindowAdapter() { public void windowClosed(WindowEvent e) { System.exit(0); } public void windowClosing(WindowEvent e) { windowClosed(e); } } ); f.setLayout(new BorderLayout()); f.add("Center", applet); applet.setSize(500,300); applet.isAnApplet = false; applet.init(); applet.start(); Dimension ps = applet.getPreferredSize(); f.setBounds(-100,-100,99,99); f.setVisible(true); f.setVisible(false); f.setVisible(true); Insets i = f.getInsets(); f.setBounds(0,0, ps.width+i.left+i.right, ps.height+i.top+i.bottom); f.setVisible(true); } public void start() { } public void stop() { } class pngTextureTest extends GLCanvas implements MouseListener,MouseMotionListener { float []mPosObjTrans; float []mPosObjRot; Point mousePoint; Point oldMousePoint; boolean mouseMoveFlag; int texName[] = {0}; URL base; public pngTextureTest (int w, int h, URL base) { super(w, h); this.base=base; } public void preInit() { createOwnWindow = true; } public void init() { // texture laden PngTextureLoader txtLoader1 = new PngTextureLoader(gl, glu); if(base!=null) txtLoader1.readTexture(base, "tex/DAISYX.png"); else { try { txtLoader1.readTexture("tex/DAISYX.png"); } catch (Exception ex) { ex.printStackTrace(); } } byte[] pixels1 = txtLoader1.getTexture(); if(txtLoader1.isOk()) { gl.glEnable(GL_TEXTURE_2D); // JAU: let's show us the scaled, // and the tricky one using glTexSubImage2D gl.glGenTextures(1,texName); gl.glBindTexture(GL_TEXTURE_2D,texName[0]); gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); txtLoader1.texImage2DNonScaled(true); // The Scaled Way // txtLoader1.texImage2DScaled2Pow2(); gl.glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); System.out.println("texture succesfully loaded !"); System.out.println("texture: "+txtLoader1); } // cameraMatrix init mPosObjTrans=new float[16]; for(int i=0;i<16;i++) mPosObjTrans[i]=0f; mPosObjTrans[0]=mPosObjTrans[5]=mPosObjTrans[10]=mPosObjTrans[15]=1f; mPosObjRot=new float[16]; for(int i=0;i<16;i++) mPosObjRot[i]=0f; mPosObjRot[0]=mPosObjRot[5]=mPosObjRot[10]=mPosObjRot[15]=1f; TranlateObj(0f,0f,-10f); gl.glShadeModel (GL_SMOOTH); gl.glEnable(GL_DEPTH_TEST); gl.glClearColor(0.2f, 0.2f, 0.2f, 1.0f); gl.glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glj.gljCheckGL(); canvas.addMouseListener(this); canvas.addMouseMotionListener(this); mouseMoveFlag=false; reshape(getSize().width, getSize().height); } public void display() { int i; /* Standard GL4Java Init */ if( glj.gljMakeCurrent() == false ) { System.out.println("problem in use() method"); return; } // just render it gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); SetCamera(); DrawScene(); /* For your animation dutys ;-) */ glj.gljSwap(); glj.gljCheckGL(); glj.gljFree(); } public void reshape(int w, int h) { gl.glMatrixMode (GL_MODELVIEW); gl.glViewport (0, 0, w, h); gl.glLoadIdentity(); SetCamera(); } public void drawGrid(float x0, float y0, float width, float height, float step) { float i,j; /* draw grid */ gl.glBegin(GL_LINES); for(i=x0;i