1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| @Override public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0, image.getWidth(), image.getHeight(), 0, 0, 1); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glDisable(GL2.GL_DEPTH_TEST); gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f); gl.glClear(GL2.GL_COLOR_BUFFER_BIT); gl.glBlendFunc (GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA); gl.glEnable (GL2.GL_BLEND);
WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, w, h, 4, null);
ComponentColorModel colorModel= new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] {8,8,8,8}, true, false, ComponentColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE);
BufferedImage dukeImg = new BufferedImage (colorModel, raster, false, null);
Graphics2D g = dukeImg.createGraphics(); g.drawImage(image, null, null); DataBufferByte dukeBuf = (DataBufferByte)raster.getDataBuffer(); byte[] dukeRGBA = dukeBuf.getData(); ByteBuffer bb = ByteBuffer.wrap(dukeRGBA); bb.position(0); bb.mark();
gl.glBindTexture(GL2.GL_TEXTURE_2D, 13); gl.glPixelStorei(GL2.GL_UNPACK_ALIGNMENT, 1); gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_CLAMP); gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_CLAMP); gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR); gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR); gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE); gl.glTexImage2D (GL2.GL_TEXTURE_2D, 0, GL2.GL_RGBA, w, h, 0, GL2.GL_RGBA, GL2.GL_UNSIGNED_BYTE, bb); int left = 1; int top = 1; gl.glEnable(GL2.GL_TEXTURE_2D); gl.glBindTexture (GL2.GL_TEXTURE_2D, 13); gl.glBegin(GL2.GL_POLYGON); gl.glTexCoord2d (0, 0); gl.glVertex2d (left,top); gl.glTexCoord2d(1,0); gl.glVertex2d (left + w, top); gl.glTexCoord2d(1,1); gl.glVertex2d (left + w, top + h); gl.glTexCoord2d(0,1); gl.glVertex2d (left, top + h); gl.glEnd(); gl.glFlush(); } |