List of usage examples for org.lwjgl.opengl GL30 glGenerateMipmap
public static void glGenerateMipmap(@NativeType("GLenum") int target)
From source file:me.ukl.api.util.TextureUtil.java
License:MIT License
public static void loadTextureMipmap(int tex, int[] rgb, int width, int height) { IntBuffer rgbBuf = BufferUtils.createIntBuffer(rgb.length); rgbBuf.put(rgb);/*from w w w. jav a2 s . c o m*/ rgbBuf.flip(); bind(tex); //If OpenGL30, use glGenerateMipmap, else use the GL_GENERATE_MIPMAP tex param if (RenderUtil.GL_30) { GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, rgbBuf); GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); } else { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, rgbBuf); } }
From source file:mwisbest.openbase.opengl.TextureLoader.java
License:Open Source License
private TextureImplementation getTexture(InputStream in, String resourceName, int target, int minFilter, int magFilter, boolean flipped, int[] transparent) throws IOException { // create the texture ID for this texture ByteBuffer textureBuffer;// www . jav a 2 s.c o m LoadableImageData imageData = ImageDataFactory.getImageDataFor(resourceName); textureBuffer = imageData.loadImage(new BufferedInputStream(in), flipped, transparent); int textureID = createTextureID(); TextureImplementation texture = new TextureImplementation(resourceName, target, textureID); // bind this texture GL11.glEnable(target); GL11.glBindTexture(target, textureID); int width; int height; int texWidth; int texHeight; ImageData.Format format; width = imageData.getWidth(); height = imageData.getHeight(); format = imageData.getFormat(); texture.setTextureWidth(imageData.getTexWidth()); texture.setTextureHeight(imageData.getTexHeight()); texWidth = texture.getTextureWidth(); texHeight = texture.getTextureHeight(); IntBuffer temp = BufferUtils.createIntBuffer(16); GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE, temp); int max = temp.get(0); if (texWidth > max || texHeight > max) throw new IOException("Attempt to allocate a texture to big for the current hardware"); int srcPixelFormat = format.getOGLType(); texture.setWidth(width); texture.setHeight(height); texture.setImageFormat(format); GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, minFilter); GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, magFilter); ContextCapabilities capabilities = GLContext.getCapabilities(); if (capabilities.OpenGL30 || capabilities.GL_EXT_framebuffer_object || capabilities.GL_ARB_framebuffer_object || capabilities.OpenGL14) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, GL11.GL_POLYGON_BIT); if (capabilities.OpenGL30) GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); else if (capabilities.GL_EXT_framebuffer_object) EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_2D); else if (capabilities.GL_ARB_framebuffer_object) ARBFramebufferObject.glGenerateMipmap(GL11.GL_TEXTURE_2D); else if (capabilities.OpenGL14) GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE); } // produce a texture from the byte buffer GL11.glTexImage2D(target, 0, this.dstPixelFormat, get2Fold(width), get2Fold(height), 0, srcPixelFormat, GL11.GL_UNSIGNED_BYTE, textureBuffer); return texture; }
From source file:net.skourti.superhornet.utils.TextureLoader.java
public static int loadTexture(BufferedImage image) { int[] pixels = new int[image.getWidth() * image.getHeight()]; image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth()); ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * BYTES_PER_PIXEL); //4 for RGBA, 3 for RGB for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int pixel = pixels[y * image.getWidth() + x]; buffer.put((byte) ((pixel >> 16) & 0xFF)); // Red component buffer.put((byte) ((pixel >> 8) & 0xFF)); // Green component buffer.put((byte) (pixel & 0xFF)); // Blue component buffer.put((byte) ((pixel >> 24) & 0xFF)); // Alpha component. Only for RGBA }/*ww w . j a v a2 s . c om*/ } buffer.flip(); //FOR THE LOVE OF GOD DO NOT FORGET THIS // You now have a ByteBuffer filled with the color data of each pixel. // Now just create a texture ID and bind it. Then you can load it using // whatever OpenGL method you want, for example: int textureID = glGenTextures(); //Generate texture ID glBindTexture(GL_TEXTURE_2D, textureID); //Bind texture ID //Setup wrap mode glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //Setup texture scaling filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //Send texel data to OpenGL glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); GL30.glGenerateMipmap(GL_TEXTURE_2D); //Return the texture ID so we can bind it later again return textureID; }
From source file:net.smert.frameworkgl.opengl.helpers.TextureHelper.java
License:Apache License
public void generateMipmap() { GL30.glGenerateMipmap(textureTarget); }
From source file:org.getspout.spout.config.MipMapUtils.java
License:Open Source License
public static void onTick(int texture, float targetFade, float currentFade) { GL11.glPushMatrix();/*from w w w.ja v a2 s .c o m*/ GL11.glBindTexture(3553, texture); if (targetFade != currentFade) { if (targetFade < currentFade) { currentFade -= 0.01f; if (currentFade <= targetFade) { currentFade = targetFade; } } else { currentFade += 0.01f; if (currentFade >= targetFade) { currentFade = targetFade; } } if (currentFade <= 0.0f) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glAlphaFunc(GL11.GL_GREATER, 0.01F); //default blend state updateTerrain = false; GL11.glPopMatrix(); return; } else { GL11.glTexEnvf(GL14.GL_TEXTURE_FILTER_CONTROL, GL14.GL_TEXTURE_LOD_BIAS, getMipmapLevels(texture) * (currentFade - 1.0f)); } } switch (mode) { case 1: GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); break; case 2: EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_2D); break; } GL11.glAlphaFunc(GL11.GL_GEQUAL, 0.3F); //more strict blend state GL11.glPopMatrix(); }
From source file:org.spout.renderer.lwjgl.gl30.GL30Texture.java
License:Open Source License
@Override public void setImageData(ByteBuffer imageData, int width, int height) { checkCreated();/*ww w.ja v a 2 s .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"); } 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; 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:org.spoutcraft.client.config.MipMapUtils.java
License:Open Source License
public static void onTick(int texture, float targetFade, float currentFade) { GL11.glPushMatrix();/*w ww.j a v a 2s . c o m*/ SpoutClient.getHandle().renderEngine.bindTexture(texture); if (targetFade != currentFade) { if (targetFade < currentFade) { currentFade -= 0.01f; if (currentFade <= targetFade) { currentFade = targetFade; } } else { currentFade += 0.01f; if (currentFade >= targetFade) { currentFade = targetFade; } } if (currentFade <= 0.0f) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glAlphaFunc(GL11.GL_GREATER, 0.01F); // Default blend state updateTerrain = false; GL11.glPopMatrix(); return; } else { GL11.glTexEnvf(GL14.GL_TEXTURE_FILTER_CONTROL, GL14.GL_TEXTURE_LOD_BIAS, getMipmapLevels(texture) * (currentFade - 1.0f)); } } switch (mode) { case 1: GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); break; case 2: EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_2D); break; } GL11.glAlphaFunc(GL11.GL_GEQUAL, 0.3F); // More strict blend state GL11.glPopMatrix(); }
From source file:org.spoutcraft.client.gui.MCRenderDelegate.java
License:Open Source License
public void drawTexture(Texture textureBinding, int width, int height, Color color, boolean blend, int left, int top, boolean mipmap, int filter) { if (textureBinding == null) { return;/*from w ww .j av a 2 s. c o m*/ } GL11.glPushMatrix(); GL11.glDisable(GL11.GL_DEPTH_TEST); boolean wasBlend = GL11.glGetBoolean(GL11.GL_BLEND); if (blend) { GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(770, 771); } GL11.glDepthMask(false); bindColor(color); SpoutClient.getHandle().renderEngine.bindTexture(textureBinding.getTextureID()); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filter); if (mipmap) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, 8); ContextCapabilities capabilities = GLContext.getCapabilities(); if (capabilities.OpenGL30) { GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); } else if (capabilities.GL_EXT_framebuffer_object) { EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_2D); } else if (capabilities.OpenGL14) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE); } } double tLeft = 0, tTop = 0, rWidth = textureBinding.getWidth(), rHeight = textureBinding.getHeight(), tWidth = rWidth, tHeight = rHeight; if (top >= 0 && left >= 0) { tWidth = Math.min(tWidth, (width / (double) textureBinding.getImageWidth()) * textureBinding.getWidth()); tHeight = Math.min(tHeight, (height / (double) textureBinding.getImageHeight()) * textureBinding.getHeight()); tLeft = Math.min( Math.max(0, (left / (double) textureBinding.getImageWidth())) * textureBinding.getWidth(), rWidth); tTop = Math.min( Math.max(0, (top / (double) textureBinding.getImageHeight()) * textureBinding.getHeight()), rHeight); } tHeight = -tHeight; tTop = rHeight - tTop; Tessellator tessellator = Tessellator.instance; tessellator.startDrawingQuads(); tessellator.addVertexWithUV(0.0D, height, -90, tLeft, tTop + tHeight); // draw corners tessellator.addVertexWithUV(width, height, -90, tLeft + tWidth, tTop + tHeight); tessellator.addVertexWithUV(width, 0.0D, -90, tLeft + tWidth, tTop); tessellator.addVertexWithUV(0.0D, 0.0D, -90, tLeft, tTop); tessellator.draw(); GL11.glDepthMask(true); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glPopMatrix(); if (blend && !wasBlend) { GL11.glDisable(GL11.GL_BLEND); } }
From source file:processing.lwjgl.PGL.java
License:Open Source License
public void generateMipmap(int target) { GL30.glGenerateMipmap(target); }
From source file:processing.opengl.PLWJGL.java
License:Open Source License
@Override public void generateMipmap(int target) { GL30.glGenerateMipmap(target); }