List of usage examples for org.lwjgl.opengl GL11 glTexParameteri
public static void glTexParameteri(@NativeType("GLenum") int target, @NativeType("GLenum") int pname, @NativeType("GLint") int param)
From source file:com.opengrave.og.resources.TextureDead.java
License:Open Source License
public static TextureDead create(String location) { InputStream in = null;/*from w ww . ja v a2 s .co m*/ File f = new File(Resources.cache, location); try { in = new FileInputStream(f.getAbsolutePath()); } catch (FileNotFoundException e1) { System.out.println("Cannot open file " + f.getAbsolutePath()); return null; } PNGDecoder decoder; TextureDead textureObject = new TextureDead(); int texture = -1; try { decoder = new PNGDecoder(in); textureObject.width = decoder.getWidth(); textureObject.height = decoder.getHeight(); System.out.println("Width : " + decoder.getWidth() + " Height : " + decoder.getHeight()); ByteBuffer buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight()); decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA); buf.flip(); texture = GL11.glGenTextures(); textureObject.id = texture; GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); 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); 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, decoder.getWidth(), decoder.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf); // GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); } catch (IOException e) { new DebugExceptionHandler(e, location); } finally { try { if (in != null) { in.close(); } } catch (IOException e) { } } return textureObject; }
From source file:com.opengrave.og.resources.TextureEditable.java
License:Open Source License
public TextureEditable(int size, float r, float g, float b, float a) { this.size = getPowerOfTwo(size); id = GL11.glGenTextures();/* w ww .ja va2s . c om*/ mainBuf = BufferUtils.createByteBuffer(4 * this.size * this.size); for (int count = 0; count < this.size * this.size; count++) { addColour(r, g, b, a); } mainBuf.flip(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, this.size, this.size, 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, mainBuf); 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); 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.glBindTexture(GL11.GL_TEXTURE_2D, 0); }
From source file:com.owens.oobjloader.lwjgl.TextureLoader.java
License:BSD License
public int convertToTexture(BufferedImage img) { int[] pixels = new int[img.getWidth() * img.getHeight()]; PixelGrabber grabber = new PixelGrabber(img, 0, 0, img.getWidth(), img.getHeight(), pixels, 0, img.getWidth());/*from w ww . ja v a 2s .com*/ try { grabber.grabPixels(); } catch (InterruptedException e) { log.log(SEVERE, "InterruptedException while trying to grab pixels, e=" + e); e.printStackTrace(); return -1; } int bufLen = 0; bufLen = pixels.length * 4; ByteBuffer oglPixelBuf = BufferUtils.createByteBuffer(bufLen); for (int y = img.getHeight() - 1; y >= 0; y--) { for (int x = 0; x < img.getWidth(); x++) { int pixel = pixels[y * img.getWidth() + x]; oglPixelBuf.put((byte) ((pixel >> 16) & 0xFF)); oglPixelBuf.put((byte) ((pixel >> 8) & 0xFF)); oglPixelBuf.put((byte) ((pixel >> 0) & 0xFF)); oglPixelBuf.put((byte) ((pixel >> 24) & 0xFF)); } } oglPixelBuf.flip(); ByteBuffer temp = ByteBuffer.allocateDirect(4); temp.order(ByteOrder.nativeOrder()); IntBuffer textBuf = temp.asIntBuffer(); GL11.glGenTextures(textBuf); int textureID = textBuf.get(0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, TEXTURE_LEVEL, GL11.GL_RGBA8, img.getWidth(), img.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, oglPixelBuf); return textureID; }
From source file:com.redthirddivision.quad.rendering.materials.Texture.java
License:Apache License
private TextureManager loadTexture(String path, String root) { // String[] splitArray = path.split("\\."); // String extension = splitArray[splitArray.length - 1]; File file = null;/*w ww. j a v a2 s. c om*/ BufferedImage image = null; System.out.println("Attempting to load a new texture: <" + root + "/" + path + ">"); file = new File(root + "/" + path + ".png"); try { image = ImageIO.read(file); } catch (IOException e) { System.err.println("Could not find texture: <" + root + "/" + path + ">"); return textures.get(MISSING_TEXTURE_FILE); } try { int[] pixels = image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth()); ByteBuffer buffer = Util.createByteBuffer(image.getWidth() * image.getHeight() * 4); boolean hasAlpha = image.getColorModel().hasAlpha(); 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)); buffer.put((byte) ((pixel >> 8) & 0xFF)); buffer.put((byte) ((pixel) & 0xFF)); if (hasAlpha) buffer.put((byte) ((pixel >> 24) & 0xFF)); else buffer.put((byte) 0xFF); } } buffer.flip(); System.out.println("Succesfully loaded texture from file: <" + file.getPath() + ">"); TextureManager result = new TextureManager(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, result.getID()); 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); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); return result; } catch (Exception e) { System.err.println("Could not load texture: <" + path + ".png>"); System.exit(1); } return null; }
From source file:com.runescape.client.revised.editor.modelviewer.Generator.java
License:Open Source License
public void draw() { GL11.glBegin(GL11.GL_QUADS);//ww w . ja v a2s. c o m for (int i = 0; i < this.particleCount; i++) { if (this.particles[i] != null) { GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, this.decParticle.getWidth(), this.decParticle.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, this.bufParticle); GL11.glBindTexture(GL11.GL_ADD, GL11.GL_LOAD); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 1); 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); GL11.glPushMatrix(); GL11.glTranslated(this.particles[i].x + (Main.getMain().getCanvas().getX() / 2), this.particles[i].y + (Main.getMain().getCanvas().getY() / 2), 0); this.particles[i].draw(); GL11.glPopMatrix(); } } GL11.glEnd(); }
From source file:com.samrj.devil.gl.Texture.java
License:Open Source License
/** * Sets the given parameter to the given int for this texture. The texture * must be bound./*from ww w. j ava 2 s .com*/ * * @param param The OpenGL texture parameter to set. * @param value The value to set the parameter to. * @return This texture. */ public final T parami(int param, int value) { if (!isBound()) throw new IllegalStateException("Texture must be bound."); GL11.glTexParameteri(target, param, value); return getThis(); }
From source file:com.specialeffect.gui.StateOverlay.java
License:Open Source License
private void drawScaledTextureWithGlow(ResourceLocation res, int x, int y, int width, int height) { GL11.glPushAttrib(GL11.GL_TEXTURE_BIT); this.mc.renderEngine.bindTexture(res); // First draw enlarged and blurred, for glow. GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_ADD); // We draw the texture larger, in white, at progressive levels of alpha // for blur effect (the alpha gets added on each layer) int blurSteps = 4; // how many levels of progressive blur double totalBlur = width / 12; // in pixels GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f / blurSteps); for (int i = 0; i < blurSteps; i++) { double blurAmount = totalBlur / blurSteps * (i + 1); ModUtils.drawTexQuad(x - blurAmount, y - blurAmount, width + 2 * blurAmount, height + 2 * blurAmount); }// www. j a v a 2 s . c o m GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE); GL11.glColor3f(1.0f, 1.0f, 1.0f); this.mc.renderEngine.bindTexture(res); ModUtils.drawTexQuad(x, y, width, height); // reset GL attributes! GL11.glPopAttrib(); }
From source file:com.telinc1.rpjg.texture.Texture.java
License:Apache License
public void setFilter(int minFilter, int magFilter) { this.bind();/*from ww w . j av a 2 s. c o m*/ GL11.glTexParameteri(this.getTarget(), GL11.GL_TEXTURE_MIN_FILTER, minFilter); GL11.glTexParameteri(this.getTarget(), GL11.GL_TEXTURE_MAG_FILTER, magFilter); }
From source file:com.telinc1.rpjg.texture.Texture.java
License:Apache License
public void setWrap(int sWrap, int tWrap) { this.bind();//from w w w.j a va2s . c om GL11.glTexParameteri(this.getTarget(), GL11.GL_TEXTURE_WRAP_S, tWrap); GL11.glTexParameteri(this.getTarget(), GL11.GL_TEXTURE_WRAP_T, tWrap); }
From source file:com.voxelplugineering.voxelsniper.util.TextureUtilities.java
License:Open Source License
public static int loadPNGTexture(File file, int textureUnit) { ByteBuffer buf = null;//from w w w .j av a 2 s.c o 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; }