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:com.xrbpowered.gl.res.textures.CubeTexture.java

License:Open Source License

public CubeTexture(String pathFormat) {
    try {// w ww  .  j  a v  a 2 s.c o m
        texId = GL11.glGenTextures();
        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texId);

        IntBuffer buf = null;

        for (int i = 0; i < 6; i++) {
            //            BufferedImage img = load(new FileInputStream(String.format("assets/"+pathFormat, FACE_NAMES[i])));
            BufferedImage img = AssetManager.defaultAssets.loadImage(String.format(pathFormat, FACE_NAMES[i]));
            buf = getPixels(img, buf);
            put(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, img.getWidth(), img.getHeight(), buf);
        }

        GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
        GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
        GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL12.GL_TEXTURE_WRAP_R, GL12.GL_CLAMP_TO_EDGE);
        GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, 0);

        Client.checkError();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    }
}

From source file:com.xrbpowered.gl.res.textures.Texture.java

License:Open Source License

protected void create(int w, int h, IntBuffer buf, boolean wrap, boolean filter) {
    width = w;//from  w w w  . j  a  va 2  s .  c om
    height = h;
    texId = GL11.glGenTextures();
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);

    put(GL11.GL_TEXTURE_2D, w, h, buf);
    setProperties(GL11.GL_TEXTURE_2D, wrap, filter, Client.settings.anisotropy);
}

From source file:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public int createTexture(int width, int height) {

    int texId = GL11.glGenTextures();
    if (texId == 0) {
        return 0;
    }/*  w w w. j  a  v a2s  .c  om*/

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);

    // make the texture
    clearGLErrors();
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, 0);

    // if something bad happened, delete the texture
    if (hasGLError()) {
        GL11.glDeleteTextures(texId);
        return 0;
    }

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

    return texId;
}

From source file:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public int genAndBindTexture() {
    int texId = GL11.glGenTextures();
    setBoundTexture(texId);
    return texId;
}

From source file:dataAccess.lwjgl.VAO_Loader.java

public static int loadCubeMap(String... textureFiles) {
    int texID = GL11.glGenTextures();
    GL13.glActiveTexture(texID);//from ww  w .j a  v a2  s . co  m
    GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texID);

    for (int i = 0; i < textureFiles.length; i++) {
        TextureData data = dataAccess.fileLoaders.TextureLoader
                .decodeTextureFile("res/textures/skybox/" + textureFiles[i] + ".png");
        GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL11.GL_RGBA, data.getWidth(),
                data.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data.getBuffer());
    }
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
    textureMap.put("cubeMap", texID);
    return texID;
}

From source file:de.ikosa.mars.viewer.glviewer.engine.GLTextureArrayBuilder.java

License:Open Source License

@Override
public GLTextureArray createTexture() {
    try {//  w  w w . ja  v a  2 s .  c o  m
        int files = filePaths.length;
        byte[][] imageData = new byte[files][];
        int totalSize = 0;
        int imageWidth = 0;
        int imageHeight = 0;
        // read in files
        for (int file = 0; file < files; file++) {
            InputStream inputStream = new FileInputStream(filePaths[file]);
            BufferedImage image = ImageIO.read(inputStream);

            if (file > 0)
                if (imageWidth != image.getWidth() | imageHeight != image.getHeight())
                    ML.f("Incompatible images in 3D texture...");

            imageWidth = image.getWidth();
            imageHeight = image.getHeight();

            imageData[file] = GLPNGLoader.loadPNG(image);
            totalSize += imageData[file].length;
        }

        // store in consecutive buffer
        ByteBuffer buffer = ByteBuffer.allocateDirect(totalSize);
        for (int file = 0; file < files; file++) {
            byte[] singleImageData = imageData[file];
            for (int i = 0; i < singleImageData.length; i++)
                buffer.put(singleImageData[i]);
        }

        buffer.flip();

        int textureId = GL11.glGenTextures();
        GLRenderer2Stage.errorCheck("generating texture id");

        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GLRenderer2Stage.errorCheck("activating texture image unit");

        GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, textureId);
        GLRenderer2Stage.errorCheck("binding 2d texture array");

        GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
        GLRenderer2Stage.errorCheck("setting unpack aligment");

        GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL11.GL_RGBA, imageWidth, imageHeight, files, 0,
                GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
        GLRenderer2Stage.errorCheck("storing 2d texture array data");

        GL30.glGenerateMipmap(GL30.GL_TEXTURE_2D_ARRAY);
        GLRenderer2Stage.errorCheck("generating 2d texture array mipmaps");

        GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, 0);
        GLRenderer2Stage.errorCheck("unbinding 2d texture array");

        return new GLTextureArray(name, textureId);
    } catch (Exception e) {
        ML.f(e);
    }
    return null;
}

