List of usage examples for org.lwjgl.opengl GL11 glGenTextures
@NativeType("void") public static int glGenTextures()
From source file:com.kauridev.lunarfever.graphics.TextureLoader.java
License:Open Source License
public static Texture loadTexture(String file) { Texture texture = cache.get(file);/*from w w w . j ava 2 s . c o m*/ if (texture != null && texture.getTexture().valid()) { return texture; } BufferedImage image = loadImage(file); GL11.glEnable(GL11.GL_TEXTURE_2D); int id = GL11.glGenTextures(); // bind GL11.glBindTexture(GL11.GL_TEXTURE_2D, id); // set filter GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); // set wrap 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); // set unpack alignment GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); // send data to gpu GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, loadBuffer(image)); // Create texture texture = new Texture(id, image.getWidth(), image.getHeight()); cache.put(file, texture); return texture; }
From source file:com.mtbs3d.minecrift.FBOParams.java
License:LGPL
public FBOParams(String fboName, int textureType, int internalFormat, int baseFormat, int bufferType, int fboWidth, int fboHeight) throws Exception { Minecraft mc = Minecraft.getMinecraft(); _textureType = textureType;/*from ww w.j a v a 2s . co m*/ if (fboSupport == FBO_SUPPORT.USE_EXT_UNKNOWN) { // The framebuffer, which regroups 0, 1, or more textures, and 0 or 1 depth buffer. try { _frameBufferId = GL30.glGenFramebuffers(); fboSupport = FBO_SUPPORT.USE_GL30; } catch (IllegalStateException ex) { System.out.println( "[Minecrift] FBO creation: GL30.glGenFramebuffers not supported. Attempting to use EXTFramebufferObject.glGenFramebuffersEXT"); fboSupport = FBO_SUPPORT.USE_EXT; try { _frameBufferId = EXTFramebufferObject.glGenFramebuffersEXT(); } catch (IllegalStateException ex1) { System.out.println( "[Minecrift] FBO creation: EXTFramebufferObject.glGenFramebuffersEXT not supported, FBO creation failed."); throw ex1; } } } else if (fboSupport == FBO_SUPPORT.USE_GL30) { _frameBufferId = GL30.glGenFramebuffers(); } else { _frameBufferId = EXTFramebufferObject.glGenFramebuffersEXT(); } if (fboSupport == FBO_SUPPORT.USE_GL30) { _colorTextureId = GL11.glGenTextures(); _depthRenderBufferId = GL30.glGenRenderbuffers(); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, _frameBufferId); checkGLError("FBO bind framebuffer"); GL11.glBindTexture(textureType, _colorTextureId); checkGLError("FBO bind texture"); GL11.glEnable(textureType); GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(textureType, 0, internalFormat, fboWidth, fboHeight, 0, baseFormat, bufferType, (java.nio.ByteBuffer) null); System.out.println("[Minecrift] FBO '" + fboName + "': w: " + fboWidth + ", h: " + fboHeight); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, textureType, _colorTextureId, 0); checkGLError("FBO bind texture framebuffer"); GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, _depthRenderBufferId); // bind the depth renderbuffer GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL14.GL_DEPTH_COMPONENT24, fboWidth, fboHeight); // get the data space for it GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, _depthRenderBufferId); checkGLError("FBO bind depth framebuffer"); } else { _colorTextureId = GL11.glGenTextures(); _depthRenderBufferId = EXTFramebufferObject.glGenRenderbuffersEXT(); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, _frameBufferId); checkGLError("FBO bind framebuffer"); GL11.glBindTexture(textureType, _colorTextureId); checkGLError("FBO bind texture"); GL11.glEnable(textureType); GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(textureType, 0, internalFormat, fboWidth, fboHeight, 0, baseFormat, bufferType, (java.nio.ByteBuffer) null); System.out.println("[Minecrift] FBO '" + fboName + "': w: " + fboWidth + ", h: " + fboHeight); EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, textureType, _colorTextureId, 0); checkGLError("FBO bind texture framebuffer"); EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, _depthRenderBufferId); // bind the depth renderbuffer EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL14.GL_DEPTH_COMPONENT24, fboWidth, fboHeight); // get the data space for it EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, _depthRenderBufferId); checkGLError("FBO bind depth framebuffer"); } if (!checkFramebufferStatus()) { // OK, if we have an error here - then throw an exception System.out.println("[Minecrift] FAILED to create framebuffer!!"); throw new Exception("Failed to create framebuffer"); } }
From source file:com.mtbs3d.minecrift.render.FBOParams.java
License:LGPL
public FBOParams(String fboName, int textureType, int internalFormat, int baseFormat, int bufferType, int fboWidth, int fboHeight) throws Exception { Minecraft mc = Minecraft.getMinecraft(); _textureType = textureType;/*from w w w. j a va2 s .co m*/ if (fboSupport == FBO_SUPPORT.USE_EXT_UNKNOWN) { // The framebuffer, which regroups 0, 1, or more textures, and 0 or 1 depth buffer. try { _frameBufferId = GL30.glGenFramebuffers(); fboSupport = FBO_SUPPORT.USE_GL30; } catch (IllegalStateException ex) { System.out.println( "[Minecrift] FBO creation: GL30.glGenFramebuffers not supported. Attempting to use EXTFramebufferObject.glGenFramebuffersEXT"); fboSupport = FBO_SUPPORT.USE_EXT; try { _frameBufferId = EXTFramebufferObject.glGenFramebuffersEXT(); } catch (IllegalStateException ex1) { System.out.println( "[Minecrift] FBO creation: EXTFramebufferObject.glGenFramebuffersEXT not supported, FBO creation failed."); throw ex1; } } } else if (fboSupport == FBO_SUPPORT.USE_GL30) { _frameBufferId = GL30.glGenFramebuffers(); } else { _frameBufferId = EXTFramebufferObject.glGenFramebuffersEXT(); } if (fboSupport == FBO_SUPPORT.USE_GL30) { _colorTextureId = GL11.glGenTextures(); _depthRenderBufferId = GL30.glGenRenderbuffers(); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, _frameBufferId); mc.checkGLError("FBO bind framebuffer"); GL11.glBindTexture(textureType, _colorTextureId); mc.checkGLError("FBO bind texture"); GL11.glEnable(textureType); GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(textureType, 0, internalFormat, fboWidth, fboHeight, 0, baseFormat, bufferType, (java.nio.ByteBuffer) null); //System.out.println("[Minecrift] FBO '" + fboName + "': w: " + fboWidth + ", h: " + fboHeight); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, textureType, _colorTextureId, 0); mc.checkGLError("FBO bind texture framebuffer"); GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, _depthRenderBufferId); // bind the depth renderbuffer GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL14.GL_DEPTH_COMPONENT24, fboWidth, fboHeight); // get the data space for it GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, _depthRenderBufferId); mc.checkGLError("FBO bind depth framebuffer"); } else { _colorTextureId = GL11.glGenTextures(); _depthRenderBufferId = EXTFramebufferObject.glGenRenderbuffersEXT(); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, _frameBufferId); mc.checkGLError("FBO bind framebuffer"); GL11.glBindTexture(textureType, _colorTextureId); mc.checkGLError("FBO bind texture"); GL11.glEnable(textureType); GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexImage2D(textureType, 0, internalFormat, fboWidth, fboHeight, 0, baseFormat, bufferType, (java.nio.ByteBuffer) null); //System.out.println("[Minecrift] FBO '" + fboName + "': w: " + fboWidth + ", h: " + fboHeight); EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, textureType, _colorTextureId, 0); mc.checkGLError("FBO bind texture framebuffer"); EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, _depthRenderBufferId); // bind the depth renderbuffer EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL14.GL_DEPTH_COMPONENT24, fboWidth, fboHeight); // get the data space for it EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, _depthRenderBufferId); mc.checkGLError("FBO bind depth framebuffer"); } if (!checkFramebufferStatus()) { // OK, if we have an error here - then throw an exception System.out.println("[Minecrift] FAILED to create framebuffer!!"); throw new Exception("Failed to create framebuffer"); } }
From source file:com.opengrave.og.light.Texture2DShadowMap.java
License:Open Source License
public Texture2DShadowMap(int size) { texture = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); Util.checkErr();/*from ww w . java 2 s .c om*/ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); Util.checkErr(); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); Util.checkErr(); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); Util.checkErr(); // GL11.glTexParameteri(GL11.GL_TEXTURE_2D, // GL14.GL_TEXTURE_COMPARE_FUNC, GL11.GL_LEQUAL); // GL11.glTexParameteri(GL11.GL_TEXTURE_2D, // GL14.GL_TEXTURE_COMPARE_MODE, // GL30.GL_COMPARE_REF_TO_TEXTURE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_COMPARE_MODE, GL11.GL_NONE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_DEPTH_TEXTURE_MODE, GL11.GL_INTENSITY); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_DEPTH_COMPONENT, size, size, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (FloatBuffer) null); Util.checkErr(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); // texture2 = GL11.glGenTextures(); // GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture2); // GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0,GL11.GL_RGB, size, size, // 0,GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, (FloatBuffer)null); // 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.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.glBindTexture(GL11.GL_TEXTURE_2D, 0); }
From source file:com.opengrave.og.light.TextureCubeShadowMap.java
License:Open Source License
public TextureCubeShadowMap(int size) { texture = GL11.glGenTextures(); GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texture); GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); Util.checkErr();// w w w.ja v a 2 s . co m GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); Util.checkErr(); GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); Util.checkErr(); GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); Util.checkErr(); GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL12.GL_TEXTURE_WRAP_R, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL14.GL_TEXTURE_COMPARE_MODE, GL11.GL_NONE); GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL14.GL_DEPTH_TEXTURE_MODE, GL11.GL_INTENSITY); // GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, // GL12.GL_TEXTURE_BASE_LEVEL, 0); // GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, // GL12.GL_TEXTURE_MAX_LEVEL, 0); for (int i = 0; i < 6; i++) { GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL11.GL_DEPTH_COMPONENT, size, size, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (FloatBuffer) null); } Util.checkErr(); GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, 0); // texture2 = GL11.glGenTextures(); // GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture2); // GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0,GL11.GL_RGB, size, size, // 0,GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, (FloatBuffer)null); // 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.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.glBindTexture(GL11.GL_TEXTURE_2D, 0); }
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//www . j a va2s.co m 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(); mainBuf = BufferUtils.createByteBuffer(4 * this.size * this.size); for (int count = 0; count < this.size * this.size; count++) { addColour(r, g, b, a);//from www . jav a 2s . c o m } 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);/* ww w.j a v a 2 s . co m*/ 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.TextureDead.java
License:Open Source License
public static TextureDead create(String location) { InputStream in = null;//ww w . j a v a 2 s . 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(); mainBuf = BufferUtils.createByteBuffer(4 * this.size * this.size); for (int count = 0; count < this.size * this.size; count++) { addColour(r, g, b, a);//from w ww . j a v a 2 s . co m } 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); }