List of usage examples for org.lwjgl.opengl GL11 glBindTexture
public static void glBindTexture(@NativeType("GLenum") int target, @NativeType("GLuint") int texture)
From source file:processing.opengl.PLWJGL.java
License:Open Source License
@Override protected void bindTextureImpl(int target, int texture) { GL11.glBindTexture(target, texture); }
From source file:pw.knx.feather.font.FontCache.java
License:Apache License
/** * Update a portion of the current glyph cache texture using the contents of the glyphImage with glTexSubImage2D(). * * @param dirty The rectangular region in glyphImage that has changed and needs to be copied into the texture *///from w w w . java 2s. co m private void updateTexture(Rectangle dirty) { if (dirty != null) { updateBuffer(dirty.x, dirty.y, dirty.width, dirty.height); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); 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: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.//from ww w.jav 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 www . j av a2 s . co m 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 .ja v a 2s . c o 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:rainwarrior.mt100.client.PstFont.java
License:Open Source License
public void bindFontTexture() { GL11.glLoadIdentity();//from w w w .ja v a2 s .c o m GL11.glScalef(1F / textureWidth, 1F / textureHeight, 1F); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.get(0)); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); 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:resource.Material.java
License:Open Source License
public void bind() { GL13.glActiveTexture(GL13.GL_TEXTURE0); if (textures[0] == null) { GL11.glDisable(GL11.GL_TEXTURE_2D); } else {// w w w . j a va 2 s .co m GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textures[0].getID()); // GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE); } GL13.glActiveTexture(GL13.GL_TEXTURE1); if (textures[1] == null) { GL11.glDisable(GL11.GL_TEXTURE_2D); } else { GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textures[1].getID()); // GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE); } GL13.glActiveTexture(GL13.GL_TEXTURE0); // And set the materails GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SPECULAR, get(specular)); GL11.glMaterial(GL11.GL_FRONT, GL11.GL_DIFFUSE, get(diffuse)); GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SHININESS, get(shininess)); }
From source file:resource.ResourceManager.java
License:Open Source License
public void bindTexture(Texture tex) { // Put Image In Memory ByteBuffer scratch = ByteBuffer.allocateDirect(4 * tex.getSize() * tex.getSize()); byte data[] = (byte[]) tex.getImage().getRaster().getDataElements(0, 0, tex.getSize(), tex.getSize(), null); scratch.clear();//from w ww .j a v a 2 s .c o m scratch.put(data); scratch.rewind(); IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer(); GL11.glGenTextures(buf); // Create a texure ID tex.setID(buf.get(0)); GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getID()); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); // Generate The Texture GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, GL11.GL_RGBA, tex.getSize(), tex.getSize(), GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, scratch); }
From source file:rtype.entity.Missile.java
License:Open Source License
public void draw() { animationCursor += animationSpeed * tick; animationCursor %= animationTextures.length; GL11.glLoadIdentity();/*from w ww .ja v a2 s. co m*/ GL11.glTranslatef(position.x, position.y, Prototyp.DEFAULT_Z); // Translate Into/Out Of The Screen By z GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.animationTextures[(int) animationCursor].getTextureId()); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glBegin(GL11.GL_QUADS); { GL11.glTexCoord2f(textureRight, textureUp); //Upper right GL11.glVertex2f(width, -height); GL11.glTexCoord2f(textureLeft, textureUp); //Upper left GL11.glVertex2f(-width, -height); GL11.glTexCoord2f(textureLeft, textureDown); //Lower left GL11.glVertex2f(-width, height); GL11.glTexCoord2f(textureRight, textureDown); // Lower right GL11.glVertex2f(width, height); } GL11.glEnd(); }
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 {//from w w w . j a v a2s . c o m 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; }