List of usage examples for org.lwjgl.opengl GL11 glTexImage2D
public static void glTexImage2D(@NativeType("GLenum") int target, @NativeType("GLint") int level, @NativeType("GLint") int internalformat, @NativeType("GLsizei") int width, @NativeType("GLsizei") int height, @NativeType("GLint") int border, @NativeType("GLenum") int format, @NativeType("GLenum") int type, @Nullable @NativeType("void const *") double[] pixels)
From source file:playn.java.JavaGLContext.java
License:Apache License
void updateTexture(int tex, BufferedImage image) { // Convert the image into a format for quick uploading image = convertImage(image);/*from w ww.j ava 2s. c o m*/ DataBuffer dbuf = image.getRaster().getDataBuffer(); ByteBuffer bbuf; int format, type; if (image.getType() == BufferedImage.TYPE_INT_ARGB_PRE) { DataBufferInt ibuf = (DataBufferInt) dbuf; int iSize = ibuf.getSize() * 4; bbuf = checkGetImageBuffer(iSize); bbuf.asIntBuffer().put(ibuf.getData()); bbuf.position(bbuf.position() + iSize); bbuf.flip(); format = GL12.GL_BGRA; type = GL12.GL_UNSIGNED_INT_8_8_8_8_REV; } else if (image.getType() == BufferedImage.TYPE_4BYTE_ABGR) { DataBufferByte dbbuf = (DataBufferByte) dbuf; bbuf = checkGetImageBuffer(dbbuf.getSize()); bbuf.put(dbbuf.getData()); bbuf.flip(); format = GL11.GL_RGBA; type = GL12.GL_UNSIGNED_INT_8_8_8_8; } else { // Something went awry and convertImage thought this image was in a good form already, // except we don't know how to deal with it throw new RuntimeException("Image type wasn't converted to usable: " + image.getType()); } bindTexture(tex); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, image.getWidth(), image.getHeight(), 0, format, type, bbuf); checkGLError("updateTexture"); }
From source file:playn.java.JavaImage.java
License:Apache License
@Override protected void upload(Graphics gfx, Texture tex) { // Convert the bitmap into a format for quick uploading (NOOPs if already optimized) JavaGraphics jgfx = (JavaGraphics) gfx; BufferedImage bitmap = JavaGraphics.convertImage(img); DataBuffer dbuf = bitmap.getRaster().getDataBuffer(); ByteBuffer bbuf;/*w w w.j a v a 2s .c o m*/ int format, type; if (bitmap.getType() == BufferedImage.TYPE_INT_ARGB_PRE) { DataBufferInt ibuf = (DataBufferInt) dbuf; int iSize = ibuf.getSize() * 4; bbuf = jgfx.checkGetImageBuffer(iSize); bbuf.asIntBuffer().put(ibuf.getData()); bbuf.position(bbuf.position() + iSize); bbuf.flip(); format = GL12.GL_BGRA; type = GL12.GL_UNSIGNED_INT_8_8_8_8_REV; } else if (bitmap.getType() == BufferedImage.TYPE_4BYTE_ABGR) { DataBufferByte dbbuf = (DataBufferByte) dbuf; bbuf = jgfx.checkGetImageBuffer(dbbuf.getSize()); bbuf.put(dbbuf.getData()); bbuf.flip(); format = GL11.GL_RGBA; type = GL12.GL_UNSIGNED_INT_8_8_8_8; } else { // Something went awry and convertImage thought this image was in a good form already, // except we don't know how to deal with it throw new RuntimeException("Image type wasn't converted to usable: " + bitmap.getType()); } gfx.gl.glBindTexture(GL11.GL_TEXTURE_2D, tex.id); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, bitmap.getWidth(), bitmap.getHeight(), 0, format, type, bbuf); gfx.gl.checkError("updateTexture"); }
From source file:playn.java.LWJGLGraphics.java
License:Apache License
@Override protected void upload(BufferedImage img, Texture tex) { // Convert the bitmap into a format for quick uploading (NOOPs if already optimized) BufferedImage bitmap = convertImage(img); DataBuffer dbuf = bitmap.getRaster().getDataBuffer(); ByteBuffer bbuf;/*from w w w . j a va 2s.c o m*/ int format, type; if (bitmap.getType() == BufferedImage.TYPE_INT_ARGB_PRE) { DataBufferInt ibuf = (DataBufferInt) dbuf; int iSize = ibuf.getSize() * 4; bbuf = checkGetImageBuffer(iSize); bbuf.asIntBuffer().put(ibuf.getData()); bbuf.position(bbuf.position() + iSize); bbuf.flip(); format = GL12.GL_BGRA; type = GL12.GL_UNSIGNED_INT_8_8_8_8_REV; } else if (bitmap.getType() == BufferedImage.TYPE_4BYTE_ABGR) { DataBufferByte dbbuf = (DataBufferByte) dbuf; bbuf = checkGetImageBuffer(dbbuf.getSize()); bbuf.put(dbbuf.getData()); bbuf.flip(); format = GL11.GL_RGBA; type = GL12.GL_UNSIGNED_INT_8_8_8_8; } else { // Something went awry and convertImage thought this image was in a good form already, // except we don't know how to deal with it throw new RuntimeException("Image type wasn't converted to usable: " + bitmap.getType()); } gl.glBindTexture(GL11.GL_TEXTURE_2D, tex.id); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, bitmap.getWidth(), bitmap.getHeight(), 0, format, type, bbuf); gl.checkError("updateTexture"); }
From source file:processing.lwjgl.PGL.java
License:Open Source License
public void texImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, Buffer data) { GL11.glTexImage2D(target, level, internalFormat, width, height, border, format, type, (IntBuffer) data); }
From source file:processing.opengl.PLWJGL.java
License:Open Source License
@Override public void texImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, Buffer data) { GL11.glTexImage2D(target, level, internalFormat, width, height, border, format, type, (IntBuffer) data); }
From source file:pw.knx.feather.font.FontCache.java
License:Apache License
/** * Allocate a new OpenGL texture for caching pre-rendered glyph images. The new texture is initialized to fully transparent * white so the individual glyphs images within can have a transparent border between them. The new texture remains bound * after returning from the function./* ww w .j av a 2 s . c o m*/ */ private void allocateTexture() { /* Initialize the background to all white but fully transparent. */ glyphGraphics.clearRect(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT); /* Allocate new OpenGL texure */ texture = GL11.glGenTextures(); /* Load imageBuffer with pixel data ready for transfer to OpenGL texture */ updateBuffer(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT); /* * Initialize texture with the now cleared BufferedImage. Using a texture with GL_ALPHA8 internal format may result in * faster rendering since the GPU has to only fetch 1 byte per texel instead of 4 with a regular RGBA texture. */ GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_ALPHA8, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, imageBuffer); /* Explicitly disable mipmap support because updateTexture() will only update the base level 0 */ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); }
From source file:rainwarrior.mt100.client.PstFont.java
License:Open Source License
public PstFont() { charsize = 1;//from w w w . jav a2 s .c om width = 1; height = 1; length = 1; lShift = 0; textureWidth = 1; textureHeight = 1; ByteBuffer textureBuffer = BufferUtils.createByteBuffer(1); texture = BufferUtils.createIntBuffer(1); GL11.glGenTextures(texture); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.get(0)); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0x0, GL11.GL_ALPHA, textureWidth, textureHeight, 0x0, GL11.GL_ALPHA, GL11.GL_UNSIGNED_BYTE, textureBuffer); }
From source file:rainwarrior.mt100.client.PstFont.java
License:Open Source License
public PstFont(String fontFile) { this.fontFile = fontFile; boolean hasUni; boolean psf1; try {/*from w w w . j a v a 2 s.co m*/ InputStream str = this.getClass().getResourceAsStream(fontFile); if (str != null) { GZIPInputStream stream = new GZIPInputStream(str); DataInputStream file = new DataInputStream(stream); byte[] b = new byte[4]; for (int i = 0; i < 4; i++) b[i] = file.readByte(); int hoffset; if (b[0] == (byte) 0x36 && b[1] == (byte) 04) // psf1 magic { psf1 = true; width = 8; height = charsize = b[3]; length = ((b[2] & 0x01) != 0) ? 512 : 256; lShift = 4; hasUni = ((b[2] & 0x02) != 0); hoffset = 0; } else if (b[0] == (byte) 0x72 && b[1] == (byte) 0xB5 && b[2] == (byte) 0x4A && b[3] == (byte) 0x86) // psf2 magic { psf1 = false; ByteBuffer header = ByteBuffer.allocate(28); file.readFully(header.array(), 0, 28); header.order(ByteOrder.LITTLE_ENDIAN); int version = header.getInt(); hoffset = header.getInt() - 32; if (debug) MT100.logger.info("hoffset: " + hoffset); int flags = header.getInt(); hasUni = ((flags & 0x01) != 0); length = header.getInt(); if (length != 256 && length != 512) { throw new RuntimeException("PSF2 file of unsupported length:" + length); } lShift = 4; charsize = header.getInt(); height = header.getInt(); width = header.getInt(); } else { if (debug) MT100.logger.severe("File " + fontFile + " is not a PSf file: " + b[0] + " " + b[1] + " " + b[2] + " " + b[3]); throw new java.io.IOException(); } if (debug) MT100.logger.info("width: " + width); if (debug) MT100.logger.info("height: " + height); if (debug) MT100.logger.info("charsize: " + charsize); if (debug) MT100.logger.info("length: " + length); ByteBuffer chars = ByteBuffer.allocate(length * charsize); chars.order(ByteOrder.LITTLE_ENDIAN); file.skipBytes(hoffset); file.readFully(chars.array(), 0, length * charsize); int roundWidth = charsize / height; // bytes textureWidth = 1; while (textureWidth < (1 << lShift) * width) { textureWidth <<= 1; } textureHeight = 1; while (textureHeight < (length >> lShift) * height) { textureHeight <<= 1; } ByteBuffer textureBuffer = BufferUtils.createByteBuffer(textureWidth * textureHeight); byte bt; for (int i = 0; i < (1 << lShift); i++) { // if(debug) MT100.logger.info("i: " + i + ", ^i: "+ ((i >> 4) + (i & 0xF) * (length >> 4))); for (int j = 0; j < (length >> lShift); j++) { // if(debug) MT100.logger.info("j: " + j + " " + (j * roundWidth) + " " + (i * charsize + j * roundWidth) + " " + ((i >> 4) * width + (i & 0xF) * 16 * width * height + j * 16 * width)); for (int k = 0; k < height; k++) { // if(debug) MT100.logger.info("k: " + k); for (int l = 0; l < width; l++) { bt = (byte) (((chars .get((i * (length >> lShift) + j) * charsize + k * roundWidth + (l >> 3)) & (1 << (7 - (l & 7)))) != 0) ? 0xFF : 0x00); textureBuffer.put(i * width + (j * height + k) * textureWidth + l, bt); } } } } texture = BufferUtils.createIntBuffer(1); GL11.glGenTextures(texture); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.get(0)); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0x0, GL11.GL_ALPHA, textureWidth, textureHeight, 0x0, GL11.GL_ALPHA, GL11.GL_UNSIGNED_BYTE, textureBuffer); int ss = (psf1 ? 0xFFFE : 0xFE); int term = (psf1 ? 0xFFFF : 0xFF); if (hasUni) { int c = 0; int sep; int i = 0; boolean leading = true; do { c = 0; sep = file.readByte(); if (sep < 0) sep += 0x100; if (psf1) { int sep2 = file.readByte(); if (sep2 < 0) sep2 += 0x100; sep |= (sep2 << 8); } if (sep < 0) sep += (psf1 ? 0x10000 : 0x100); if (sep == ss) { leading = false; } else if (sep == term) { leading = true; i++; c = 0; } else // real char { if (!psf1) // parse utf8; TODO: maybe more compact? { int shift; if (sep >= 0xFE) { throw new RuntimeException("Illegal UTF8 start byte"); } if (sep >= 0xFC) { shift = 5; c |= ((sep & 0x01) << 30); } else if (sep >= 0xF8) { shift = 4; c |= ((sep & 0x03) << 24); } else if (sep >= 0xF0) { shift = 3; c |= ((sep & 0x07) << 18); } else if (sep >= 0xE0) { shift = 2; c |= ((sep & 0x0F) << 12); } else if (sep >= 0xC0) { shift = 1; c |= ((sep & 0x1F) << 6); } else if (sep >= 0x80) { throw new RuntimeException("Illegal UTF8 start byte: " + sep); } else { shift = 0; c = sep; } if (debug) MT100.logger.info("c: " + c + ", sep: " + sep + ", shift: " + shift); while (shift-- > 0) { sep = file.readByte(); if (sep < 0) sep += 0x100; if (sep >= 0xC0 || sep < 0x80) { throw new RuntimeException("Illegal UTF8 intermediate byte" + sep); } c |= (sep & 0x3F) << (shift * 6); } } else { c = sep; } if (leading) { PstFontRegistry.fontMap.put(c, this); PstFontRegistry.indexMap.put(c, i); if (debug) MT100.logger.info("c: " + c + ", sep: " + sep + ", i: " + i); } } } while (i < length); } else { for (int i = 0; i < length; i++) { PstFontRegistry.fontMap.put(i, this); PstFontRegistry.indexMap.put(i, i); } } // System.out.println(file); } else { MT100.logger.warning("No font file!"); } } catch (java.io.IOException e) { throw new RuntimeException(e); } debug = false; }
From source file:rtype.JNLPTextureLoader.java
License:Open Source License
private Texture loadTexture(String path, int xOffSet, int yOffSet, int textWidth, int textHeight) { BufferedImage buffImage = null; try {// w w w . j ava 2 s .c om if (imageCache.get(path) != null) buffImage = (BufferedImage) imageCache.get(path); else { System.out.println("Loading image:" + path); buffImage = ImageIO.read(new FileImageInputStream(new File(path))); imageCache.put(path, buffImage); } } catch (IOException e) { e.printStackTrace(); } int bytesPerPixel = buffImage.getColorModel().getPixelSize() / 8; ByteBuffer scratch = ByteBuffer.allocateDirect(textWidth * textHeight * bytesPerPixel) .order(ByteOrder.nativeOrder()); DataBufferByte data = ((DataBufferByte) buffImage.getRaster().getDataBuffer()); for (int i = 0; i < textHeight; i++) scratch.put(data.getData(), (xOffSet + (yOffSet + i) * buffImage.getWidth()) * bytesPerPixel, textWidth * bytesPerPixel); scratch.rewind(); // Create A IntBuffer For Image Address In Memory IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer(); GL11.glGenTextures(buf); // Create Texture In OpenGL // Create Nearest Filtered Texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0)); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, textWidth, textHeight, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, scratch); Texture newTexture = new Texture(); newTexture.textureId = buf.get(0); // Return Image Addresses In Memory newTexture.textureHeight = textHeight; newTexture.textureWidth = textWidth; return newTexture; }
From source file:rtype.Prototyp.java
License:Open Source License
private void createOffScreenBuffer() { int bytesPerPixel = 3; ByteBuffer scratch = ByteBuffer.allocateDirect(1024 * 1024 * bytesPerPixel); IntBuffer buf = ByteBuffer.allocateDirect(12).order(ByteOrder.nativeOrder()).asIntBuffer(); GL11.glGenTextures(buf); // Create Texture In OpenGL GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0)); SCREEN_TEXTURE_ID = buf.get(0);//w w w . ja v a 2s. c o m int glType = GL11.GL_RGB; GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, glType, 1024, 1024, 0, glType, GL11.GL_UNSIGNED_BYTE, scratch); }