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

public static void glGenTextures(@NativeType("GLuint *") int[] textures) 

Source Link

Document

Array version of: #glGenTextures GenTextures

Usage

From source file:a1.gui.GUI_Map.java

License:Open Source License

public void DoCreate() {
    IntBuffer tt = BufferUtils.createIntBuffer(1);
    GL11.glGenTextures(tt);
    LightMap = tt.get(0);/*from   w ww . jav a  2  s . co  m*/

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, LightMap);
    ByteBuffer bb = BufferUtils.createByteBuffer(1024 * 1024 * 4);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, 1024, 1024, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE,
            bb);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    Render2D.CheckError();
}

From source file:betterfonts.GlyphCache.java

License:Open Source License

/**
 * Allocate a new OpenGL texture for caching pre-rendered glyph images. The new texture is initialized to fully transparent
 * white so the individual glyphs images within can have a transparent border between them. The new texture remains bound
 * after returning from the function./*from  www .j  a v a  2s  .com*/
 *
 * @todo use GL_ALPHA4 if anti-alias is turned off for even smaller textures
 */
private void allocateGlyphCacheTexture() {
    /* Initialize the background to all white but fully transparent. */
    glyphCacheGraphics.clearRect(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);

    /* Allocate new OpenGL texure */
    singleIntBuffer.clear();
    GL11.glGenTextures(singleIntBuffer);
    textureName = singleIntBuffer.get(0);

    /* Load imageBuffer with pixel data ready for transfer to OpenGL texture */
    updateImageBuffer(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);

    /*
     * Initialize texture with the now cleared BufferedImage. Using a texture with GL_ALPHA8 internal format may result in
     * faster rendering since the GPU has to only fetch 1 byte per texel instead of 4 with a regular RGBA texture.
     */
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureName);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_ALPHA8, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, imageBuffer);

    /* Explicitely disable mipmap support becuase updateTexture() will only update the base level 0 */
    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);
}

From source file:com.ardor3d.renderer.lwjgl.LwjglPbufferTextureRenderer.java

License:Open Source License

/**
 * <code>setupTexture</code> initializes a new Texture object for use with TextureRenderer. Generates a valid gl
 * texture id for this texture and inits the data type for the texture.
 *///from ww  w.ja va 2 s .  co  m
public void setupTexture(final Texture tex) {
    if (tex.getType() != Type.TwoDimensional) {
        throw new IllegalArgumentException("Unsupported type: " + tex.getType());
    }
    final RenderContext context = ContextManager.getCurrentContext();
    final TextureStateRecord record = (TextureStateRecord) context
            .getStateRecord(RenderState.StateType.Texture);

    // check if we are already setup... if so, throw error.
    if (tex.getTextureKey() == null) {
        tex.setTextureKey(TextureKey.getRTTKey(tex.getMinificationFilter()));
    } else if (tex.getTextureIdForContext(context.getGlContextRep()) != 0) {
        throw new Ardor3dException("Texture is already setup and has id.");
    }

    // Create the texture
    final IntBuffer ibuf = BufferUtils.createIntBuffer(1);
    GL11.glGenTextures(ibuf);
    final int textureId = ibuf.get(0);
    tex.setTextureIdForContext(context.getGlContextRep(), textureId);

    LwjglTextureStateUtil.doTextureBind(tex, 0, true);

    // Initialize our texture with some default data.
    final int internalFormat = LwjglTextureUtil.getGLInternalFormat(tex.getTextureStoreFormat());
    final int dataFormat = LwjglTextureUtil.getGLPixelFormatFromStoreFormat(tex.getTextureStoreFormat());
    final int pixelDataType = LwjglTextureUtil.getGLPixelDataType(tex.getRenderedTexturePixelDataType());

    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, internalFormat, _width, _height, 0, dataFormat, pixelDataType,
            (ByteBuffer) null);

    // Setup filtering and wrap
    final TextureRecord texRecord = record.getTextureRecord(textureId, tex.getType());
    LwjglTextureStateUtil.applyFilter(tex, texRecord, 0, record, context.getCapabilities());
    LwjglTextureStateUtil.applyWrap(tex, texRecord, 0, record, context.getCapabilities());

    logger.fine("setup pbuffer tex" + textureId + ": " + _width + "," + _height);
}

From source file:com.ardor3d.renderer.lwjgl.LwjglTextureRenderer.java

License:Open Source License

/**
 * <code>setupTexture</code> initializes a new Texture object for use with TextureRenderer. Generates a valid OpenGL
 * texture id for this texture and initializes the data type for the texture.
 *//*from www .  j  av a  2s .  co  m*/
