List of usage examples for org.lwjgl.opengl GL11 glGenTextures
@NativeType("void") public static int glGenTextures()
From source file:itemrender.client.rendering.FBOHelper.java
License:MIT License
private void createFramebuffer() { framebufferID = EXTFramebufferObject.glGenFramebuffersEXT(); textureID = GL11.glGenTextures(); int currentFramebuffer = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT); int currentTexture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, framebufferID); // Set our texture up, empty. GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID); 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.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, renderTextureSize, renderTextureSize, 0, GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, (java.nio.ByteBuffer) null); // Restore old texture GL11.glBindTexture(GL11.GL_TEXTURE_2D, currentTexture); // Create depth buffer depthbufferID = EXTFramebufferObject.glGenRenderbuffersEXT(); EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthbufferID); EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, GL11.GL_DEPTH_COMPONENT, renderTextureSize, renderTextureSize); // Bind depth buffer to the framebuffer EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthbufferID);//from ww w . j a v a 2s. com // Bind our texture to the framebuffer EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, textureID, 0); // Revert to default framebuffer EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, currentFramebuffer); }
From source file:ivengine.Util.java
License:Creative Commons License
/** * Loads a texture from a URL <filename> into a texture unit <textureUnit> *//*from w w w.j a va 2 s.c om*/ public static int loadPNGTexture(URL filename, int textureUnit) { ByteBuffer buf = null; int tWidth = 0; int tHeight = 0; try { // Open the PNG file as an InputStream InputStream in = filename.openStream(); // Link the PNG decoder to this stream PNGDecoder decoder = new PNGDecoder(in); // Get the width and height of the texture tWidth = decoder.getWidth(); tHeight = decoder.getHeight(); // Decode the PNG file in a ByteBuffer buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight()); decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA); buf.flip(); in.close(); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } // 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); return texId; }
From source file:ivengine.Util.java
License:Creative Commons License
/** * Stores a variable amount of textures defined by URLS <filenames> into a texture array. Uses a magfilter <magfilter>, a minfilter <minfilter>. * If <mipmap> is true, mipmaps will be activated. * If <anisotropic> is true, anisotropic filtering will be activated, if supported. *//*from ww w. ja v a 2 s. co m*/ public static int loadTextureAtlasIntoTextureArray(URL[] filenames, int magfilter, int minfilter, boolean mipmap, boolean anisotropic) { int tex = GL11.glGenTextures(); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, tex); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MAG_FILTER, magfilter); GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MIN_FILTER, minfilter); 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); ByteBuffer buf = null; PNGDecoder decoder = null; try { InputStream in = filenames[0].openStream(); decoder = new PNGDecoder(in); buf = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight()); decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA); buf.flip(); in.close(); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } int tileWidth = decoder.getWidth(); System.out.println(tileWidth); int tileHeight = decoder.getHeight(); System.out.println(tileHeight); GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL11.GL_RGBA, tileWidth, tileHeight, filenames.length, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); for (int i = 0; i < filenames.length; i++) { GL12.glTexSubImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, /*tileWidth*x*/0, /*tileHeight*y*/0, i, tileWidth, tileHeight, 1, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf); buf.rewind(); if (i < filenames.length - 1) loadTexture(filenames[i + 1], buf); } if (mipmap) GL30.glGenerateMipmap(GL30.GL_TEXTURE_2D_ARRAY); if (anisotropic) { if (GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) { float maxanis = GL11.glGetFloat(EXTTextureFilterAnisotropic.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT); System.out.println("Anisotropic filtering activated with a resolution of " + maxanis); System.out.println(GL11.glGetError()); GL11.glTexParameterf(GL30.GL_TEXTURE_2D_ARRAY, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, maxanis); System.out.println(GL11.glGetError()); } else { System.err.println( "WARNING - Anisotropic filtering not supported by this graphics card. Setting it as disabled"); } } GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0); return tex; }
From source file:jpcsp.graphics.RE.RenderingEngineLwjgl.java
License:Open Source License
@Override public int genTexture() { return GL11.glGenTextures(); }
From source file:loon.core.graphics.opengl.LWjglGL10.java
License:Apache License
public final void glGenTextures(int n, int[] textures, int offset) { for (int i = offset; i < offset + n; i++) { textures[i] = GL11.glGenTextures(); }/* ww w . jav a 2 s. c o m*/ }
From source file:main.java.com.YeAJG.game.io.FileIOHandler.java
License:Open Source License
public static int loadPNGTexture(String filename, int textureUnit) throws IOException { ByteBuffer buf = null;//from w w w.j a va 2 s .com int tWidth = 0; int tHeight = 0; try { // Open the PNG file as an InputStream InputStream in = new FileInputStream(filename); // Link the PNG decoder to this stream PNGDecoder decoder = new PNGDecoder(in); // Get the width and height of the texture tWidth = decoder.getWidth(); tHeight = decoder.getHeight(); // Decode the PNG file in a ByteBuffer buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight()); decoder.decode(buf, decoder.getWidth() * 4, PNGDecoder.RGBA); buf.flip(); in.close(); } catch (IOException e) { throw new IOException(e.getMessage()); } // 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_RGBA, 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_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); Game.exitOnGLError("loadPNGTexture"); return texId; }
From source file:me.thehutch.fusion.engine.render.opengl.gl20.OpenGL20Texture.java
License:Open Source License
@Override public void create() { ensureNotCreated("Texture is already created."); // Generate the texture this.id = GL11.glGenTextures(); // Create the texture super.create(); }
From source file:me.ukl.api.util.TextureUtil.java
License:MIT License
public static int loadTexture(int[] rgb, int width, int height) { IntBuffer rgbBuf = BufferUtils.createIntBuffer(rgb.length); rgbBuf.put(rgb);/* w w w . ja v a 2 s . c om*/ rgbBuf.flip(); int tex = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, rgbBuf); return tex; }
From source file:net.chocolapod.lwjgfont.texture.FontTextureLoader.java
License:Open Source License
private static FontTexture makeTexture(Class clazz, String imagePath) throws IOException { BufferedImage srcImage;//from w w w .ja va 2 s. com int srcImageType; srcImage = ImageIO.read(clazz.getResourceAsStream(imagePath)); srcImageType = srcImage.getType(); int target = GL_TEXTURE_2D; // target int dstPixelFormat = GL_RGBA; // dst pixel format int format = GL_UNSIGNED_BYTE; // data type // ? ID ?? int textureID = GL11.glGenTextures(); FontTexture texture = new FontTexture(target, textureID); // glTexImage2D() ???? ID ?? glBindTexture(target, textureID); // All RGB bytes are aligned to each other and each component is 1 byte // GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); int width = srcImage.getWidth(); int height = srcImage.getHeight(); texture.setWidth(width); texture.setHeight(height); texture.setTextureWidth(width); texture.setTextureHeight(height); texture.setAlphaPremultiplied(false); ByteBuffer byteBuffer; Pixel pixel = null; // System.out.println(srcImageType); if (srcImageType == BufferedImage.TYPE_INT_ARGB) { throw new RuntimeException("Unsupported type: " + srcImage.getType()); } else if (srcImageType == BufferedImage.TYPE_3BYTE_BGR) { pixel = new Pixel3ByteBGR(); } else if (srcImageType == BufferedImage.TYPE_4BYTE_ABGR) { // Photoshop ? 8bit/?? ????? // ?? ABGR ??????????? 8bit(1Byte) ???? pixel = new Pixel4ByteABGR(); } else if (srcImageType == BufferedImage.TYPE_CUSTOM) { // Photoshop ? 16bit/?? ????? // ?? ABGR ??????????? 16bit(2Byte) ???? // pixel = new Pixel8ByteABGR(); // ????????? // MikMikuStudio/engine/src/core/com/jme3/texture/Image.java // MikMikuStudio/engine/src/jogl2/com/jme3/renderer/jogl/TextureUtil.java // ?????? // pixel = new Pixel4ByteABGR(); /* dstPixelFormat = GL_RGBA2; dstPixelFormat = GL_RGBA8; */ dstPixelFormat = GL_RGBA16; /* format = GL_UNSIGNED_SHORT; format = GL_SHORT; format = GL_UNSIGNED_SHORT_4_4_4_4; */ // Miku.png (8bit/channel)???????????? Pixel4ByteABGR ??? pixel = new Pixel4ByteABGR(); } else { throw new RuntimeException("Unsupported type: " + srcImage.getType()); } byteBuffer = pixel.toBuffer(srcImage); byteBuffer.order(ByteOrder.nativeOrder()); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int b[] = srcImage.getRaster().getPixel(x, y, pixel.getBuffer()); pixel.writeBuffer(byteBuffer); } } byteBuffer.flip(); // ????? glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // ???????? glTexImage2D(target, 0, dstPixelFormat, // ??? width, height, 0, // ???????? 0???? 1 GL_RGBA, // ??? ? http://wisdom.sakura.ne.jp/system/opengl/gl22.html format, // ????? http://wisdom.sakura.ne.jp/system/opengl/gl22.html byteBuffer); // ?? // GL30.glGenerateMipmap(GL_TEXTURE_2D); byteBuffer.clear(); return texture; }
From source file:net.minecraft.src.PaintWorld.java
License:Open Source License
public void getTextureForFace(int face) { PaintFace pface = renderBlock.paintedFaces[face]; if (textureBuffer == null) { textureBuffer = ByteBuffer.allocateDirect(ARRAY_SIZE); textureBuffer.order(ByteOrder.nativeOrder()); }/* w w w . j a v a2s .c om*/ if (textureId <= 0) { textureId = GL11.glGenTextures(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); 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); } GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); textureBuffer.clear(); textureBuffer.put(pface.points); textureBuffer.flip(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, ROW, ROW, 0, GL11.GL_RGBA, GL11.GL_BYTE, textureBuffer); }