Example usage for org.lwjgl.opengl GL11 GL_TRUE

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

Introduction

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

Prototype

int GL_TRUE

To view the source code for org.lwjgl.opengl GL11 GL_TRUE.

Click Source Link

Document

Boolean

Usage

From source file:Doom.java

private void init() {
    // Setup an error callback. The default implementation
    // will print the error message in System.err.
    glfwSetErrorCallback(errorCallback = errorCallbackPrint(System.err));

    // Initialize GLFW. Most GLFW functions will not work before doing this.
    if (glfwInit() != GL11.GL_TRUE) {
        throw new IllegalStateException("Unable to initialize GLFW");
    }/*w w w .j  a va 2  s  . com*/

    // Configure our window
    glfwDefaultWindowHints(); // optional, the current window hints are already the default
    glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation
    glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable

    WIDTH = 600;
    HEIGHT = 600;

    // Create the window
    window = glfwCreateWindow(WIDTH, HEIGHT, "Hello World!", NULL, NULL);
    if (window == NULL) {
        throw new RuntimeException("Failed to create the GLFW window");
    }

    // Setup a key callback. It will be called every time a key is pressed, repeated or released.
    glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() {
        @Override
        public void invoke(long window, int key, int scancode, int action, int mods) {
            if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
                glfwSetWindowShouldClose(window, GL_TRUE); // We will detect this in our rendering loop
            }
            if (action == GLFW_REPEAT || action == GLFW_PRESS) {
                if (key == GLFW_KEY_W) {

                } else if (key == GLFW_KEY_A) {

                } else if (key == GLFW_KEY_S) {

                } else if (key == GLFW_KEY_D) {

                }
            }

        }
    });
    //mouse position callback
    glfwSetCursorPosCallback(window, posCallback = new GLFWCursorPosCallback() {
        private double prevX;
        private double prevY;

        @Override
        public void invoke(long window, double xpos, double ypos) {
            Doom.dX = xpos - prevX;
            Doom.dY = ypos - prevY;
            prevX = xpos;
            prevY = ypos;
        }
    });
    //mouse button callback
    glfwSetMouseButtonCallback(window, mouseCallback = new GLFWMouseButtonCallback() {
        @Override
        public void invoke(long window, int button, int action, int mods) {

        }
    });
    // Get the resolution of the primary monitor
    ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    // Center our window
    glfwSetWindowPos(window, (GLFWvidmode.width(vidmode) - WIDTH) / 2,
            (GLFWvidmode.height(vidmode) - HEIGHT) / 2);

    // Make the OpenGL context current
    glfwMakeContextCurrent(window);
    // Enable v-sync
    glfwSwapInterval(1);

    // Make the window visible
    glfwShowWindow(window);
}

From source file:RobotDemo.java

