List of usage examples for org.lwjgl.opengl GL11 glTexSubImage2D
public static void glTexSubImage2D(@NativeType("GLenum") int target, @NativeType("GLint") int level, @NativeType("GLint") int xoffset, @NativeType("GLint") int yoffset, @NativeType("GLsizei") int width, @NativeType("GLsizei") int height, @NativeType("GLenum") int format, @NativeType("GLenum") int type, @NativeType("void const *") double[] pixels)
From source file:armonkeykit.videocapture.QtCaptureImage.java
License:Open Source License
public boolean update(Texture texture) { synchronized (this) { if (buffer == null) { return false; }/* w w w.j a v a 2 s.co m*/ buffer.rewind(); if (initAndScaleTexture) { scaleTexture(texture); } GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureId()); GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, videowidth, videoheight, pixelformat, dataformat, buffer); try { Util.checkGLError(); } catch (OpenGLException e) { log.info("Error rendering video to texture. No glTexSubImage2D/OpenGL 1.2 support?"); System.err.println(e.getMessage()); } lastupdated = framecounter; return true; } }
From source file:betterfonts.GlyphCache.java
License:Open Source License
/** * Update a portion of the current glyph cache texture using the contents of the glyphCacheImage with glTexSubImage2D(). * * @param dirty The rectangular region in glyphCacheImage that has changed and needs to be copied into the texture * * @todo Add mip-mapping support here// w ww.ja v a 2 s. c o m * @todo Test with bilinear texture interpolation and possibly add a 1 pixel transparent border around each glyph to avoid * bleedover when interpolation is active or add a small "fudge factor" to the UV coordinates like already n FontRenderer */ private void updateTexture(Rectangle dirty) { /* Only update OpenGL texture if changes were made to the texture */ if (dirty != null) { /* Load imageBuffer with pixel data ready for transfer to OpenGL texture */ updateImageBuffer(dirty.x, dirty.y, dirty.width, dirty.height); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureName); GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, dirty.x, dirty.y, dirty.width, dirty.height, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, imageBuffer); } }
From source file:com.adavr.player.context.RGBVideoContext.java
License:Open Source License
public void setPixels(IntBuffer pixels) { Texture.bind(texture);/* ww w .j a va 2 s. c om*/ // GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, stride); GL11.glTexSubImage2D(texture.getTarget(), 0, 0, 0, videoWidth, videoHeight, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, pixels); }
From source file:com.adavr.player.context.YUVVideoContext.java
License:Open Source License
public void setPixels(int index, ByteBuffer pixels, int stride) { int w;/*from w w w.jav a2s. com*/ int h; if (index == Y_INDEX) { w = width; h = height; } else { w = width / 2; h = height / 2; } Texture.bind(textures[index]); GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, stride); GL11.glTexSubImage2D(textures[index].getTarget(), 0, 0, 0, w, h, GL11.GL_RED, GL11.GL_UNSIGNED_BYTE, pixels); }
From source file:com.ardor3d.renderer.lwjgl.LwjglRenderer.java
License:Open Source License
private void updateTexSubImage(final Texture destination, final int dstOffsetX, final int dstOffsetY, final int dstOffsetZ, final int dstWidth, final int dstHeight, final int dstDepth, final ByteBuffer source, final int srcOffsetX, final int srcOffsetY, final int srcOffsetZ, final int srcTotalWidth, final int srcTotalHeight, final Face dstFace) { // Ignore textures that do not have an id set if (destination.getTextureIdForContext(ContextManager.getCurrentContext().getGlContextRep()) == 0) { logger.warning("Attempting to update a texture that is not currently on the card."); return;//from ww w.j a v a2s . c o m } // Determine the original texture configuration, so that this method can // restore the texture configuration to its original state. final IntBuffer idBuff = BufferUtils.createIntBuffer(16); GL11.glGetInteger(GL11.GL_UNPACK_ALIGNMENT, idBuff); final int origAlignment = idBuff.get(0); final int origRowLength = 0; final int origImageHeight = 0; final int origSkipPixels = 0; final int origSkipRows = 0; final int origSkipImages = 0; final int alignment = 1; int rowLength; if (srcTotalWidth == dstWidth) { // When the row length is zero, then the width parameter is used. // We use zero in these cases in the hope that we can avoid two // unnecessary calls to glPixelStorei. rowLength = 0; } else { // The number of pixels in a row is different than the number of // pixels in the region to be uploaded to the texture. rowLength = srcTotalWidth; } int imageHeight; if (srcTotalHeight == dstHeight) { // When the image height is zero, then the height parameter is used. // We use zero in these cases in the hope that we can avoid two // unnecessary calls to glPixelStorei. imageHeight = 0; } else { // The number of pixels in a row is different than the number of // pixels in the region to be uploaded to the texture. imageHeight = srcTotalHeight; } // Grab pixel format final int pixelFormat; if (destination.getImage() != null) { pixelFormat = LwjglTextureUtil.getGLPixelFormat(destination.getImage().getDataFormat()); } else { pixelFormat = LwjglTextureUtil.getGLPixelFormatFromStoreFormat(destination.getTextureStoreFormat()); } // bind... LwjglTextureStateUtil.doTextureBind(destination, 0, false); // Update the texture configuration (when necessary). if (origAlignment != alignment) { GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, alignment); } if (origRowLength != rowLength) { GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, rowLength); } if (origSkipPixels != srcOffsetX) { GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_PIXELS, srcOffsetX); } // NOTE: The below will be skipped for texture types that don't support them because we are passing in 0's. if (origSkipRows != srcOffsetY) { GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_ROWS, srcOffsetY); } if (origImageHeight != imageHeight) { GL11.glPixelStorei(GL12.GL_UNPACK_IMAGE_HEIGHT, imageHeight); } if (origSkipImages != srcOffsetZ) { GL11.glPixelStorei(GL12.GL_UNPACK_SKIP_IMAGES, srcOffsetZ); } // Upload the image region into the texture. try { switch (destination.getType()) { case TwoDimensional: GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, dstOffsetX, dstOffsetY, dstWidth, dstHeight, pixelFormat, GL11.GL_UNSIGNED_BYTE, source); break; case OneDimensional: GL11.glTexSubImage1D(GL11.GL_TEXTURE_1D, 0, dstOffsetX, dstWidth, pixelFormat, GL11.GL_UNSIGNED_BYTE, source); break; case ThreeDimensional: GL12.glTexSubImage3D(GL12.GL_TEXTURE_3D, 0, dstOffsetX, dstOffsetY, dstOffsetZ, dstWidth, dstHeight, dstDepth, pixelFormat, GL11.GL_UNSIGNED_BYTE, source); break; case CubeMap: GL11.glTexSubImage2D(LwjglTextureStateUtil.getGLCubeMapFace(dstFace), 0, dstOffsetX, dstOffsetY, dstWidth, dstHeight, pixelFormat, GL11.GL_UNSIGNED_BYTE, source); break; default: throw new Ardor3dException("Unsupported type for updateTextureSubImage: " + destination.getType()); } } finally { // Restore the texture configuration (when necessary)... // Restore alignment. if (origAlignment != alignment) { GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, origAlignment); } // Restore row length. if (origRowLength != rowLength) { GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, origRowLength); } // Restore skip pixels. if (origSkipPixels != srcOffsetX) { GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_PIXELS, origSkipPixels); } // Restore skip rows. if (origSkipRows != srcOffsetY) { GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_ROWS, origSkipRows); } // Restore image height. if (origImageHeight != imageHeight) { GL11.glPixelStorei(GL12.GL_UNPACK_IMAGE_HEIGHT, origImageHeight); } // Restore skip images. if (origSkipImages != srcOffsetZ) { GL11.glPixelStorei(GL12.GL_UNPACK_SKIP_IMAGES, origSkipImages); } } }
From source file:com.ardor3d.util.lwjgl.LwjglTextureUpdater.java
License:Open Source License
public static void updateTexture(final Texture texture, final ByteBuffer data, final int w, final int h, final Format format) { final int dataFormat = LwjglTextureUtil.getGLDataFormat(format); final int pixelFormat = LwjglTextureUtil.getGLPixelFormat(format); idBuff.clear();/*w w w .ja v a 2s.c o m*/ GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D, idBuff); final int oldTex = idBuff.get(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureId()); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); if (glTexSubImage2DSupported) { GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, w, h, pixelFormat, GL11.GL_UNSIGNED_BYTE, data); try { Util.checkGLError(); } catch (final OpenGLException e) { glTexSubImage2DSupported = false; updateTexture(texture, data, w, h, format); } } else { GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, dataFormat, w, h, 0, pixelFormat, GL11.GL_UNSIGNED_BYTE, data); } GL11.glBindTexture(GL11.GL_TEXTURE_2D, oldTex); }
From source file:com.badlogic.gdx.backends.jglfw.JglfwGL20.java
License:Apache License
public void glTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, Buffer pixels) { if (pixels instanceof ByteBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (ByteBuffer) pixels); else if (pixels instanceof ShortBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (ShortBuffer) pixels); else if (pixels instanceof IntBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (IntBuffer) pixels); else if (pixels instanceof FloatBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (FloatBuffer) pixels); else if (pixels instanceof DoubleBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (DoubleBuffer) pixels); else/*from ww w .j av a 2 s .c o m*/ throw new GdxRuntimeException("Can't use " + pixels.getClass().getName() + " with this method. Use ByteBuffer, ShortBuffer, IntBuffer, FloatBuffer or DoubleBuffer instead. Blame LWJGL"); }
From source file:com.badlogic.gdx.backends.lwjgl.LwjglGL10.java
License:Apache License
public final void glTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, Buffer pixels) { if (pixels instanceof ByteBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (ByteBuffer) pixels); else if (pixels instanceof ShortBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (ShortBuffer) pixels); else if (pixels instanceof IntBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (IntBuffer) pixels); else if (pixels instanceof FloatBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (FloatBuffer) pixels); else if (pixels instanceof DoubleBuffer) GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, (DoubleBuffer) pixels); else// w w w . ja v a2 s . c o m throw new GdxRuntimeException("Can't use " + pixels.getClass().getName() + " with this method. Use ByteBuffer, ShortBuffer, IntBuffer, FloatBuffer or DoubleBuffer instead. Blame LWJGL"); }
From source file:com.badlogic.gdx.tools.hiero.unicodefont.GlyphPage.java
License:Apache License
/** Loads a single glyph to the backing texture, if it fits. */ private void renderGlyph(Glyph glyph, int width, int height) { // Draw the glyph to the scratch image using Java2D. scratchGraphics.setComposite(AlphaComposite.Clear); scratchGraphics.fillRect(0, 0, MAX_GLYPH_SIZE, MAX_GLYPH_SIZE); scratchGraphics.setComposite(AlphaComposite.SrcOver); if (unicodeFont.getNativeRendering()) { for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();) { Effect effect = (Effect) iter.next(); if (effect instanceof ColorEffect) scratchGraphics.setColor(((ColorEffect) effect).getColor()); }/* ww w .j a v a 2s . c om*/ scratchGraphics.setColor(java.awt.Color.white); scratchGraphics.setFont(unicodeFont.getFont()); scratchGraphics.drawString("" + (char) glyph.getCodePoint(), 0, unicodeFont.getAscent()); } else { scratchGraphics.setColor(java.awt.Color.white); for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();) ((Effect) iter.next()).draw(scratchImage, scratchGraphics, unicodeFont, glyph); glyph.setShape(null); // The shape will never be needed again. } width = Math.min(width, texture.getWidth()); height = Math.min(height, texture.getHeight()); WritableRaster raster = scratchImage.getRaster(); int[] row = new int[width]; for (int y = 0; y < height; y++) { raster.getDataElements(0, y, width, 1, row); scratchIntBuffer.put(row); } GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, pageX, pageY, width, height, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, scratchByteBuffer); scratchIntBuffer.clear(); float u = pageX / (float) texture.getWidth(); float v = pageY / (float) texture.getHeight(); float u2 = (pageX + width) / (float) texture.getWidth(); float v2 = (pageY + height) / (float) texture.getHeight(); glyph.setTexture(texture, u, v, u2, v2); }
From source file:com.dinasgames.engine.graphics.Texture.java
public boolean loadFromImage(Image image, BoundingBox area) { int width = image.getWidth(); int height = image.getHeight(); if (area.width == 0 || area.height == 0 || (area.x <= 0 && area.y <= 0 && area.width >= width && area.height >= height)) { // Load entire image if (create(width, height)) { update(image);//from w w w . j ava 2s .co m GL11.glFlush(); return true; } return false; } else { // Load part of the image BoundingBox r = new BoundingBox(area); if (r.x < 0) { r.x = 0; } if (r.y < 0) { r.y = 0; } if (r.x + r.width > width) { r.width = width - r.x; } if (r.y + r.height > height) { r.height = height - r.y; } if (create((int) r.width, (int) r.height)) { ByteBuffer pixels = image.toByteBuffer(); int pos = 4 * ((int) r.x + (width * (int) r.y)); GL11.glBindTexture(GL11.GL_TEXTURE_2D, mTexture); for (int i = 0; i < r.height; i++) { GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, i, (int) r.width, 1, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, pixels); pos += 4 * width; } GL11.glFlush(); return true; } return false; } }