From source file:de.ikosa.mars.viewer.glviewer.engine.GLTextureBuilder.java

License:Open Source License

public static GLTexture createEmptyTexture(String name, int width, int height, byte r, byte g, byte b, byte a) {
    try {//from  w  w w  . j  av a2  s.c  om
        int textureId = GL11.glGenTextures();

        ByteBuffer buffer = ByteBuffer.allocateDirect(width * height * 4);

        for (int i = 0; i < width * height; i++) {
            buffer.put(r);
            buffer.put(g);
            buffer.put(b);
            buffer.put(a);
        }
        buffer.flip();

        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
        GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA,
                GL11.GL_UNSIGNED_BYTE, buffer);
        GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

        return new GLTexture(name, textureId);
    } catch (Exception e) {
        ML.f(e);
    }
    return null;
}

From source file:de.ikosa.mars.viewer.glviewer.engine.GLTextureBuilder.java

License:Open Source License

public static GLTexture createEmptyTexture(String name, int width, int height, float initial) {
    try {/* w  ww .ja v a  2 s .  c  om*/
        int textureId = GL11.glGenTextures();

        ByteBuffer buffer = ByteBuffer.allocateDirect(width * height * 4);

        for (int i = 0; i < width * height * 4; i++) {
            buffer.put((byte) 0);
        }
        buffer.flip();

        GL13.glActiveTexture(GL13.GL_TEXTURE0);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
        GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_DEPTH_COMPONENT, width, height, 0,
                GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, buffer);
        GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

        return new GLTexture(name, textureId);
    } catch (Exception e) {
        ML.f(e);
    }
    return null;
}

From source file:de.ikosa.mars.viewer.glviewer.engine.GLTextureBuilder.java

License:Open Source License

private int createRGBTexture(BufferedImage image, byte[] x) {
    ByteBuffer buffer;//from ww  w  . jav a2 s  . c om

    buffer = ByteBuffer.allocateDirect(x.length);
    for (int i = 0; i < x.length; i++) {
        buffer.put(x[i]);
    }

    buffer.flip();

    int textureId = GL11.glGenTextures();
    GLRenderer2Stage.errorCheck("generating texture id");

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GLRenderer2Stage.errorCheck("activating texture image unit");

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
    GLRenderer2Stage.errorCheck("binding 2d texture");

    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
    GLRenderer2Stage.errorCheck("setting unpack aligment");

    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, buffer);
    GLRenderer2Stage.errorCheck("storing 2d texture data");

    GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
    GLRenderer2Stage.errorCheck("generating 2d texture array mipmaps");

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
    GLRenderer2Stage.errorCheck("unbinding 2d texture array");
    return textureId;
}

From source file:de.ikosa.mars.viewer.glviewer.engine.GLTextureBuilder.java

License:Open Source License

private int createGrayscaleTexture(BufferedImage image, byte[] x) {
    ShortBuffer buffer;//from   ww w  . j a  v  a 2 s.  co m

    buffer = BufferUtils.createShortBuffer(image.getHeight() * image.getWidth());
    for (int i = 0; i < x.length; i += 2) {
        short val = (short) (fromByte(x[i]) + (fromByte(x[i + 1]) << 8));
        buffer.put(val);
    }

    buffer.flip();

    int textureId = GL11.glGenTextures();
    GLRenderer2Stage.errorCheck("generating texture id");

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GLRenderer2Stage.errorCheck("activating texture image unit");

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
    GLRenderer2Stage.errorCheck("binding 2d texture");

    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 2);
    GLRenderer2Stage.errorCheck("setting unpack aligment");

    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL30.GL_R16, image.getWidth(), image.getHeight(), 0, GL11.GL_RED,
            GL11.GL_UNSIGNED_SHORT, buffer);
    GLRenderer2Stage.errorCheck("storing 2d texture data");

    GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
    GLRenderer2Stage.errorCheck("generating 2d texture array mipmaps");

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
    GLRenderer2Stage.errorCheck("unbinding 2d texture array");
    return textureId;
}