private void init() {
    GLFW.glfwInit();//from  w w  w . ja  v a  2s  . c  o m
    window = GLFW.glfwCreateWindow(WIDTH, HEIGHT, "Robot Demo", 0, 0);
    GLFW.glfwMakeContextCurrent(window);
    GL.createCapabilities();

    robots = new Robot[2];
    robots[0] = new Robot();
    robots[0].setColor(0.4f, 0.1f, 0.0f);
    robots[1] = new Robot();
    robots[1].setColor(0.0f, 0.1f, 0.4f);
    selectedRobot = 0;

    GLFW.glfwSetKeyCallback(window, new GLFWKeyCallback() {
        @Override
        public void invoke(long window, int key, int scancode, int action, int mods) {
            if (key == GLFW.GLFW_KEY_ESCAPE)
                GLFW.glfwSetWindowShouldClose(window, GL11.GL_TRUE);
            if (key == GLFW.GLFW_KEY_P && action == GLFW.GLFW_PRESS)
                robots[selectedRobot].toggleBouncing();
            if (key == GLFW.GLFW_KEY_H && action == GLFW.GLFW_PRESS)
                robots[selectedRobot].toggleSelected("HEAD");
            if (key == GLFW.GLFW_KEY_N && action == GLFW.GLFW_PRESS)
                robots[selectedRobot].toggleSelected("NECK");
            if (key == GLFW.GLFW_KEY_T && action == GLFW.GLFW_PRESS)
                robots[selectedRobot].toggleSelected("TORSO");
            if (key == GLFW.GLFW_KEY_U && action == GLFW.GLFW_PRESS && mods != GLFW.GLFW_MOD_SHIFT)
                robots[selectedRobot].toggleSelected("UPPER_RIGHT_ARM");
            if (key == GLFW.GLFW_KEY_U && action == GLFW.GLFW_PRESS && mods == GLFW.GLFW_MOD_SHIFT)
                robots[selectedRobot].toggleSelected("UPPER_LEFT_ARM");
            if (key == GLFW.GLFW_KEY_L && action == GLFW.GLFW_PRESS && mods != GLFW.GLFW_MOD_SHIFT)
                robots[selectedRobot].toggleSelected("LOWER_RIGHT_ARM");
            if (key == GLFW.GLFW_KEY_L && action == GLFW.GLFW_PRESS && mods == GLFW.GLFW_MOD_SHIFT)
                robots[selectedRobot].toggleSelected("LOWER_LEFT_ARM");
            if (key == GLFW.GLFW_KEY_G && action == GLFW.GLFW_PRESS && mods != GLFW.GLFW_MOD_SHIFT)
                robots[selectedRobot].toggleSelected("RIGHT_THIGH");
            if (key == GLFW.GLFW_KEY_G && action == GLFW.GLFW_PRESS && mods == GLFW.GLFW_MOD_SHIFT)
                robots[selectedRobot].toggleSelected("LEFT_THIGH");
            if (key == GLFW.GLFW_KEY_C && action == GLFW.GLFW_PRESS && mods != GLFW.GLFW_MOD_SHIFT)
                robots[selectedRobot].toggleSelected("RIGHT_CALF");
            if (key == GLFW.GLFW_KEY_C && action == GLFW.GLFW_PRESS && mods == GLFW.GLFW_MOD_SHIFT)
                robots[selectedRobot].toggleSelected("LEFT_CALF");
            if (key == GLFW.GLFW_KEY_RIGHT && action != GLFW.GLFW_RELEASE)
                robots[selectedRobot].moveRight();
            if (key == GLFW.GLFW_KEY_LEFT && action != GLFW.GLFW_RELEASE)
                robots[selectedRobot].moveLeft();
            if (key == GLFW.GLFW_KEY_1 && action == GLFW.GLFW_PRESS)
                selectedRobot = 0;
            if (key == GLFW.GLFW_KEY_2 && action == GLFW.GLFW_PRESS)
                selectedRobot = 1;
        }
    });
}

From source file:RobotDemo.java

private void loop() {
    GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);

    while (GLFW.glfwWindowShouldClose(window) != GL11.GL_TRUE) {
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        GL11.glPushMatrix();//from   w w  w.  ja v  a2 s  .co m
        for (Robot r : robots)
            r.draw();
        GL11.glPopMatrix();
        GLFW.glfwSwapBuffers(window);
        GLFW.glfwPollEvents();
    }
}

From source file:ch.render.OGLrenderer.java

private void init() {
    //init Gameboy
    gb = new GB();
    gb.loadRom("roms/Big Scroller Demo (PD).gb");
    //gb.loadRom("roms/Pokemon - Red Version (USA, Europe).gb");

    //init GLFW//from   www . j av  a 2 s  . c  o  m
    glfwSetErrorCallback(errorCallback = errorCallbackPrint(System.err));
    if (glfwInit() != GL11.GL_TRUE) {
        throw new IllegalStateException("Unable initialize GLFW");
    }

    //open a window with GLFW
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
    window = glfwCreateWindow(160 * 2, 144 * 2, "R_GB Gameboy Color Emulator", NULL, NULL);
    if (window == NULL) {
        throw new RuntimeException("glfwCreateWindow failed. OpenGL 3.2 supported?");
    }

    glfwSetKeyCallback(window, keyCallback = new GLFWInput().register(gb.comps.joypad)); //hook this

    IntBuffer w = BufferUtils.createIntBuffer(1);
    IntBuffer h = BufferUtils.createIntBuffer(2);
    glfwGetFramebufferSize(window, w, h);
    //System.out.println(w.get());
    //System.out.println(h.get());
    //GLFW settings
    glfwMakeContextCurrent(window);
    GL.createCapabilities();
    //init GLEW
    //lwjgl has no GLEW
    //TODO: output graphics card capabilities
    //openGL settings
    //glEnable(GL_BLEND);
    //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //glDisable(GL_LIGHTING);
    loadShaders();
    loadTexture();
    loadRectangle();

}

