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:com.dinasgames.engine.graphics.Texture.java
protected void update(ByteBuffer pixels, int width, int height, int x, int y) { assert (x + width <= mWidth); assert (y + height <= mHeight); if (pixels != null && mTexture > 0) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, mTexture); GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, x, y, width, height, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, pixels);/* ww w .j a va 2 s .com*/ mPixelsFlipped = false; mCacheId = getUniqueId(); } }
From source file:com.flowpowered.caustic.lwjgl.gl20.GL20Texture.java
License:MIT License
@Override public void setImageData(ByteBuffer imageData, int width, int height) { checkCreated();/*from w w w . j av a2s .c om*/ if (width <= 0) { throw new IllegalArgumentException("Width must be greater than zero"); } if (height <= 0) { throw new IllegalArgumentException("Height must be greater than zero"); } // Back up the old values int oldWidth = this.width; int oldHeight = this.height; // Update the texture width and height this.width = width; this.height = height; // Bind the texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); // Upload the texture to the GPU final boolean hasInternalFormat = internalFormat != null; if (minFilter.needsMipMaps() && imageData != null) { // Build mipmaps if using mip mapped filters GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, hasInternalFormat ? internalFormat.getGLConstant() : format.getGLConstant(), width, height, format.getGLConstant(), hasInternalFormat ? internalFormat.getComponentType().getGLConstant() : DataType.UNSIGNED_BYTE.getGLConstant(), imageData); } else { // Else just make it a normal texture, use byte alignment GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); // Check if we can only upload without reallocating if (imageData != null && width == oldWidth && height == oldHeight) { GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, width, height, format.getGLConstant(), hasInternalFormat ? internalFormat.getComponentType().getGLConstant() : DataType.UNSIGNED_BYTE.getGLConstant(), imageData); } else { // Reallocate and upload the image GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, hasInternalFormat ? internalFormat.getGLConstant() : format.getGLConstant(), width, height, 0, format.getGLConstant(), hasInternalFormat ? internalFormat.getComponentType().getGLConstant() : DataType.UNSIGNED_BYTE.getGLConstant(), imageData); } } // Unbind the texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); // Check for errors LWJGLUtil.checkForGLError(); }
From source file:com.flowpowered.caustic.lwjgl.gl30.GL30Texture.java
License:MIT License
@Override public void setImageData(ByteBuffer imageData, int width, int height) { checkCreated();/*w w w .j av a 2s. co m*/ if (width <= 0) { throw new IllegalArgumentException("Width must be greater than zero"); } if (height <= 0) { throw new IllegalArgumentException("Height must be greater than zero"); } // Back up the old values int oldWidth = this.width; int oldHeight = this.height; // Update the texture width and height this.width = width; this.height = height; // Bind the texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); // Use byte alignment GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); // Upload the texture final boolean hasInternalFormat = internalFormat != null; // Check if we can only upload without reallocating if (imageData != null && width == oldWidth && height == oldHeight) { GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, width, height, format.getGLConstant(), hasInternalFormat ? internalFormat.getComponentType().getGLConstant() : DataType.UNSIGNED_BYTE.getGLConstant(), imageData); } else { // Reallocate and upload the image GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, hasInternalFormat ? internalFormat.getGLConstant() : format.getGLConstant(), width, height, 0, format.getGLConstant(), hasInternalFormat ? internalFormat.getComponentType().getGLConstant() : DataType.UNSIGNED_BYTE.getGLConstant(), imageData); } // Generate mipmaps if necessary if (minFilter.needsMipMaps() && imageData != null) { GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); } // Unbind the texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); // Check for errors LWJGLUtil.checkForGLError(); }
From source file:com.gundogstudios.modules.DesktopGL11.java
License:Open Source License
public final void glTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, ByteBuffer pixels) { GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); }
From source file:com.opengrave.og.resources.TextureAtlasEditable.java
License:Open Source License
@Override public void bind(int t) { GL13.glActiveTexture(t);//www . j av a2s .c o m if (pixels != null) { id = GL11.glGenTextures(); mainBuf = BufferUtils.createByteBuffer(4 * this.size * this.size); // for (int i = this.size - 1; i >= 0; i--) { for (int i = 0; i < this.size; i++) { for (int j = 0; j < this.size; j++) { float r = 1f, g = 1f, b = 1f, a = 0f; if (i < py && j < px) { int pixel = pixels[i * px + j]; r = (float) ((pixel >> 16) & 0xFF) / 255f; g = (float) ((pixel >> 8) & 0xFF) / 255f; b = (float) (pixel & 0xFF) / 255f; a = (float) ((pixel >> 24) & 0xFF) / 255f; } addColour(r, g, b, a); } } mainBuf.flip(); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, id); GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL11.GL_RGBA, this.size, this.size, 1, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, mainBuf); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0); pixels = null; } synchronized (changeList) { if (changeList.size() < 10) { GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, id); for (TextureEditableDeferedChanges change : changeList) { applyChangeToMainBuffer(change); ByteBuffer buf = BufferUtils.createByteBuffer(4); buf.put((byte) (255 * change.getColour().z)).put((byte) (255 * change.getColour().y)) .put((byte) (255 * change.getColour().x)).put((byte) (255 * change.getColour().w)); buf.flip(); GL11.glTexSubImage2D(GL30.GL_TEXTURE_2D_ARRAY, 0, change.getX(), change.getY(), 1, 1, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, buf); } GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0); } else { // Replace the whole image. There's bound to be better ways // around this... for (TextureEditableDeferedChanges change : changeList) { applyChangeToMainBuffer(change); } mainBuf.position(0); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, id); Util.checkErr(); GL12.glTexSubImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, size, size, 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, mainBuf); Util.checkErr(); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0); Util.checkErr(); } changeList.clear(); } Util.checkErr(); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, id); lastTexNum = t; }
From source file:com.opengrave.og.resources.TextureEditable.java
License:Open Source License
@Override public void bind(int t) { GL13.glActiveTexture(t);/*from ww w . ja v a2 s.co m*/ synchronized (changeList) { if (changeList.size() < 10) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); for (TextureEditableDeferedChanges change : changeList) { applyChangeToMainBuffer(change); ByteBuffer buf = BufferUtils.createByteBuffer(4); buf.put((byte) (255 * change.getColour().z)).put((byte) (255 * change.getColour().y)) .put((byte) (255 * change.getColour().x)).put((byte) (255 * change.getColour().w)); buf.flip(); GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, change.getX(), change.getY(), 1, 1, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, buf); } GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); } else { // Replace the whole image. There's bound to be better ways // around this... for (TextureEditableDeferedChanges change : changeList) { applyChangeToMainBuffer(change); } mainBuf.position(0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); Util.checkErr(); GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, size, size, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, mainBuf); Util.checkErr(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); Util.checkErr(); } changeList.clear(); } Util.checkErr(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); lastTexNum = t; }
From source file:com.telinc1.rpjg.texture.Texture.java
License:Apache License
/** * Positions an image on top of the texture. * /*from w w w . ja va 2s . co m*/ * @param x - The X position at which to place the subimage. * @param y - The Y position at which to place the subimage. * @param width - The width of the subimage. * @param height - The height of the subimage. * @param format - The byte order of the subimage. * @param data - The data to upload. */ public void upload(int x, int y, int width, int height, int format, ByteBuffer data) { this.bind(); this.setUnpackAlignment(); GL11.glTexSubImage2D(this.getTarget(), 0, x, y, width, height, format, GL11.GL_UNSIGNED_BYTE, data); }
From source file:com.xrbpowered.gl.examples.GLLife.java
License:Open Source License
private void addGlider(int x, int y, int width, int height, int[] pixels) { IntBuffer intBuffer = ByteBuffer.allocateDirect(4 * width * height).order(ByteOrder.nativeOrder()) .asIntBuffer();//from w ww .j a v a 2 s . co m intBuffer.put(pixels); intBuffer.flip(); GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, buffers[1 - targetBuffer].getColorTexId()); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, x, y, width, height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuffer); }
From source file:cuchaz.jfxgl.prism.JFXGLContext.java
License:Open Source License
@Override public void texSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, java.nio.Buffer pixels) { // NOTE: null pixels are allowed if (pixels != null && !(pixels instanceof ByteBuffer)) { throw new Error( "buffer should be a " + ByteBuffer.class.getName() + ", not a " + pixels.getClass().getName()); }/* ww w.j a va 2 s.c o m*/ ByteBuffer buf = (ByteBuffer) pixels; // if buf is not direct, copy it to a direct buffer if (buf != null && !buf.isDirect()) { imageBuf = updateBuffer(imageBuf, buf); buf = imageBuf; } GL11.glTexSubImage2D(translatePrismToGL(target), level, xoffset, yoffset, width, height, translatePrismToGL(format), translatePrismToGL(type), buf); }
From source file:edu.csun.ecs.cs.multitouchj.application.whiteboard.ui.InteractiveCanvas.java
License:Apache License
public void render() { synchronized (resizableBufferedImage) { Texture texture = getTexture();//from w ww.jav a 2s . co m if (texture == null) { try { Image image = getBufferedImageImage(resizableBufferedImage.getBufferedImage()); texture = getTextureManager().createTexture("" + this.hashCode(), image, true); setTexture(texture); } catch (Exception exception) { log.debug("Failed to generate texture from ResizableBufferedImage.", exception); } } if (isDirty) { Image image = getBufferedImageImage(resizableBufferedImage.getBufferedImage()); ByteBuffer imageData = prepareImage(image); GL11.glEnable(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT); GL11.glBindTexture(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, texture.getId().intValue()); GL11.glTexSubImage2D(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, image.getWidth(), image.getHeight(), (image.hasAlpha()) ? GL11.GL_RGBA : GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, imageData); isDirty = false; } } super.render(); }