List of usage examples for org.lwjgl.opengl GL13 glActiveTexture
public static void glActiveTexture(@NativeType("GLenum") int texture)
From source file:com.voxelplugineering.voxelsniper.util.TextureUtilities.java
License:Open Source License
public static int loadPNGTexture(File file, int textureUnit) { ByteBuffer buf = null;/* w w w . j a va 2 s .co m*/ 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.w67clement.openw67render.utils.Texture.java
License:Open Source License
/** * Binds the texture. */ public void bind() { GL13.glActiveTexture(id); glBindTexture(GL_TEXTURE_2D, id); }
From source file:com.xrbpowered.gl.examples.GLLife.java
License:Open Source License
private void resetBuffers(boolean fill) { if (buffers[0] != null) buffers[0].destroy();/* w w w . ja va 2s . c o m*/ if (buffers[1] != null) buffers[1].destroy(); int width = getTargetWidth(); int height = getTargetHeight(); buffers[0] = new OffscreenBuffers(width, height, false); buffers[1] = new OffscreenBuffers(width, height, false); targetBuffer = 1; turn = 0; IntBuffer intBuffer = ByteBuffer.allocateDirect(4 * width * height).order(ByteOrder.nativeOrder()) .asIntBuffer(); int[] pixels = new int[width * height]; for (int x = 1; x < width; x++) for (int y = 1; y < height; y++) { int v = fill && random.nextInt(27) == 0 ? 0xffffffff : 0xff000000; pixels[y * width + x] = v; } intBuffer.put(pixels); intBuffer.flip(); GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, buffers[0].getColorTexId()); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuffer); GL11.glBindTexture(GL11.GL_TEXTURE_2D, buffers[1].getColorTexId()); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuffer); }
From source file:com.xrbpowered.gl.examples.GLLife.java
License:Open Source License
private void addGlider(int x, int y, int width, int height, int[] pixels) { IntBuffer intBuffer = ByteBuffer.allocateDirect(4 * width * height).order(ByteOrder.nativeOrder()) .asIntBuffer();/*from ww w.ja v a 2s . c o m*/ intBuffer.put(pixels); intBuffer.flip(); GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, buffers[1 - targetBuffer].getColorTexId()); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, x, y, width, height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuffer); }
From source file:com.xrbpowered.gl.res.buffers.OffscreenBuffers.java
License:Open Source License
public void bindColorBuffer(int index) { GL13.glActiveTexture(GL13.GL_TEXTURE0 + index); GL11.glBindTexture(GL11.GL_TEXTURE_2D, colorTexId); }
From source file:com.xrbpowered.gl.res.buffers.OffscreenBuffers.java
License:Open Source License
public void bindDepthBuffer(int index) { if (depthTexId > 0) { GL13.glActiveTexture(GL13.GL_TEXTURE0 + index); GL11.glBindTexture(GL11.GL_TEXTURE_2D, depthTexId); }/* ww w .j ava 2 s.c o m*/ }
From source file:com.xrbpowered.gl.res.SkyBox.java
License:Open Source License
public void draw() { shader.use(); GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texture.getId()); cube.draw(); shader.unuse(); }
From source file:com.xrbpowered.gl.res.textures.ArrayTexture.java
License:Open Source License
public ArrayTexture(int w, int h, int layers) { this.width = w; this.height = h; this.layers = layers; texId = GL11.glGenTextures();// www. j ava2s.c om GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, texId); intBuffer = ByteBuffer.allocateDirect(4 * w * h * layers).order(ByteOrder.nativeOrder()).asIntBuffer(); }
From source file:com.xrbpowered.gl.res.textures.ArrayTexture.java
License:Open Source License
public void bind(int index) { GL13.glActiveTexture(GL13.GL_TEXTURE0 + index); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, texId); }
From source file:com.xrbpowered.gl.res.textures.BufferTexture.java
License:Open Source License
public void update() { if (this.imgBuffer == null) createBuffers();//from www . ja va 2 s .c o m if (updateBuffer((Graphics2D) imgBuffer.getGraphics(), width, height)) { pixels = imgBuffer.getRGB(0, 0, width, height, pixels, 0, width); intBuffer.put(pixels); intBuffer.flip(); GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, getId()); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuffer); // GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); // TODO needless mipmaps? } if (!staticBuffers) destroyBuffers(); }