From source file:com.adavr.player.Application.java

License:Open Source License

private void init() {
    GLFW.glfwSetErrorCallback(errorCallback = Callbacks.errorCallbackPrint(System.err));

    if (GLFW.glfwInit() != GL11.GL_TRUE) {
        throw new IllegalStateException("Unable to initialize GLFW");
    }/*from   w ww. j a v  a2 s. c om*/

    System.out.println("GLFW:" + GLFW.glfwGetVersionString());

    // We need OpenGL 3.2+
    GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 3);
    GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 2);
    GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE);
    GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);

    if (hmdCtxFactory != null) {
        hmdCtx = hmdCtxFactory.create(appCtx.getSceneRenderContext());
    } else {
        hmdCtx = new DummyHMDRenderContext(appCtx.getSceneRenderContext());
    }

    if (appCtx instanceof HMDStatusListener) {
        hmdCtx.addStatusListener((HMDStatusListener) appCtx);
    }

    final long monitor = hmdCtx.getPreferredMonitor();
    final int width = hmdCtx.getPreferredWidth();
    final int height = hmdCtx.getPreferredHeight();

    window = GLFW.glfwCreateWindow(width, height, "Welcome to the Real World", monitor, MemoryUtil.NULL);
    if (window == MemoryUtil.NULL) {
        throw new RuntimeException("Failed to create the GLFW window");
    }

    mediaCtx = appCtx.getMediaContext();
    if (mediaCtx != null) {
        keyCallback = new MediaPlayerKeyCallback(hmdCtx, mediaCtx);
    } else {
        keyCallback = new HMDKeyCallback(hmdCtx);
    }
    GLFW.glfwSetKeyCallback(window, keyCallback);
    GLFW.glfwMakeContextCurrent(window);
    if (vSync) {
        GLFW.glfwSwapInterval(1);
    }
    GLFW.glfwShowWindow(window);
    GLFW.glfwSetInputMode(window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_NORMAL);
}

From source file:com.adavr.player.DefaultKeyCallback.java

License:Open Source License

@Override
public void invoke(long window, int key, int scancode, int action, int mods) {
    if (key == GLFW.GLFW_KEY_ESCAPE && action == GLFW.GLFW_RELEASE) {
        GLFW.glfwSetWindowShouldClose(window, GL11.GL_TRUE);
    }//from   www.j av a 2 s . co m
}

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

License:Open Source License

@Override
public void setupPointParameters(final float pointSize, final boolean antialiased, final boolean isSprite,
        final boolean useDistanceAttenuation, final FloatBuffer attenuationCoefficients,
        final float minPointSize, final float maxPointSize) {
    final RenderContext context = ContextManager.getCurrentContext();

    // TODO: make a record for point states
    GL11.glPointSize(pointSize);/*from w  w  w. java 2s .c  o m*/

    if (isSprite && context.getCapabilities().isPointSpritesSupported()) {
        GL11.glEnable(ARBPointSprite.GL_POINT_SPRITE_ARB);
        GL11.glTexEnvi(ARBPointSprite.GL_POINT_SPRITE_ARB, ARBPointSprite.GL_COORD_REPLACE_ARB, GL11.GL_TRUE);
    }

    if (useDistanceAttenuation && context.getCapabilities().isPointParametersSupported()) {
        ARBPointParameters.glPointParameterARB(ARBPointParameters.GL_POINT_DISTANCE_ATTENUATION_ARB,
                attenuationCoefficients);
        ARBPointParameters.glPointParameterfARB(ARBPointParameters.GL_POINT_SIZE_MIN_ARB, minPointSize);
        ARBPointParameters.glPointParameterfARB(ARBPointParameters.GL_POINT_SIZE_MAX_ARB, maxPointSize);
    }

    if (antialiased) {
        GL11.glEnable(GL11.GL_POINT_SMOOTH);
        GL11.glHint(GL11.GL_POINT_SMOOTH_HINT, GL11.GL_NICEST);
    }
}

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

License:Open Source License

