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:src.graphics.common.Texture.java
License:Open Source License
public static void setDefaultTexParams(int target) { GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(target, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); GL11.glTexParameteri(target, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); }
From source file:tectonicus.rasteriser.lwjgl.LwjglTextureUtils.java
License:BSD License
public static int createTexture(BufferedImage imageData, TextureFilter filterMode) { imageData = convertToGlFormat(imageData); IntBuffer buff = BufferUtils.createIntBuffer(16); buff.limit(1);/*from w w w.j av a2s . c om*/ GL11.glGenTextures(buff); int textureId = buff.get(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); if (filterMode == TextureFilter.NEAREST) { 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); } else { 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.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); ByteBuffer scratch = ByteBuffer.allocateDirect(4 * imageData.getWidth() * imageData.getHeight()); Raster raster = imageData.getRaster(); byte data[] = (byte[]) raster.getDataElements(0, 0, imageData.getWidth(), imageData.getHeight(), null); scratch.clear(); scratch.put(data); scratch.rewind(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, // Mip level & Internal format imageData.getWidth(), imageData.getHeight(), 0, // width, height, border GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, // pixel data format scratch); // pixel data GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, imageData.getWidth(), imageData.getHeight(), GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, // format, type scratch); return textureId; }
From source file:tectonicus.rasteriser.lwjgl.LwjglTextureUtils.java
License:BSD License
public static int createTexture(BufferedImage[] mips, TextureFilter filterMode) { IntBuffer buff = BufferUtils.createIntBuffer(16); buff.limit(1);/*w w w .j av a2s.com*/ GL11.glGenTextures(buff); int textureId = buff.get(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); if (filterMode == TextureFilter.NEAREST) { 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_LINEAR); } else { 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_MIPMAP_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); for (int mip = 0; mip < mips.length; mip++) { BufferedImage imageData = mips[mip]; imageData = convertToGlFormat(imageData); ByteBuffer scratch = ByteBuffer.allocateDirect(4 * imageData.getWidth() * imageData.getHeight()); Raster raster = imageData.getRaster(); byte data[] = (byte[]) raster.getDataElements(0, 0, imageData.getWidth(), imageData.getHeight(), null); scratch.clear(); scratch.put(data); scratch.rewind(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, mip, GL11.GL_RGBA, // Mip level & Internal format imageData.getWidth(), imageData.getHeight(), 0, // width, height, border GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, // pixel data format scratch); // pixel data // GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, // 0, 0, // imageData.getWidth(), imageData.getHeight(), // GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, // format, type // scratch); } return textureId; }
From source file:terminal.gld.TrueTypeFont.java
License:Open Source License
public static int loadImage(BufferedImage bufferedImage) { try {// w ww . j a v a 2 s . c o m 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; 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); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } return -1; }
From source file:tk.ivybits.engine.gl.GL.java
License:Open Source License
public static void glTexParameteri(int a, int b, int c) { GL11.glTexParameteri(a, b, c); }
From source file:v9t9.gui.client.swt.gl.TextureLoader.java
License:Open Source License
/** * Load a texture into OpenGL from a image reference on * disk.// ww w . ja v a 2 s. c om * * @param resourceName The location of the resource to load * @param target The GL target to load the texture against * @param dstPixelFormat The pixel format of the screen * @param minFilter The minimising filter * @param magFilter The magnification filter * @return The loaded texture * @throws IOException Indicates a failure to access the resource */ public Texture getTexture(String resourceName, int target, int dstPixelFormat, int minFilter, int magFilter) throws IOException { int srcPixelFormat = 0; // create the texture ID for this texture int textureID = createTextureID(); Texture texture = new Texture(target, textureID); // bind this texture GL11.glBindTexture(target, textureID); BufferedImage bufferedImage = loadImage(resourceName); texture.setWidth(bufferedImage.getWidth()); texture.setHeight(bufferedImage.getHeight()); if (bufferedImage.getColorModel().hasAlpha()) { srcPixelFormat = GL11.GL_RGBA; } else { srcPixelFormat = GL11.GL_RGB; } // convert that image into a byte buffer of texture data ByteBuffer textureBuffer = convertImageData(bufferedImage, texture); if (target == GL11.GL_TEXTURE_2D) { GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, minFilter); GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, magFilter); } // produce a texture from the byte buffer GL11.glTexImage2D(target, 0, dstPixelFormat, get2Fold(bufferedImage.getWidth()), get2Fold(bufferedImage.getHeight()), 0, srcPixelFormat, GL11.GL_UNSIGNED_BYTE, textureBuffer); return texture; }
From source file:voxicity.TextureManager.java
License:Open Source License
public static int get_texture(String name) { if (name == null) return 0; if (textures.containsKey(name)) return textures.get(name).getTextureID(); try {/* ww w . j a va 2s. c om*/ Texture new_tex = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(name), true, GL11.GL_NEAREST); System.out.println("Loaded texture: " + new_tex); textures.put(name, new_tex); int tex_bak = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); GL11.glBindTexture(GL11.GL_TEXTURE_2D, new_tex.getTextureID()); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex_bak); return new_tex.getTextureID(); } catch (java.io.IOException e) { System.out.println("Failed to load texture " + name); e.printStackTrace(); System.exit(0); } return 0; }
From source file:wrath.client.ClientUtils.java
License:Open Source License
/** * Loads a LWJGL Texture from an image.//w w w .j av a 2s .co m * @param image The {@link java.awt.image.BufferedImage} version of the Texture. * @return Returns the LWJGL texture id. */ public static int getTexture(BufferedImage image) { if (image == null) return 0; 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() * 4); 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)); buffer.put((byte) ((pixel >> 24) & 0xFF)); } } buffer.flip(); int id = GL11.glGenTextures(); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); 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.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); return id; }
From source file:wrath.client.graphics.Texture.java
License:Open Source License
/** * Constructor.// ww w.j ava 2 s .c om * @param textureFile The image {@link java.io.File} to load the texture from. */ protected Texture(File textureFile) { this.file = textureFile; this.texID = ClientUtils.getTexture(ClientUtils.loadImageFromFile(textureFile)); Game.getCurrentInstance().getLogger() .println("Created texture ID '" + texID + "' from file '" + file.getName() + "'!"); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID); 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); if (Game.getCurrentInstance().getConfig().getBoolean("TexureMipmapping", true)) GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); if (Game.getCurrentInstance().getConfig().getBoolean("AntiAliasingTexture", true)) { if (Game.getCurrentInstance().getConfig().getBoolean("TexureMipmapping", true)) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); } else { 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_NEAREST); } } Texture.unbindTextures(); afterConstructor(); }
From source file:wrath.client.graphics.Texture.java
License:Open Source License
@Override public void reload() { this.texID = ClientUtils.getTexture(ClientUtils.loadImageFromFile(file)); GL11.glEnable(GL11.GL_TEXTURE_2D);/*from w w w .j a va2s . c o m*/ GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID); 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); if (Game.getCurrentInstance().getConfig().getBoolean("TexureMipmapping", true)) GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); if (Game.getCurrentInstance().getConfig().getBoolean("AntiAliasingTexture", true)) { if (Game.getCurrentInstance().getConfig().getBoolean("TexureMipmapping", true)) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); } else { 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_NEAREST); } } Texture.unbindTextures(); Game.getCurrentInstance().getLogger() .println("Created texture ID '" + texID + "' from file '" + file.getName() + "'!"); }