public void setupTexture(final Texture tex) {
    if (tex.getType() != Type.TwoDimensional && tex.getType() != Type.CubeMap) {
        throw new IllegalArgumentException("Texture type not supported: " + tex.getType());
    }

    final RenderContext context = ContextManager.getCurrentContext();
    final TextureStateRecord record = (TextureStateRecord) context
            .getStateRecord(RenderState.StateType.Texture);

    // check if we are already setup... if so, throw error.
    if (tex.getTextureKey() == null) {
        tex.setTextureKey(TextureKey.getRTTKey(tex.getMinificationFilter()));
    } else if (tex.getTextureIdForContext(context.getGlContextRep()) != 0) {
        throw new Ardor3dException("Texture is already setup and has id.");
    }

    // Create the texture
    final IntBuffer ibuf = BufferUtils.createIntBuffer(1);
    GL11.glGenTextures(ibuf);
    final int textureId = ibuf.get(0);
    tex.setTextureIdForContext(context.getGlContextRep(), textureId);

    LwjglTextureStateUtil.doTextureBind(tex, 0, true);

    // Initialize our texture with some default data.
    final int internalFormat = LwjglTextureUtil.getGLInternalFormat(tex.getTextureStoreFormat());
    final int dataFormat = LwjglTextureUtil.getGLPixelFormatFromStoreFormat(tex.getTextureStoreFormat());
    final int pixelDataType = LwjglTextureUtil.getGLPixelDataType(tex.getRenderedTexturePixelDataType());

    if (tex.getType() == Type.TwoDimensional) {
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, internalFormat, _width, _height, 0, dataFormat, pixelDataType,
                (ByteBuffer) null);
    } else {
        for (final Face face : Face.values()) {
            GL11.glTexImage2D(LwjglTextureStateUtil.getGLCubeMapFace(face), 0, internalFormat, _width, _height,
                    0, dataFormat, pixelDataType, (ByteBuffer) null);
        }
    }

    // Initialize mipmapping for this texture, if requested
    if (tex.getMinificationFilter().usesMipMapLevels()) {
        EXTFramebufferObject.glGenerateMipmapEXT(LwjglTextureStateUtil.getGLType(tex.getType()));
    }

    // Setup filtering and wrap
    final TextureRecord texRecord = record.getTextureRecord(textureId, tex.getType());
    LwjglTextureStateUtil.applyFilter(tex, texRecord, 0, record, context.getCapabilities());
    LwjglTextureStateUtil.applyWrap(tex, texRecord, 0, record, context.getCapabilities());

    logger.fine("setup fbo tex with id " + textureId + ": " + _width + "," + _height);
}

From source file:com.ardor3d.scene.state.lwjgl.LwjglTextureStateUtil.java

License:Open Source License

public static void load(final Texture texture, final int unit) {
    if (texture == null) {
        return;//  w w  w .  j  av  a  2  s .  c o m
    }

    final RenderContext context = ContextManager.getCurrentContext();
    if (context == null) {
        logger.warning("RenderContext is null for texture: " + texture);
        return;
    }

    final ContextCapabilities caps = context.getCapabilities();
    final TextureStateRecord record = (TextureStateRecord) context.getStateRecord(StateType.Texture);

    // Check we are in the right unit
    if (record != null) {
        checkAndSetUnit(unit, record, caps);
    }

    // Create the texture...
    // First, look for a texture in the cache just like ours
    final Texture cached = TextureManager.findCachedTexture(texture.getTextureKey());

    if (cached == null) {
        TextureManager.addToCache(texture);
    } else {
        final int textureId = cached.getTextureIdForContext(context.getGlContextRep());
        if (textureId != 0) {
            doTextureBind(cached, unit, false);
            return;
        }
    }

    // Create a new texture id for this texture
    final IntBuffer id = BufferUtils.createIntBuffer(1);
    id.clear();
    GL11.glGenTextures(id);
    final int textureId = id.get(0);

    // store the new id by our current gl context.
    texture.setTextureIdForContext(context.getGlContextRep(), textureId);

    update(texture, unit);
}

From source file:com.badlogic.gdx.backends.jglfw.JglfwGL20.java

License:Apache License

public void glGenTextures(int n, IntBuffer textures) {
    GL11.glGenTextures(textures);
}

From source file:com.badlogic.gdx.backends.lwjgl.LwjglGL10.java

License:Apache License

public final void glGenTextures(int n, IntBuffer textures) {
    GL11.glGenTextures(textures);
}

From source file:com.damagedearth.Utilities.Components.TrueTypeFont.java

License:Open Source License

public static int loadImage(BufferedImage bufferedImage) {
    try {/*from   ww w  . j  av  a  2s. 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:com.dbi.games.fortress.engine.graphics.TextureManager.java

public int newTextureID() {
    GL11.glGenTextures(textureIDBuffer);
    return textureIDBuffer.get(0);
}

From source file:com.dyonovan.tcnodetracker.lib.truetyper.TrueTypeFont.java

License:Open Source License

public static int loadImage(BufferedImage bufferedImage) {
    try {//from ww w .j  a  va 2 s  . co  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_NEAREST);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
        //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_NEAREST);

        //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_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR);
        //GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_NEAREST);

        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;
}