public TextureData loadTextureData(String filename, GL gl) throws IOException { TextureData i2 = TextureIO.newTextureData(gl.getGLProfile(), new File(filename), true, null); return i2; }
public final static TextureData createTestTextureData() { TextureData res = null; try { final URLConnection urlConn = IOUtil.getResource("jogl/util/data/av/test-ntsc01-28x16.png", NullGLMediaPlayer.class.getClassLoader()); if(null != urlConn) { res = TextureIO.newTextureData(GLProfile.getGL2ES2(), urlConn.getInputStream(), false, TextureIO.PNG); } } catch (final Exception e) { e.printStackTrace(); } if(null == res) { final int w = 160; final int h = 90; final ByteBuffer buffer = Buffers.newDirectByteBuffer(w*h*4); while(buffer.hasRemaining()) { buffer.put((byte) 0xEA); buffer.put((byte) 0xEA); buffer.put((byte) 0xEA); buffer.put((byte) 0xEA); } buffer.rewind(); res = new TextureData(GLProfile.getGL2ES2(), GL.GL_RGBA, w, h, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, false, false, false, buffer, null); } return res; }
public final static TextureData createTestTextureData() { TextureData res = null; try { final URLConnection urlConn = IOUtil.getResource("jogl/util/data/av/test-ntsc01-28x16.png", NullGLMediaPlayer.class.getClassLoader()); if(null != urlConn) { res = TextureIO.newTextureData(GLProfile.getGL2ES2(), urlConn.getInputStream(), false, TextureIO.PNG); } } catch (final Exception e) { e.printStackTrace(); } if(null == res) { final int w = 160; final int h = 90; final ByteBuffer buffer = Buffers.newDirectByteBuffer(w*h*4); while(buffer.hasRemaining()) { buffer.put((byte) 0xEA); buffer.put((byte) 0xEA); buffer.put((byte) 0xEA); buffer.put((byte) 0xEA); } buffer.rewind(); res = new TextureData(GLProfile.getGL2ES2(), GL.GL_RGBA, w, h, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, false, false, false, buffer, null); } return res; }
public final void addFrame(final GL gl, final Class<?> context, final String imageResourcePath, final String imageSuffix) throws IOException { final URLConnection urlConn = IOUtil.getResource(imageResourcePath, context.getClassLoader(), context); if(null != urlConn) { final TextureData texData = TextureIO.newTextureData(GLProfile.getGL2ES2(), urlConn.getInputStream(), false, imageSuffix); final Texture tex = new Texture(getTextureTarget()); tex.updateImage(gl, texData); addFrame(gl, tex); } } public final int getFrameCount() { return frames.size(); }
public final void addFrame(final GL gl, final Class<?> context, final String imageResourcePath, final String imageSuffix) throws IOException { final URLConnection urlConn = IOUtil.getResource(context, imageResourcePath); if(null != urlConn) { final TextureData texData = TextureIO.newTextureData(GLProfile.getGL2ES2(), urlConn.getInputStream(), false, imageSuffix); final Texture tex = new Texture(getTextureTarget()); tex.updateImage(gl, texData); addFrame(gl, tex); } } public final int getFrameCount() { return frames.size(); }
final TextureData data = newTextureData(glp, url, mipmap, fileSuffix); final Texture texture = newTexture(gl, data); data.flush();
final TextureData data = newTextureData(glp, url, mipmap, fileSuffix); final Texture texture = newTexture(gl, data); data.flush();
/** * Creates an OpenGL texture object from the specified stream using * the current OpenGL context. * * @param stream the stream from which to read the texture data * @param mipmap whether mipmaps should be produced for this * texture either by autogenerating them or * reading them from the file. Some file formats * support multiple mipmaps in a single file in * which case those mipmaps will be used rather * than generating them. * @param fileSuffix the suffix of the file name to be used as a * hint of the file format to the underlying * texture provider, or null if none and should be * auto-detected (some texture providers do not * support this) * @throws IOException if an error occurred while reading the stream * @throws GLException if no OpenGL context is current or if an * OpenGL error occurred */ public static Texture newTexture(final InputStream stream, final boolean mipmap, final String fileSuffix) throws IOException, GLException { final GL gl = GLContext.getCurrentGL(); final GLProfile glp = gl.getGLProfile(); final TextureData data = newTextureData(glp, stream, mipmap, fileSuffix); final Texture texture = newTexture(gl, data); data.flush(); return texture; }
/** * Creates an OpenGL texture object from the specified stream using * the current OpenGL context. * * @param stream the stream from which to read the texture data * @param mipmap whether mipmaps should be produced for this * texture either by autogenerating them or * reading them from the file. Some file formats * support multiple mipmaps in a single file in * which case those mipmaps will be used rather * than generating them. * @param fileSuffix the suffix of the file name to be used as a * hint of the file format to the underlying * texture provider, or null if none and should be * auto-detected (some texture providers do not * support this) * @throws IOException if an error occurred while reading the stream * @throws GLException if no OpenGL context is current or if an * OpenGL error occurred */ public static Texture newTexture(final InputStream stream, final boolean mipmap, final String fileSuffix) throws IOException, GLException { final GL gl = GLContext.getCurrentGL(); final GLProfile glp = gl.getGLProfile(); final TextureData data = newTextureData(glp, stream, mipmap, fileSuffix); final Texture texture = newTexture(gl, data); data.flush(); return texture; }
/** * Creates an OpenGL texture object from the specified file using * the current OpenGL context. * * @param file the file from which to read the texture data * @param mipmap whether mipmaps should be produced for this * texture either by autogenerating them or * reading them from the file. Some file formats * support multiple mipmaps in a single file in * which case those mipmaps will be used rather * than generating them. * @throws IOException if an error occurred while reading the file * @throws GLException if no OpenGL context is current or if an * OpenGL error occurred */ public static Texture newTexture(final File file, final boolean mipmap) throws IOException, GLException { final GL gl = GLContext.getCurrentGL(); final GLProfile glp = gl.getGLProfile(); final TextureData data = newTextureData(glp, file, mipmap, IOUtil.getFileSuffix(file)); final Texture texture = newTexture(gl, data); data.flush(); return texture; }
/** * Creates an OpenGL texture object from the specified file using * the current OpenGL context. * * @param file the file from which to read the texture data * @param mipmap whether mipmaps should be produced for this * texture either by autogenerating them or * reading them from the file. Some file formats * support multiple mipmaps in a single file in * which case those mipmaps will be used rather * than generating them. * @throws IOException if an error occurred while reading the file * @throws GLException if no OpenGL context is current or if an * OpenGL error occurred */ public static Texture newTexture(final File file, final boolean mipmap) throws IOException, GLException { final GL gl = GLContext.getCurrentGL(); final GLProfile glp = gl.getGLProfile(); final TextureData data = newTextureData(glp, file, mipmap, IOUtil.getFileSuffix(file)); final Texture texture = newTexture(gl, data); data.flush(); return texture; }
@Override public void update(ResourceHandle changed, final Texture old) { TextureData a = null; try { a = TextureIO.newTextureData(gc.getGL().getGLProfile(), changed.getStream(), true, IOUtil.getFileSuffix(changed.getName())); } catch (IOException ex) { } final TextureData data = a; gc.invoke(false, new GLRunnable() { @Override public boolean run(GLAutoDrawable glad) { old.updateImage(glad.getGL(), data); return true; } }); }
@Override public Image load(final InputStream is, final boolean flipped) throws IOException { final TextureData textureData = TextureIO.newTextureData(_capsUtil.getProfile(), is, true, null); final Buffer textureDataBuffer = textureData.getBuffer(); final Image ardorImage = new Image(); final TYPE bufferDataType = getBufferDataType(textureDataBuffer); if (bufferDataType == null) { throw new UnsupportedOperationException("Unknown buffer type " + textureDataBuffer.getClass().getName()); } else { final int dataSizeInBytes = textureDataBuffer.capacity() * Buffers.sizeOfBufferElem(textureDataBuffer); final ByteBuffer scratch = createOnHeap ? BufferUtils.createByteBufferOnHeap(dataSizeInBytes) : Buffers .newDirectByteBuffer(dataSizeInBytes); if (flipped) { flipImageData(textureDataBuffer, scratch, dataSizeInBytes, bufferDataType, textureData.getWidth(), textureData.getHeight()); } else { copyImageData(textureDataBuffer, scratch, bufferDataType); } ardorImage.setWidth(textureData.getWidth()); ardorImage.setHeight(textureData.getHeight()); ardorImage.setData(scratch); ardorImage.setDataFormat(JoglTextureUtil.getImageDataFormat(textureData.getPixelFormat())); // ardorImage.setDataType(JoglTextureUtil.getPixelDataType(textureData.getPixelType())); ardorImage.setDataType(PixelDataType.UnsignedByte); return ardorImage; } }