private static void setTwoSided(final boolean twoSided, final LightStateRecord record) {
    if (!record.isValid() || record.isTwoSidedOn() != twoSided) {
        if (twoSided) {
            GL11.glLightModeli(GL11.GL_LIGHT_MODEL_TWO_SIDE, GL11.GL_TRUE);
        } else {//w w w  .  jav a  2s .com
            GL11.glLightModeli(GL11.GL_LIGHT_MODEL_TWO_SIDE, GL11.GL_FALSE);
        }
        record.setTwoSidedOn(twoSided);
    }
}

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

License:Open Source License

private static void setLocalViewer(final boolean localViewer, final LightStateRecord record) {
    if (!record.isValid() || record.isLocalViewer() != localViewer) {
        if (localViewer) {
            GL11.glLightModeli(GL11.GL_LIGHT_MODEL_LOCAL_VIEWER, GL11.GL_TRUE);
        } else {//  w w w .j a  v a 2s . c  om
            GL11.glLightModeli(GL11.GL_LIGHT_MODEL_LOCAL_VIEWER, GL11.GL_FALSE);
        }
        record.setLocalViewer(localViewer);
    }
}

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

License:Open Source License

/**
 * bind texture and upload image data to card
 *//*from   w w  w . ja  v  a  2  s .  c  o m*/
