List of usage examples for org.lwjgl.opengl GL11 glBindTexture
public static void glBindTexture(@NativeType("GLenum") int target, @NativeType("GLuint") int texture)
From source file:com.opengrave.og.light.TextureCubeShadowMap.java
License:Open Source License
@Override public void bind(int t) { if (t == 0 || texture == 0) { lastTexNum = 0;//from www . ja v a 2s.c o m return; } lastTexNum = t; GL13.glActiveTexture(t); Util.checkErr(); GL11.glBindTexture(getTextureType(), texture); Util.checkErr(); }
From source file:com.opengrave.og.light.TextureCubeShadowMap.java
License:Open Source License
@Override public void unbind() { if (lastTexNum == 0) { return;// ww w. java2s . c om } Util.checkErr(); GL13.glActiveTexture(lastTexNum); Util.checkErr(); GL11.glBindTexture(getTextureType(), 0); Util.checkErr(); }
From source file:com.opengrave.og.resources.TextureAtlas.java
License:Open Source License
@Override public void bind(int t) { // GLSL Will assume the order if we don't Uniform it. I like that. // GL20.glUniform1i(i, 0); lastTexNum = t;/*from ww w.j a v a 2s . c o m*/ GL13.glActiveTexture(t); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, id); Util.checkErr(); }
From source file:com.opengrave.og.resources.TextureAtlas.java
License:Open Source License
@Override public void unbind() { Util.checkErr();// w ww .ja v a 2 s . co m GL13.glActiveTexture(lastTexNum); Util.checkErr(); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0); Util.checkErr(); }
From source file:com.opengrave.og.resources.TextureAtlas.java
License:Open Source License
protected static TextureAtlas create(ArrayList<String> files) { if (files.size() == 0) { // WAT/*from w w w . j a v a 2 s . com*/ files.add("blank"); } TextureAtlas atlas = new TextureAtlas(); atlas.id = GL11.glGenTextures(); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, atlas.id); Util.checkErr(); atlas.depth = getPowerOfTwo(files.size()); while (files.size() < atlas.depth) { files.add("blank"); } // System.out.println("Texture Atlas id : " + atlas.id + " size : " // + files.size() + " end size : " + atlas.depth); atlas.width = 1; atlas.height = 1; for (int i = 0; i < files.size(); i++) { if (files.get(i).equalsIgnoreCase("blank") || files.get(i).equalsIgnoreCase("none")) { continue; } PNGDecoder firstImage = getImageFile(files.get(i)); if (firstImage == null) { return null; } atlas.width = firstImage.getWidth(); atlas.height = firstImage.getHeight(); break; } Util.checkErr(); // ARBTextureStorage.glTexStorage3D(atlas.getTextureType(), 1, // GL11.GL_RGBA, atlas.width, atlas.height, atlas.depth); // Throws an // error for GL_RGBA, it wants an internal format only. // Inversly. No GL_RGBAx values work. // Util.checkErr(false); ByteBuffer buf = ByteBuffer.allocateDirect(4 * atlas.width * atlas.height * atlas.depth); for (String location : files) { if (location.equalsIgnoreCase("blank")) { byte b = (byte) 255; for (int count = 0; count < atlas.width * atlas.height; count++) { buf.put(b).put(b).put(b).put(b); } // System.out // .println("Added BLANK to atlas as number" + (index++)); atlas.token = atlas.token + ":blank"; } else if (location.equalsIgnoreCase("none")) { byte b = (byte) 0; for (int count = 0; count < atlas.width * atlas.height; count++) { buf.put(b).put(b).put(b).put(b); } // System.out // .println("Added BLANK to atlas as number" + (index++)); atlas.token = atlas.token + ":blank"; } else { PNGDecoder decoder = getImageFile(location); if (decoder == null) { byte b = (byte) 255; for (int count = 0; count < atlas.width * atlas.height; count++) { buf.put(b).put(b).put(b).put(b); } } else { if (decoder.getWidth() != atlas.width || decoder.getHeight() != atlas.height) { System.out.println( "Non-standard image size. All images" + " in an atlas must have the same size"); System.out.println("Offender : " + location); return null; } try { decoder.decode(buf, atlas.width * 4, Format.RGBA); } catch (IOException e) { new DebugExceptionHandler(e); } } // System.out.println("Added " + location + // " to atlas as number " // + (index++)); atlas.token = atlas.token + ":" + location; } } buf.flip(); GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL11.GL_RGBA, atlas.width, atlas.height, atlas.depth, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf); Util.checkErr(); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); Util.checkErr(); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); Util.checkErr(); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); Util.checkErr(); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); Util.checkErr(); // GL30.glGenerateMipmap(GL30.GL_TEXTURE_2D_ARRAY); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0); Util.checkErr(); return atlas; }
From source file:com.opengrave.og.resources.TextureAtlasEditable.java
License:Open Source License
public TextureAtlasEditable(int size, float r, float g, float b, float a) { this.size = getPowerOfTwo(size); id = GL11.glGenTextures();/*from ww w. ja v a 2s . c o m*/ 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(GL30.GL_TEXTURE_2D_ARRAY, id); GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL11.GL_RGBA, this.size, this.size, 1, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, mainBuf); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0); }
From source file:com.opengrave.og.resources.TextureAtlasEditable.java
License:Open Source License
@Override public void bind(int t) { GL13.glActiveTexture(t);//w ww. j a va2 s .c om if (pixels != null) { id = GL11.glGenTextures(); mainBuf = BufferUtils.createByteBuffer(4 * this.size * this.size); // for (int i = this.size - 1; i >= 0; i--) { for (int i = 0; i < this.size; i++) { for (int j = 0; j < this.size; j++) { float r = 1f, g = 1f, b = 1f, a = 0f; if (i < py && j < px) { int pixel = pixels[i * px + j]; r = (float) ((pixel >> 16) & 0xFF) / 255f; g = (float) ((pixel >> 8) & 0xFF) / 255f; b = (float) (pixel & 0xFF) / 255f; a = (float) ((pixel >> 24) & 0xFF) / 255f; } addColour(r, g, b, a); } } mainBuf.flip(); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, id); GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL11.GL_RGBA, this.size, this.size, 1, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, mainBuf); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0); pixels = null; } synchronized (changeList) { if (changeList.size() < 10) { GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, id); for (TextureEditableDeferedChanges change : changeList) { applyChangeToMainBuffer(change); ByteBuffer buf = BufferUtils.createByteBuffer(4); buf.put((byte) (255 * change.getColour().z)).put((byte) (255 * change.getColour().y)) .put((byte) (255 * change.getColour().x)).put((byte) (255 * change.getColour().w)); buf.flip(); GL11.glTexSubImage2D(GL30.GL_TEXTURE_2D_ARRAY, 0, change.getX(), change.getY(), 1, 1, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, buf); } GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0); } else { // Replace the whole image. There's bound to be better ways // around this... for (TextureEditableDeferedChanges change : changeList) { applyChangeToMainBuffer(change); } mainBuf.position(0); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, id); Util.checkErr(); GL12.glTexSubImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, size, size, 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, mainBuf); Util.checkErr(); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0); Util.checkErr(); } changeList.clear(); } Util.checkErr(); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, id); lastTexNum = t; }
From source file:com.opengrave.og.resources.TextureAtlasEditable.java
License:Open Source License
@Override public void unbind() { GL13.glActiveTexture(lastTexNum); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0); }
From source file:com.opengrave.og.resources.TextureDead.java
License:Open Source License
public static TextureDead create(String location) { InputStream in = null;// w w w . j av a 2s.c o 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 w w.ja v a 2 s .c o m 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); }