List of usage examples for org.lwjgl.opengl GL30 glGenerateMipmap
public static void glGenerateMipmap(@NativeType("GLenum") int target)
From source file:ar.com.quark.backend.lwjgl.opengl.DesktopGLES20.java
License:Apache License
/** * {@inheritDoc} */ @Override public void glGenerateMipmap(int target) { GL30.glGenerateMipmap(target); }
From source file:com.badlogic.gdx.backends.jglfw.JglfwGL30.java
License:Apache License
@Override public void glGenerateMipmap(int target) { GL30.glGenerateMipmap(target); }
From source file:com.flowpowered.caustic.lwjgl.gl30.GL30Texture.java
License:MIT License
@Override public void setImageData(ByteBuffer imageData, int width, int height) { checkCreated();/*from w w w .j a v a 2s . com*/ 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.github.kajdreef.mazerunnermvn.Object.GameObject.java
protected void setTextureUnit(Texture texture, int textureUnit) { // Create a new texture object in memory and bind it texId = GL11.glGenTextures();/*from w w w .ja va 2s . c o m*/ GL13.glActiveTexture(textureUnit); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId); // All RGB bytes are aligned to each other and each component is 1 byte GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); // Upload the texture data and generate mip maps (for scaling) GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, texture.getWidth(), texture.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, texture.getTexBuffer()); GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); // Setup the ST coordinate system GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); // Setup what to do when the texture has to be scaled GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); }
From source file:com.grillecube.client.opengl.GLTexture.java
/** generate a mipmap (texture lod) */ public final void generateMipmap(float bias) { this.bind(GL13.GL_TEXTURE0, GL11.GL_TEXTURE_2D); GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); this.parameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); this.parameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, bias); }
From source file:com.samrj.devil.gl.Texture.java
License:Open Source License
/** * Generates mipmaps for this texture./*from ww w. j a v a 2s . c o m*/ * * @return This texture. */ public final T generateMipmap() { int oldID = tempBind(); GL30.glGenerateMipmap(target); if (!hasMipmaps) setVRAMUsage(vramUsage * 2); hasMipmaps = true; tempUnbind(oldID); return getThis(); }
From source file:com.voxelplugineering.voxelsniper.util.TextureUtilities.java
License:Open Source License
public static int loadPNGTexture(File file, int textureUnit) { ByteBuffer buf = null;//ww w . j a v a 2 s . c om int tWidth = 0; int tHeight = 0; try { BufferedImage image = ImageIO.read(file); tWidth = image.getWidth(); tHeight = image.getHeight(); buf = imageToRGBABuffer(image); } catch (IOException e) { e.printStackTrace(); if (file.getName().endsWith("debug.png")) { System.exit(-1); } else { return debugTexture; } } // Create a new texture object in memory and bind it int texId = GL11.glGenTextures(); GL13.glActiveTexture(textureUnit); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId); // All RGB bytes are aligned to each other and each component is 1 byte GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); // Upload the texture data and generate mip maps (for scaling) GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tWidth, tHeight, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf); GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); // Setup the ST coordinate system GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); // Setup what to do when the texture has to be scaled GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_NEAREST); OpenGLUtilities.checkGLError("loadPNGTexture"); if (file.getName().endsWith("debug.png")) { debugTexture = texId; } return texId; }
From source file:com.xrbpowered.gl.res.textures.Texture.java
License:Open Source License
public static void setProperties(int textureType, boolean wrap, boolean filter, int anisotropy) { GL11.glTexParameteri(textureType, GL11.GL_TEXTURE_WRAP_S, wrap ? GL11.GL_REPEAT : GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(textureType, GL11.GL_TEXTURE_WRAP_T, wrap ? GL11.GL_REPEAT : GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(textureType, GL11.GL_TEXTURE_MAG_FILTER, filter ? GL11.GL_LINEAR : GL11.GL_NEAREST); GL11.glTexParameteri(textureType, GL11.GL_TEXTURE_MIN_FILTER, filter ? GL11.GL_LINEAR_MIPMAP_LINEAR : GL11.GL_NEAREST); if (filter) { GL30.glGenerateMipmap(textureType); if (anisotropy > 1) { GL11.glTexParameterf(textureType, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy);/*from ww w.j a va 2s .c o m*/ } } }
From source file:dataAccess.lwjgl.VAO_Loader.java
public static int loadTexture(File file) { int textureID; if (textureMap.containsKey(file.getAbsolutePath())) { textureID = textureMap.get(file.getAbsolutePath()); } else {/*from w w w . j av a2s . c o m*/ Texture texture = null; try { texture = TextureLoader.getTexture("PNG", new FileInputStream(file)); } catch (IOException ex) { Logger.getLogger(VAO_Loader.class.getName()).log(Level.SEVERE, null, ex); } textureID = texture.getTextureID(); textureMap.put(file.getAbsolutePath(), textureID); } GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0f); if (GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) { if (Settings.ANISOTROPIC_FILTERING) { float amount = Math.min(4f, GL11.glGetFloat(EXTTextureFilterAnisotropic.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT)); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, amount); } } else { System.out.println("no anisotropic filtering possible!"); } return textureID; }
From source file:de.ikosa.mars.viewer.glviewer.engine.GLTextureArrayBuilder.java
License:Open Source License
@Override public GLTextureArray createTexture() { try {// w w w . j a va 2s.co m int files = filePaths.length; byte[][] imageData = new byte[files][]; int totalSize = 0; int imageWidth = 0; int imageHeight = 0; // read in files for (int file = 0; file < files; file++) { InputStream inputStream = new FileInputStream(filePaths[file]); BufferedImage image = ImageIO.read(inputStream); if (file > 0) if (imageWidth != image.getWidth() | imageHeight != image.getHeight()) ML.f("Incompatible images in 3D texture..."); imageWidth = image.getWidth(); imageHeight = image.getHeight(); imageData[file] = GLPNGLoader.loadPNG(image); totalSize += imageData[file].length; } // store in consecutive buffer ByteBuffer buffer = ByteBuffer.allocateDirect(totalSize); for (int file = 0; file < files; file++) { byte[] singleImageData = imageData[file]; for (int i = 0; i < singleImageData.length; i++) buffer.put(singleImageData[i]); } buffer.flip(); int textureId = GL11.glGenTextures(); GLRenderer2Stage.errorCheck("generating texture id"); GL13.glActiveTexture(GL13.GL_TEXTURE0); GLRenderer2Stage.errorCheck("activating texture image unit"); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, textureId); GLRenderer2Stage.errorCheck("binding 2d texture array"); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GLRenderer2Stage.errorCheck("setting unpack aligment"); GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL11.GL_RGBA, imageWidth, imageHeight, files, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); GLRenderer2Stage.errorCheck("storing 2d texture array data"); GL30.glGenerateMipmap(GL30.GL_TEXTURE_2D_ARRAY); GLRenderer2Stage.errorCheck("generating 2d texture array mipmaps"); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0); GLRenderer2Stage.errorCheck("unbinding 2d texture array"); return new GLTextureArray(name, textureId); } catch (Exception e) { ML.f(e); } return null; }