public static void update(final Texture texture, final int unit) {
    final RenderContext context = ContextManager.getCurrentContext();
    final ContextCapabilities caps = context.getCapabilities();

    texture.getTextureKey().setClean(context.getGlContextRep());

    // our texture type:
    final Texture.Type type = texture.getType();

    // bind our texture id to this unit.
    doTextureBind(texture, unit, false);

    // pass image data to OpenGL
    final Image image = texture.getImage();
    final boolean hasBorder = texture.hasBorder();
    if (image == null) {
        logger.warning("Image data for texture is null.");
    }

    // set alignment to support images with width % 4 != 0, as images are
    // not aligned
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);

    // Get texture image data. Not all textures have image data.
    // For example, ApplyMode.Combine modes can use primary colors,
    // texture output, and constants to modify fragments via the
    // texture units.
    if (image != null) {
        final int maxSize = caps.getMaxTextureSize();
        final int actualWidth = image.getWidth();
        final int actualHeight = image.getHeight();

        final boolean needsPowerOfTwo = !caps.isNonPowerOfTwoTextureSupported()
                && (!MathUtils.isPowerOfTwo(image.getWidth()) || !MathUtils.isPowerOfTwo(image.getHeight()));
        if (actualWidth > maxSize || actualHeight > maxSize || needsPowerOfTwo) {
            if (needsPowerOfTwo) {
                logger.warning(
                        "(card unsupported) Attempted to apply texture with size that is not power of 2: "
                                + image.getWidth() + " x " + image.getHeight());
            }
            if (actualWidth > maxSize || actualHeight > maxSize) {
                logger.warning(
                        "(card unsupported) Attempted to apply texture with size bigger than max texture size ["
                                + maxSize + "]: " + image.getWidth() + " x " + image.getHeight());
            }

            int w = actualWidth;
            if (needsPowerOfTwo) {
                w = MathUtils.nearestPowerOfTwo(actualWidth);
            }
            if (w > maxSize) {
                w = maxSize;
            }

            int h = actualHeight;
            if (needsPowerOfTwo) {
                h = MathUtils.nearestPowerOfTwo(actualHeight);
            }
            if (h > maxSize) {
                h = maxSize;
            }
            logger.warning("Rescaling image to " + w + " x " + h + " !!!");

            // must rescale image to get "top" mipmap texture image
            final int pixFormat = LwjglTextureUtil.getGLPixelFormat(image.getDataFormat());
            final int pixDataType = LwjglTextureUtil.getGLPixelDataType(image.getDataType());
            final int bpp = ImageUtils.getPixelByteSize(image.getDataFormat(), image.getDataType());
            final ByteBuffer scaledImage = BufferUtils.createByteBuffer((w + 4) * h * bpp);
            final int error = MipMap.gluScaleImage(pixFormat, actualWidth, actualHeight, pixDataType,
                    image.getData(0), w, h, pixDataType, scaledImage);
            if (error != 0) {
                Util.checkGLError();
            }

            image.setWidth(w);
            image.setHeight(h);
            image.setData(scaledImage);
        }

        if (!texture.getMinificationFilter().usesMipMapLevels()
                && !texture.getTextureStoreFormat().isCompressed()) {

            // Load textures which do not need mipmap auto-generating and
            // which aren't using compressed images.

            switch (texture.getType()) {
            case TwoDimensional:
                // ensure the buffer is ready for reading
                image.getData(0).rewind();
                // send top level to card
                GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0,
                        LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), image.getWidth(),
                        image.getHeight(), hasBorder ? 1 : 0,
                        LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                        LwjglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0));
                break;
            case OneDimensional:
                // ensure the buffer is ready for reading
                image.getData(0).rewind();
                // send top level to card
                GL11.glTexImage1D(GL11.GL_TEXTURE_1D, 0,
                        LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()), image.getWidth(),
                        hasBorder ? 1 : 0, LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                        LwjglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0));
                break;
            case ThreeDimensional:
                if (caps.isTexture3DSupported()) {
                    // concat data into single buffer:
                    int dSize = 0;
                    int count = 0;
                    ByteBuffer data = null;
                    for (int x = 0; x < image.getData().size(); x++) {
                        if (image.getData(x) != null) {
                            data = image.getData(x);
                            dSize += data.limit();
                            count++;
                        }
                    }
                    // reuse buffer if we can.
                    if (count != 1) {
                        data = BufferUtils.createByteBuffer(dSize);
                        for (int x = 0; x < image.getData().size(); x++) {
                            if (image.getData(x) != null) {
                                data.put(image.getData(x));
                            }
                        }
                        // ensure the buffer is ready for reading
                        data.flip();
                    }
                    // send top level to card
                    GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0,
                            LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                            image.getWidth(), image.getHeight(), image.getDepth(), hasBorder ? 1 : 0,
                            LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                            LwjglTextureUtil.getGLPixelDataType(image.getDataType()), data);
                } else {
                    logger.warning("This card does not support Texture3D.");
                }
                break;
            case CubeMap:
                // NOTE: Cubemaps MUST be square, so height is ignored
                // on purpose.
                if (caps.isTextureCubeMapSupported()) {
                    for (final TextureCubeMap.Face face : TextureCubeMap.Face.values()) {
                        // ensure the buffer is ready for reading
                        image.getData(face.ordinal()).rewind();
                        // send top level to card
                        GL11.glTexImage2D(getGLCubeMapFace(face), 0,
                                LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                image.getWidth(), image.getWidth(), hasBorder ? 1 : 0,
                                LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                                LwjglTextureUtil.getGLPixelDataType(image.getDataType()),
                                image.getData(face.ordinal()));
                    }
                } else {
                    logger.warning("This card does not support Cubemaps.");
                }
                break;
            }
        } else if (texture.getMinificationFilter().usesMipMapLevels() && !image.hasMipmaps()
                && !texture.getTextureStoreFormat().isCompressed()) {

            // For textures which need mipmaps auto-generating and which
            // aren't using compressed images, generate the mipmaps.
            // A new mipmap builder may be needed to build mipmaps for
            // compressed textures.

            if (caps.isAutomaticMipmapsSupported()) {
                // Flag the card to generate mipmaps
                GL11.glTexParameteri(getGLType(type), SGISGenerateMipmap.GL_GENERATE_MIPMAP_SGIS, GL11.GL_TRUE);
            }

            switch (type) {
            case TwoDimensional:
                // ensure the buffer is ready for reading
                image.getData(0).rewind();
                if (caps.isAutomaticMipmapsSupported()) {
                    // send top level to card
                    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0,
                            LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                            image.getWidth(), image.getHeight(), hasBorder ? 1 : 0,
                            LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                            LwjglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0));
                } else {
                    // send to card
                    GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D,
                            LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                            image.getWidth(), image.getHeight(),
                            LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                            LwjglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0));
                }
                break;
            case OneDimensional:
                // ensure the buffer is ready for reading
                image.getData(0).rewind();
                if (caps.isAutomaticMipmapsSupported()) {
                    // send top level to card
                    GL11.glTexImage1D(GL11.GL_TEXTURE_1D, 0,
                            LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                            image.getWidth(), hasBorder ? 1 : 0,
                            LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                            LwjglTextureUtil.getGLPixelDataType(image.getDataType()), image.getData(0));
                } else {
                    // Note: LWJGL's GLU class does not support
                    // gluBuild1DMipmaps.
                    logger.warning(
                            "non-fbo 1d mipmap generation is not currently supported.  Use DDS or a non-mipmap minification filter.");
                    return;
                }
                break;
            case ThreeDimensional:
                if (caps.isTexture3DSupported()) {
                    if (caps.isAutomaticMipmapsSupported()) {
                        // concat data into single buffer:
                        int dSize = 0;
                        int count = 0;
                        ByteBuffer data = null;
                        for (int x = 0; x < image.getData().size(); x++) {
                            if (image.getData(x) != null) {
                                data = image.getData(x);
                                dSize += data.limit();
                                count++;
                            }
                        }
                        // reuse buffer if we can.
                        if (count != 1) {
                            data = BufferUtils.createByteBuffer(dSize);
                            for (int x = 0; x < image.getData().size(); x++) {
                                if (image.getData(x) != null) {
                                    data.put(image.getData(x));
                                }
                            }
                            // ensure the buffer is ready for reading
                            data.flip();
                        }
                        // send top level to card
                        GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0,
                                LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                image.getWidth(), image.getHeight(), image.getDepth(), hasBorder ? 1 : 0,
                                LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                                LwjglTextureUtil.getGLPixelDataType(image.getDataType()), data);
                    } else {
                        // Note: LWJGL's GLU class does not support
                        // gluBuild3DMipmaps.
                        logger.warning(
                                "non-fbo 3d mipmap generation is not currently supported.  Use DDS or a non-mipmap minification filter.");
                        return;
                    }
                } else {
                    logger.warning("This card does not support Texture3D.");
                    return;
                }
                break;
            case CubeMap:
                // NOTE: Cubemaps MUST be square, so height is ignored
                // on purpose.
                if (caps.isTextureCubeMapSupported()) {
                    if (caps.isAutomaticMipmapsSupported()) {
                        for (final TextureCubeMap.Face face : TextureCubeMap.Face.values()) {
                            // ensure the buffer is ready for reading
                            image.getData(face.ordinal()).rewind();
                            // send top level to card
                            GL11.glTexImage2D(getGLCubeMapFace(face), 0,
                                    LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                    image.getWidth(), image.getWidth(), hasBorder ? 1 : 0,
                                    LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                                    LwjglTextureUtil.getGLPixelDataType(image.getDataType()),
                                    image.getData(face.ordinal()));
                        }
                    } else {
                        for (final TextureCubeMap.Face face : TextureCubeMap.Face.values()) {
                            // ensure the buffer is ready for reading
                            image.getData(face.ordinal()).rewind();
                            // send to card
                            GLU.gluBuild2DMipmaps(getGLCubeMapFace(face),
                                    LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                    image.getWidth(), image.getWidth(),
                                    LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                                    LwjglTextureUtil.getGLPixelDataType(image.getDataType()),
                                    image.getData(face.ordinal()));
                        }
                    }
                } else {
                    logger.warning("This card does not support Cubemaps.");
                    return;
                }
                break;
            }

            if (texture.getTextureMaxLevel() >= 0) {
                GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL,
                        texture.getTextureMaxLevel());
            }
        } else {
            // Here we handle textures that are either compressed or have predefined mipmaps.
            // Get mipmap data sizes and amount of mipmaps to send to opengl. Then loop through all mipmaps and send
            // them.
            int[] mipSizes = image.getMipMapByteSizes();
            ByteBuffer data = null;

            if (type == Type.CubeMap) {
                if (caps.isTextureCubeMapSupported()) {
                    for (final TextureCubeMap.Face face : TextureCubeMap.Face.values()) {
                        data = image.getData(face.ordinal());
                        int pos = 0;
                        int max = 1;

                        if (mipSizes == null) {
                            mipSizes = new int[] { data.capacity() };
                        } else if (texture.getMinificationFilter().usesMipMapLevels()) {
                            max = mipSizes.length;
                        }

                        // set max mip level
                        GL11.glTexParameteri(getGLCubeMapFace(face), GL12.GL_TEXTURE_MAX_LEVEL, max - 1);

                        for (int m = 0; m < max; m++) {
                            final int width = Math.max(1, image.getWidth() >> m);
                            final int height = Math.max(1, image.getHeight() >> m);

                            data.position(pos);
                            data.limit(pos + mipSizes[m]);

                            if (texture.getTextureStoreFormat().isCompressed()) {
                                ARBTextureCompression.glCompressedTexImage2DARB(getGLCubeMapFace(face), m,
                                        LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                        width, height, hasBorder ? 1 : 0, data);
                            } else {
                                GL11.glTexImage2D(getGLCubeMapFace(face), m,
                                        LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                        width, height, hasBorder ? 1 : 0,
                                        LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                                        LwjglTextureUtil.getGLPixelDataType(image.getDataType()), data);
                            }
                            pos += mipSizes[m];
                        }
                    }
                } else {
                    logger.warning("This card does not support CubeMaps.");
                    return;
                }
            } else {
                data = image.getData(0);
                int pos = 0;
                int max = 1;

                if (mipSizes == null) {
                    mipSizes = new int[] { data.capacity() };
                } else if (texture.getMinificationFilter().usesMipMapLevels()) {
                    max = mipSizes.length;
                }

                // Set max mip level
                switch (type) {
                case TwoDimensional:
                    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, max - 1);
                    break;
                case ThreeDimensional:
                    GL11.glTexParameteri(GL12.GL_TEXTURE_3D, GL12.GL_TEXTURE_MAX_LEVEL, max - 1);
                    break;
                case OneDimensional:
                    GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL12.GL_TEXTURE_MAX_LEVEL, max - 1);
                    break;
                }

                if (type == Type.ThreeDimensional) {
                    if (caps.isTexture3DSupported()) {
                        // concat data into single buffer:
                        int dSize = 0;
                        int count = 0;
                        for (int x = 0; x < image.getData().size(); x++) {
                            if (image.getData(x) != null) {
                                data = image.getData(x);
                                dSize += data.limit();
                                count++;
                            }
                        }
                        // reuse buffer if we can.
                        if (count != 1) {
                            data = BufferUtils.createByteBuffer(dSize);
                            for (int x = 0; x < image.getData().size(); x++) {
                                if (image.getData(x) != null) {
                                    data.put(image.getData(x));
                                }
                            }
                            // ensure the buffer is ready for reading
                            data.flip();
                        }
                    } else {
                        logger.warning("This card does not support Texture3D.");
                        return;
                    }
                }

                for (int m = 0; m < max; m++) {
                    final int width = Math.max(1, image.getWidth() >> m);
                    final int height = Math.max(1, image.getHeight() >> m);

                    data.position(pos);
                    data.limit(pos + mipSizes[m]);

                    switch (type) {
                    case TwoDimensional:
                        if (texture.getTextureStoreFormat().isCompressed()) {
                            ARBTextureCompression.glCompressedTexImage2DARB(GL11.GL_TEXTURE_2D, m,
                                    LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                    width, height, hasBorder ? 1 : 0, data);
                        } else {
                            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, m,
                                    LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                    width, height, hasBorder ? 1 : 0,
                                    LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                                    LwjglTextureUtil.getGLPixelDataType(image.getDataType()), data);
                        }
                        break;
                    case OneDimensional:
                        if (texture.getTextureStoreFormat().isCompressed()) {
                            ARBTextureCompression.glCompressedTexImage1DARB(GL11.GL_TEXTURE_1D, m,
                                    LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                    width, hasBorder ? 1 : 0, data);
                        } else {
                            GL11.glTexImage1D(GL11.GL_TEXTURE_1D, m,
                                    LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                    width, hasBorder ? 1 : 0,
                                    LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                                    LwjglTextureUtil.getGLPixelDataType(image.getDataType()), data);
                        }
                        break;
                    case ThreeDimensional:
                        final int depth = Math.max(1, image.getDepth() >> m);
                        // already checked for support above...
                        if (texture.getTextureStoreFormat().isCompressed()) {
                            ARBTextureCompression.glCompressedTexImage3DARB(GL12.GL_TEXTURE_3D, m,
                                    LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                    width, height, depth, hasBorder ? 1 : 0, data);
                        } else {
                            GL12.glTexImage3D(GL12.GL_TEXTURE_3D, m,
                                    LwjglTextureUtil.getGLInternalFormat(texture.getTextureStoreFormat()),
                                    width, height, depth, hasBorder ? 1 : 0,
                                    LwjglTextureUtil.getGLPixelFormat(image.getDataFormat()),
                                    LwjglTextureUtil.getGLPixelDataType(image.getDataType()), data);
                        }
                        break;
                    }
                    pos += mipSizes[m];
                }
            }
            if (data != null) {
                data.clear();
            }
        }
    }
}