Example usage for org.lwjgl.opengl GL11 glGenTextures

List of usage examples for org.lwjgl.opengl GL11 glGenTextures

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 glGenTextures.

Prototype

@NativeType("void")
public static int glGenTextures() 

Source Link

Document

Returns n previously unused texture names in textures.

Usage

From source file:eu.over9000.veya.gui.TrueTypeFont.java

License:Open Source License

private void buildTexture(final BufferedImage imgTemp) throws IOException {
    textureId = GL11.glGenTextures();

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);

    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ImageIO.write(imgTemp, "png", byteArrayOutputStream);
    final PNGDecoder decoder = new PNGDecoder(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
    final ByteBuffer buffer = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight());
    decoder.decode(buffer, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
    buffer.flip();//from w ww .  j  a  v a 2s .  co m

    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0,
            GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
    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:eu.over9000.veya.rendering.Shadow.java

License:Open Source License

public void init() {
    depthMap = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, depthMap);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_DEPTH_COMPONENT, SHADOW_WIDTH, SHADOW_HEIGHT, 0,
            GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (ByteBuffer) null);
    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.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL13.GL_CLAMP_TO_BORDER);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL13.GL_CLAMP_TO_BORDER);

    shadowFBO = GL30.glGenFramebuffers();
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, shadowFBO);
    GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL11.GL_TEXTURE_2D, depthMap, 0);
    GL11.glDrawBuffer(GL11.GL_NONE);/* w  w  w . j  a  va  2 s .c  o m*/
    GL11.glReadBuffer(GL11.GL_NONE);
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
}

From source file:eu.over9000.veya.util.TextureLoader.java

License:Open Source License

public static int loadFontTexture(final int textureUnit) {

    final int texId = GL11.glGenTextures();

    try {//from w w  w  .j a  v  a 2s .c  o  m
        final InputStream in = TextureLoader.class.getResourceAsStream("/textures/font.png");
        final PNGDecoder decoder = new PNGDecoder(in);

        final int sourceTexWidth = decoder.getWidth();
        final int sourceTexHeight = decoder.getHeight();

        final ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
        decoder.decode(byteBuffer, decoder.getWidth() * 4, Format.RGBA);
        byteBuffer.flip();

        GL13.glActiveTexture(textureUnit);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, sourceTexWidth, sourceTexHeight, 0, GL11.GL_RGBA,
                GL11.GL_UNSIGNED_BYTE, byteBuffer);

        // Setup the ST coordinate system
        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);

        // 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);

        org.lwjgl.opengl.Util.checkGLError();

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

    } catch (final IOException e) {
        e.printStackTrace();
        System.exit(-1);
    }

    return texId;
}

From source file:eu.over9000.veya.util.TextureLoader.java

License:Open Source License

public static int loadBlockTexture(final int textureUnit) {

    final InputStream in = TextureLoader.class.getResourceAsStream("/textures/blocks.png");
    ByteBuffer convertedBuffer = null;
    int sourceTexWidth = 0;
    int sourceTexHeight = 0;
    int texCount = 0;

    try {/*from www  . java2 s .  co m*/
        // Link the PNG decoder to this stream
        final PNGDecoder decoder = new PNGDecoder(in);

        // Get the width and height of the texture
        sourceTexWidth = decoder.getWidth();
        sourceTexHeight = decoder.getHeight();

        texCount = sourceTexWidth / TextureLoader.TEXTURE_WIDTH
                * (sourceTexHeight / TextureLoader.TEXTURE_WIDTH);

        // Decode the PNG file in a ByteBuffer
        final ByteBuffer buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
        decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
        buf.flip();

        convertedBuffer = TextureLoader.convertBuffer(buf, sourceTexWidth, sourceTexHeight);

        in.close();

    } catch (final IOException e) {
        e.printStackTrace();
        System.exit(-1);
    }

    // Create a new texture object in memory and bind it
    final int texId = GL11.glGenTextures();
    GL13.glActiveTexture(textureUnit);
    GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 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 model 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);
    GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL11.GL_RGBA, TextureLoader.TEXTURE_WIDTH,
            TextureLoader.TEXTURE_HEIGHT, texCount, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, convertedBuffer);
    GL30.glGenerateMipmap(GL30.GL_TEXTURE_2D_ARRAY);

    // Setup the ST coordinate system
    GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

    // Setup what to do when the texture has to be scaled
    GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR);

    org.lwjgl.opengl.Util.checkGLError();

    System.out
            .println("loading block texture, id=" + texId + ", w=" + sourceTexWidth + ", h=" + sourceTexHeight);

    GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0);

    return texId;
}

From source file:fr.guillaume.prive.viper.core.model.texture.PNGTextureLoader.java

public static int loadTexture(String filename, int textureUnit) {
    ByteBuffer buf = null;/*from   w w w  .  j av a 2  s .c o m*/
    int tWidth = 0;
    int tHeight = 0;

    try (InputStream in = new FileInputStream(filename)) {
        PNGDecoder decoder = new PNGDecoder(in);

        tWidth = decoder.getWidth();
        tHeight = decoder.getHeight();

        buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
        decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
        buf.flip();
        in.close();
    } catch (IOException e) {
        throw new IllegalStateException("PNG file i/o error", e);
    }

    // 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_RGBA16, 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_LINEAR_MIPMAP_LINEAR);

    GraphicMotor.exitOnGLError("loadPNGTexture");

    return texId;
}

From source file:fr.ign.cogit.geoxygene.appli.render.DisplayableTextRenderer.java

License:Open Source License

private int getTextTextureId() {
    if (this.textTextureId == -1) {
        this.textTextureId = GL11.glGenTextures();
        if (this.textTextureId < 0) {
            Logger.getRootLogger().error("Unable to use Text texture");
        }/*w w  w .  ja  v  a2 s. c om*/
    }
    return this.textTextureId;
}

From source file:go.graphics.swing.opengl.LWJGLDrawContext.java

License:Open Source License

@Override
public TextureHandle generateTexture(int width, int height, ShortBuffer data) {
    // 1 byte aligned.
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);

    int texture = GL11.glGenTextures();
    if (texture == 0) {
        return null;
    }/*from  w ww . java 2s  .  co m*/

    //fix strange alpha test problem (minimap and landscape are unaffected)
    ShortBuffer bfr = BufferUtils.createShortBuffer(data.capacity());
    int cap = data.capacity();
    for (int i = 0; i != cap; i++)
        bfr.put(i, data.get(i));

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA,
            GL12.GL_UNSIGNED_SHORT_4_4_4_4, bfr);
    setTextureParameters();

    return new LWJGLTextureHandle(this, texture);
}

From source file:im.bci.jnuit.lwjgl.assets.Texture.java

License:Open Source License

public Texture(int width, int height, boolean alpha) {
    id = GL11.glGenTextures();
    this.width = width;
    this.height = height;
    this.alpha = alpha;
}

From source file:io.root.gfx.glutils.GL.java

License:Apache License

public static int glGenTextures() {
    return GL11.glGenTextures();
}

From source file:itdelatrisu.opsu.render.Rendertarget.java

License:Open Source License

/**
 * Create a new FBO./*from   ww w  .j  a  v a  2  s .  co  m*/
 * @param width the width
 * @param height the height
 */
private Rendertarget(int width, int height) {
    this.width = width;
    this.height = height;
    fboID = EXTFramebufferObject.glGenFramebuffersEXT();
    textureID = GL11.glGenTextures();
    depthBufferID = EXTFramebufferObject.glGenRenderbuffersEXT();
}