com.jogamp.opengl.util.texture.awt.AWTTextureIO Java Examples
The following examples show how to use
com.jogamp.opengl.util.texture.awt.AWTTextureIO.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CubeTexture.java From MeteoInfo with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void init(GLAutoDrawable drawable) { final GL2 gl = drawable.getGL().getGL2(); gl.glShadeModel(GL2.GL_SMOOTH); gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.glClearDepth(1.0f); gl.glEnable(GL2.GL_DEPTH_TEST); gl.glDepthFunc(GL2.GL_LEQUAL); gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST); gl.glEnable(GL2.GL_TEXTURE_2D); try { File im = new File("D:\\Temp\\image\\lenna.jpg "); //File im = new File("D:\\Temp\\Map\\GLOBALeb3colshade.jpg"); BufferedImage image = ImageIO.read(im); Texture t = AWTTextureIO.newTexture(gl.getGLProfile(), image, true); //Texture t = TextureIO.newTexture(im, true); texture = t.getTextureObject(gl); } catch (IOException e) { e.printStackTrace(); } }
Example #2
Source File: GLTools.java From constellation with Apache License 2.0 | 5 votes |
/** * Load a BufferedImage array into a texture array. * <p> * Each BufferedImage must be of type BufferedImage.TYPE_4BYTE_ABGR. The * images will be loaded at 0,0 at each level of the texture array. * <p> * It appears that the images must have a row length that is a multiple of * four. This is probably due to the particular format we're using, and * could probably be worked around, but the simple fix is to check your row * length. * * @param gl the current OpenGL context. * @param textureName The name of the texture to bind to with BindTexture(). * @param images A List of BufferedImages of type * BufferedImage.TYPE_4BYTE_ABGR. * @param maxWidth The maximum width of the images. * @param maxHeight The maximum height of the images. * @param minFilter Texture selection with TEXTURE_MIN_FILTER. * @param magFilter Texture selection with TEXTURE_MAG_FILTER. * @param wrapMode texture wrap mode with TEXTURE_WRAP_S and TEXTURE_WRAP_T. */ public static void loadTextures(final GL3 gl, final int textureName, final List<BufferedImage> images, final int maxWidth, final int maxHeight, final int minFilter, final int magFilter, final int wrapMode) { gl.glBindTexture(GL3.GL_TEXTURE_2D_ARRAY, textureName); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_WRAP_S, wrapMode); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_WRAP_T, wrapMode); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_MIN_FILTER, minFilter); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_MAG_FILTER, magFilter); // Call glTexImage3D() to create the buffer here: we've assumed the internalformat and format. gl.glTexImage3D(GL3.GL_TEXTURE_2D_ARRAY, 0, GL.GL_RGBA, maxWidth, maxHeight, images.size(), 0, GL.GL_RGBA, GL3.GL_UNSIGNED_BYTE, null); int i = 0; for (BufferedImage image : images) { try { final TextureData data = AWTTextureIO.newTextureData(gl.getGLProfile(), image, false); if (data.getWidth() > maxWidth || data.getHeight() > maxHeight) { throw new RenderException(String.format("Image %d is too large", i)); } // Images are always placed at 0,0. final int xoffset = 0; final int yoffset = 0; final int zoffset = i; gl.glTexSubImage3D(GL3.GL_TEXTURE_2D_ARRAY, 0, xoffset, yoffset, zoffset, data.getWidth(), data.getHeight(), 1, data.getPixelFormat(), GL3.GL_UNSIGNED_BYTE, data.getBuffer()); data.destroy(); } catch (final RuntimeException ex) { LOGGER.log(Level.SEVERE, null, ex); } i++; } }
Example #3
Source File: Plot3DGL.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
private void drawImage(GL2 gl, Graphic graphic) { ImageShape ishape = (ImageShape) graphic.getShape(); BufferedImage image = ishape.getImage(); Texture texture = AWTTextureIO.newTexture(gl.getGLProfile(), image, true); //Texture texture = this.imageCache.get(image); int idTexture = texture.getTextureObject(); List<PointZ> coords = ishape.getCoords(); gl.glColor3f(1f, 1f, 1f); gl.glBindTexture(GL2.GL_TEXTURE_2D, idTexture); // Texture parameterization gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST); gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR); // Draw image gl.glBegin(GL2.GL_QUADS); // Front Face //gl.glTexCoord2f(0.0f, 0.0f); gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(transform_xf((float) coords.get(0).X), transform_yf((float) coords.get(0).Y), transform_zf((float) coords.get(0).Z)); //gl.glTexCoord2f(1.0f, 0.0f); gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(transform_xf((float) coords.get(1).X), transform_yf((float) coords.get(1).Y), transform_zf((float) coords.get(1).Z)); //gl.glTexCoord2f(1.0f, 1.0f); gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(transform_xf((float) coords.get(2).X), transform_yf((float) coords.get(2).Y), transform_zf((float) coords.get(2).Z)); //gl.glTexCoord2f(0.0f, 1.0f); gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(transform_xf((float) coords.get(3).X), transform_yf((float) coords.get(3).Y), transform_zf((float) coords.get(3).Z)); gl.glEnd(); // Unbinding the texture gl.glBindTexture(GL2.GL_TEXTURE_2D, 0); }
Example #4
Source File: Plot3DGL.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
private void drawImage(GL2 gl) throws IOException { File im = new File("D:\\Temp\\image\\lenna.jpg "); BufferedImage image = ImageIO.read(im); Texture t = AWTTextureIO.newTexture(gl.getGLProfile(), image, true); //Texture t = TextureIO.newTexture(im, true); //Texture t = this.imageCache.get(image); int idTexture = t.getTextureObject(gl); gl.glColor3f(1f, 1f, 1f); gl.glBindTexture(GL2.GL_TEXTURE_2D, idTexture); // // Texture parameterization // gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR_MIPMAP_LINEAR); // gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR); // Draw image gl.glBegin(GL2.GL_QUADS); // Front Face gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 1.0f); gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, 1.0f); gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(1.0f, 1.0f, 1.0f); gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-1.0f, 1.0f, 1.0f); gl.glEnd(); // Unbinding the texture gl.glBindTexture(GL2.GL_TEXTURE_2D, 0); }
Example #5
Source File: TextureCache2.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public void initialize() { if (isNonPowerOf2TexturesAvailable == null) { isNonPowerOf2TexturesAvailable = !GamaPreferences.Displays.DISPLAY_POWER_OF_TWO.getValue() && gl.getGL().isNPOTTextureAvailable(); GamaPreferences.Displays.DISPLAY_POWER_OF_TWO.onChange(newValue -> { isNonPowerOf2TexturesAvailable = !newValue && gl.getGL().isNPOTTextureAvailable(); AWTTextureIO.setTexRectEnabled(newValue); }); AWTTextureIO.setTexRectEnabled(GamaPreferences.Displays.DISPLAY_POWER_OF_TWO.getValue()); // DEBUG.OUT("Non power-of-two textures available: " + isNonPowerOf2TexturesAvailable); } }
Example #6
Source File: TextureCache2.java From gama with GNU General Public License v3.0 | 5 votes |
Texture buildTexture(final GL gl, final BufferedImage im) { try { final TextureData data = AWTTextureIO.newTextureData(gl.getGLProfile(), im, true); final Texture texture = new Texture(gl, data); data.flush(); return texture; } catch (final GLException e) { e.printStackTrace(); return null; } }
Example #7
Source File: GLTools.java From constellation with Apache License 2.0 | 4 votes |
/** * Load an array of icon textures. * <p> * We assume that the textures being loaded are icons, and therefore are * roughly the same size (with a maximum of (width,height). * <p> * The array is limited to GL_MAX_ARRAY_TEXTURE_LAYERS layers. This can be * fairly low (512 on low-end systems), so icons are loaded into an 8x8 icon * matrix in each layer, thus giving a maximum of 512x8x8=32768 icons. (This * assumes that GL_MAX_3D_TEXTURE_SIZE is big enough to take that many * pixels. With the current icon size of 256x256, then * GL_MAX_3D_TEXTURE_SIZE must be at least 2048.) * <p> * Icons that are smaller than (width,height) are offset so they are * centred, so the shader can just draw the icons without worrying about * where in the texture they are. * <p> * It appears that the images must have a row length that is a multiple of * four. This is probably due to the particular format we're using, and * could probably be worked around, but the simple fix is to check your row * length. * * @param glCurrent the current OpenGL context. * @param icons a list of icons that need to added to the buffer. * @param width the width of each icon. * @param height the height of each icon. * * @return the id of the texture buffer. */ public static int loadSharedIconTextures(final GL3 glCurrent, final List<ConstellationIcon> icons, final int width, final int height) { final int[] v = new int[1]; glCurrent.glGetIntegerv(GL3.GL_MAX_ARRAY_TEXTURE_LAYERS, v, 0); final int maxIcons = v[0] * 64; if (icons.size() > maxIcons) { System.out.printf("****\n**** Warning: nIcons %d > GL_MAX_ARRAY_TEXTURE_LAYERS %d\n****\n", icons.size(), maxIcons); } final int nIcons = Math.min(icons.size(), maxIcons); glCurrent.getContext().release(); final GL3 gl = (GL3) SharedDrawable.getSharedAutoDrawable().getGL(); final int result = gl.getContext().makeCurrent(); if (result == GLContext.CONTEXT_NOT_CURRENT) { glCurrent.getContext().makeCurrent(); throw new RenderException("Could not make texture context current."); } final int[] textureName = new int[1]; try { textureName[0] = SharedDrawable.getIconTextureName(); gl.glBindTexture(GL3.GL_TEXTURE_2D_ARRAY, textureName[0]); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_WRAP_S, GL3.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_WRAP_T, GL3.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_MIN_FILTER, GL3.GL_LINEAR); gl.glTexParameteri(GL3.GL_TEXTURE_2D_ARRAY, GL3.GL_TEXTURE_MAG_FILTER, GL3.GL_LINEAR); gl.glTexImage3D(GL3.GL_TEXTURE_2D_ARRAY, 0, GL.GL_RGBA, width * 8, height * 8, (nIcons + 63) / 64, 0, GL.GL_RGBA, GL3.GL_UNSIGNED_BYTE, null); final Iterator<ConstellationIcon> iconIterator = icons.iterator(); for (int i = 0; i < nIcons; i++) { final ConstellationIcon icon = iconIterator.next(); try { BufferedImage iconImage = icon.buildBufferedImage(); if (iconImage != null) { // Appears to be a bug in JOGL where texture provider for PNG files does not flip the texture. final TextureData data = AWTTextureIO.newTextureData(gl.getGLProfile(), iconImage, false); if (data.getWidth() > width || data.getHeight() > height) { throw new RenderException(String.format("Image %d is too large (width %d>%d, height %d>%d)", i, data.getWidth(), width, data.getHeight(), height)); } // Offset each icon into an 8x8 matrix. // There are multiple icons in each // Allow for icons that are smaller than width,height. final int xoffset = (width - data.getWidth()) / 2 + (width * (i & 7)); final int yoffset = (height - data.getHeight()) / 2 + (height * ((i >>> 3) & 7)); final int zoffset = i >>> 6; gl.glTexSubImage3D(GL3.GL_TEXTURE_2D_ARRAY, 0, xoffset, yoffset, zoffset, data.getWidth(), data.getHeight(), 1, data.getPixelFormat(), GL3.GL_UNSIGNED_BYTE, data.getBuffer()); data.destroy(); } } catch (final RuntimeException ex) { System.out.printf("##%n## GLTools.loadTextures() icon %d throwable: %s%n##%n", i, ex); LOGGER.log(Level.SEVERE, null, ex); } } } finally { gl.getContext().release(); glCurrent.getContext().makeCurrent(); } return textureName[0]; }