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:im.bci.jnuit.lwjgl.assets.AssetsLoader.java
License:Open Source License
public Texture grabScreenToTexture() { int maxSize = GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE); Texture texture = new Texture(Math.min(maxSize, LwjglHelper.getWidth()), Math.min(maxSize, LwjglHelper.getHeight()), false); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getId()); LwjglHelper.setupGLTextureParams();/*from w w w . jav a2s . c om*/ GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, 0, 0, texture.getWidth(), texture.getHeight(), 0); return texture; }
From source file:im.bci.jnuit.lwjgl.assets.AssetsLoader.java
License:Open Source License
private Texture loadPngTexture(String name) throws FileNotFoundException, IOException { InputStream is = vfs.open(name); try {//w ww.j a v a 2 s. co m PNGDecoder decoder = new PNGDecoder(is); int bpp; PNGDecoder.Format format; int pixelFormat; int texWidth = decoder.getWidth(); int texHeight = decoder.getHeight(); boolean hasAlpha = decoder.hasAlpha(); if (hasAlpha) { bpp = 4; format = PNGDecoder.Format.RGBA; pixelFormat = GL11.GL_RGBA; } else { bpp = 3; format = PNGDecoder.Format.RGB; pixelFormat = GL11.GL_RGB; } int stride = bpp * texWidth; ByteBuffer buffer = ByteBuffer.allocateDirect(stride * texHeight); decoder.decode(buffer, stride, format); buffer.flip(); Texture texture = new Texture(texWidth, texHeight, hasAlpha); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getId()); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); LwjglHelper.setupGLTextureParams(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, pixelFormat, texWidth, texHeight, 0, pixelFormat, GL11.GL_UNSIGNED_BYTE, buffer); return texture; } finally { is.close(); } }
From source file:im.bci.jnuit.lwjgl.assets.AssetsLoader.java
License:Open Source License
private Texture loadJpegTexture(String name) throws IOException { InputStream is = vfs.open(name); try {/*from w w w. ja v a 2 s.co m*/ JPEGDecoder decoder = new JPEGDecoder(is); decoder.startDecode(); int texWidth = decoder.getImageWidth(); int texHeight = decoder.getImageHeight(); int stride = 3 * texWidth; ByteBuffer buffer = ByteBuffer.allocateDirect(stride * texHeight); decoder.decode(buffer, stride, decoder.getNumMCURows(), YUVtoRGB.instance); buffer.flip(); Texture texture = new Texture(texWidth, texHeight, false); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getId()); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); LwjglHelper.setupGLTextureParams(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, texWidth, texHeight, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, buffer); return texture; } finally { is.close(); } }
From source file:im.bci.jnuit.lwjgl.LwjglNuitFont.java
License:Open Source License
private void drawString(float x, float y, String whatchars, int startIndex, int endIndex, float scaleX, float scaleY, Align format) { IntObject intObject = null;//from w ww . jav a2 s .com int charCurrent; int totalwidth = 0; int i = startIndex, d, c; float startY = 0; switch (format) { case RIGHT: { d = -1; c = correctR; while (i < endIndex) { if (whatchars.charAt(i) == '\n') { startY -= fontHeight; } i++; } break; } case CENTER: { for (int l = startIndex; l <= endIndex; l++) { charCurrent = whatchars.charAt(l); if (charCurrent == '\n') { break; } if (charCurrent < 256) { intObject = charArray[charCurrent]; } else { intObject = customChars.get(new Character((char) charCurrent)); } totalwidth += intObject.width - correctL; } totalwidth /= -2; } case LEFT: default: d = 1; c = correctL; break; } GL11.glBindTexture(GL11.GL_TEXTURE_2D, fontTextureID); GL11.glBegin(GL11.GL_QUADS); while (i >= startIndex && i <= endIndex) { charCurrent = whatchars.charAt(i); if (charCurrent < 256) { intObject = charArray[charCurrent]; } else { intObject = customChars.get(new Character((char) charCurrent)); } if (intObject != null) { if (d < 0) { totalwidth += (intObject.width - c) * d; } if (charCurrent == '\n') { startY -= fontHeight * d; totalwidth = 0; if (format == Align.CENTER) { for (int l = i + 1; l <= endIndex; l++) { charCurrent = whatchars.charAt(l); if (charCurrent == '\n') { break; } if (charCurrent < 256) { intObject = charArray[charCurrent]; } else { intObject = customChars.get(new Character((char) charCurrent)); } totalwidth += intObject.width - correctL; } totalwidth /= -2; } // if center get next lines total width/2; } else { drawQuad((totalwidth + intObject.width) * scaleX + x, startY * scaleY + y, totalwidth * scaleX + x, (startY + intObject.height) * scaleY + y, intObject.storedX + intObject.width, intObject.storedY + intObject.height, intObject.storedX, intObject.storedY); if (d > 0) { totalwidth += (intObject.width - c) * d; } } i += d; } } GL11.glEnd(); }
From source file:im.bci.jnuit.lwjgl.LwjglNuitFont.java
License:Open Source License
public static int loadImage(BufferedImage bufferedImage) { short width = (short) bufferedImage.getWidth(); short height = (short) bufferedImage.getHeight(); // textureLoader.bpp = bufferedImage.getColorModel().hasAlpha() ? // (byte)32 : (byte)24; int bpp = (byte) bufferedImage.getColorModel().getPixelSize(); ByteBuffer byteBuffer;//from ww w.j av a 2 s . c o m DataBuffer db = bufferedImage.getData().getDataBuffer(); if (db instanceof DataBufferInt) { int intI[] = ((DataBufferInt) (bufferedImage.getData().getDataBuffer())).getData(); byte newI[] = new byte[intI.length * 4]; for (int i = 0; i < intI.length; i++) { byte b[] = intToByteArray(intI[i]); int newIndex = i * 4; newI[newIndex] = b[1]; newI[newIndex + 1] = b[2]; newI[newIndex + 2] = b[3]; newI[newIndex + 3] = b[0]; } byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()) .put(newI); } else { byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()) .put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData()); } byteBuffer.flip(); int internalFormat = GL11.GL_RGBA8, format = GL11.GL_RGBA; IntBuffer textureId = BufferUtils.createIntBuffer(1); GL11.glGenTextures(textureId); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId.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_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE); GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, internalFormat, width, height, format, GL11.GL_UNSIGNED_BYTE, byteBuffer); return textureId.get(0); }
From source file:im.bci.jnuit.lwjgl.LwjglNuitFont.java
License:Open Source License
public void deleteFontTexture() { IntBuffer scratch = BufferUtils.createIntBuffer(1); scratch.put(0, fontTextureID);//from w w w . j ava 2 s. c o m GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); GL11.glDeleteTextures(scratch); }
From source file:im.bci.jnuit.lwjgl.LwjglNuitRenderer.java
License:Open Source License
@Override public void visit(Widget widget, TexturedBackground background) { IAnimationFrame frame = background.getPlay().getCurrentFrame(); if (null != frame) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, (Integer) frame.getImage().getId()); float x1 = widget.getX(); float x2 = widget.getX() + widget.getWidth(); float y1 = widget.getY(); float y2 = widget.getY() + widget.getHeight(); float u1 = background.isMirrorX() ? frame.getU2() : frame.getU1(); float v1 = background.isMirrorY() ? frame.getV2() : frame.getV1(); float u2 = background.isMirrorX() ? frame.getU1() : frame.getU2(); float v2 = background.isMirrorY() ? frame.getV1() : frame.getV2(); GL11.glBegin(GL11.GL_QUADS);//from w w w . j a va 2s .com GL11.glTexCoord2f(u1, v2); GL11.glVertex2f(x1, y2); GL11.glTexCoord2f(u2, v2); GL11.glVertex2f(x2, y2); GL11.glTexCoord2f(u2, v1); GL11.glVertex2f(x2, y1); GL11.glTexCoord2f(u1, v1); GL11.glVertex2f(x1, y1); GL11.glEnd(); } }
From source file:im.bci.jnuit.lwjgl.sprite.SpriteBatcher.java
License:Open Source License
private void flush() { if (currentSpriteInBatch > 0) { boolean hasAlpha = true; if (hasAlpha) { GL11.glEnable(GL11.GL_BLEND); }//from w ww .j a va 2 s .co m texCoords.flip(); vertices.flip(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, (Integer) currentImage.getId()); GL11.glTexCoordPointer(2, 0, texCoords); GL11.glVertexPointer(2, 0, vertices); GL11.glColor4ub(currentColor.getRedByte(), currentColor.getGreenByte(), currentColor.getBlueByte(), currentColor.getAlphaByte()); GL11.glDrawArrays(GL11.GL_QUADS, 0, currentSpriteInBatch * 4); if (hasAlpha) { GL11.glDisable(GL11.GL_BLEND); } GL11.glColor3f(1f, 1f, 1f); texCoords.rewind(); texCoords.limit(texCoords.capacity()); vertices.rewind(); vertices.limit(texCoords.capacity()); currentSpriteInBatch = 0; } }
From source file:info.plugmania.novacraft.gui.Button.java
License:GNU General Public License
@Override() public void draw(Screen screen) { FontRenderer fr = Minecraft.getMinecraft().fontRenderer; GL11.glBindTexture(GL11.GL_TEXTURE_2D, Minecraft.getMinecraft().novaCraftClient.getRenderManager().addTexture("/gui/gui.png")); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); boolean isMouseOver = screen.getMouseX(offset) >= this.getX() && screen.getMouseY(offset) >= this.getY() && screen.getMouseX(offset) < this.getX() + this.getWidth() && screen.getMouseY(offset) < this.getY() + this.getHeight(); screen.drawTexturedModalRect(getScreenX(screen), getScreenY(screen), 0, 46 + getHoverState(isMouseOver) * 20, this.width / 2, this.height); screen.drawTexturedModalRect(getScreenX(screen) + this.width / 2, getScreenY(screen), 200 - this.width / 2, 46 + getHoverState(isMouseOver) * 20, this.width / 2, this.height); int colour = 14737632; if (!this.enabled) { colour = -6250336;//from ww w. j a v a 2s.c o m } else if (isMouseOver) { colour = 16777120; } screen.drawCentredString(getContent(), getScreenX(screen) + getCentreX(), getScreenY(screen) + (getCentreY() - 4), colour); }
From source file:io.github.minecraftgui.controllers.Render.java
License:Open Source License
public void drawTexture(Texture texture, double x, double y, double width, double height) { GL11.glEnable(GL11.GL_TEXTURE_2D);//ww w .j a va2s. com GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID()); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glColor4f(1, 1, 1, 1); GL11.glBegin(GL11.GL_QUADS); { GL11.glTexCoord2f(0, 0); GL11.glVertex2d(x, y); GL11.glTexCoord2f(0, texture.getHeight()); GL11.glVertex2d(x, y + height); GL11.glTexCoord2f(texture.getWidth(), texture.getHeight()); GL11.glVertex2d(x + width, y + height); GL11.glTexCoord2f(texture.getWidth(), 0); GL11.glVertex2d(x + width, y); } GL11.glEnd(); modInterface.bindMinecraftTextures(); }