Example usage for org.lwjgl.opengl GL11 glBindTexture

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

Introduction

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

Prototype

public static void glBindTexture(@NativeType("GLenum") int target, @NativeType("GLuint") int texture) 

Source Link

Document

Binds the a texture to a texture target.

Usage

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

License:Apache License

public static void glBindTexture(int target, int texture) {
    GL11.glBindTexture(target, texture);
}

From source file:ion2d.INTexture2D.java

License:Open Source License

/**
 * Binds the texture to the current OpenGL Context
 */
public void bind() {
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.id);
}

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

License:Open Source License

/**
 * Draw a curve to the screen that's tinted with `color`. The first time
 * this is called this caches the image result of the curve and on subsequent
 * runs it just draws the cached copy to the screen.
 * @param color tint of the curve/*from   w  w  w. j  a va 2  s . c  o  m*/
 * @param borderColor the curve border color
 * @param curve the points along the curve to be drawn
 */
public void draw(Color color, Color borderColor, Vec2f[] curve) {
    float alpha = color.a;

    // if this curve hasn't been drawn, draw it and cache the result
    if (fbo == null) {
        FrameBufferCache cache = FrameBufferCache.getInstance();
        Rendertarget mapping = cache.get(hitObject);
        if (mapping == null)
            mapping = cache.insert(hitObject);
        fbo = mapping;

        int oldFb = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
        int oldTex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);

        //glGetInteger requires a buffer of size 16, even though just 4
        //values are returned in this specific case
        IntBuffer oldViewport = BufferUtils.createIntBuffer(16);
        GL11.glGetInteger(GL11.GL_VIEWPORT, oldViewport);
        EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbo.getID());
        GL11.glViewport(0, 0, fbo.width, fbo.height);
        GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        Colors.WHITE_FADE.a = 1.0f;
        this.draw_curve(color, borderColor, curve);
        color.a = 1f;

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, oldTex);
        EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, oldFb);
        GL11.glViewport(oldViewport.get(0), oldViewport.get(1), oldViewport.get(2), oldViewport.get(3));
        Colors.WHITE_FADE.a = alpha;
    }

    // draw a fullscreen quad with the texture that contains the curve
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_TEXTURE_1D);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.getTextureID());
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glColor4f(1.0f, 1.0f, 1.0f, alpha);
    GL11.glTexCoord2f(1.0f, 1.0f);
    GL11.glVertex2i(fbo.width, 0);
    GL11.glTexCoord2f(0.0f, 1.0f);
    GL11.glVertex2i(0, 0);
    GL11.glTexCoord2f(0.0f, 0.0f);
    GL11.glVertex2i(0, fbo.height);
    GL11.glTexCoord2f(1.0f, 0.0f);
    GL11.glVertex2i(fbo.width, fbo.height);
    GL11.glEnd();
}

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

License:Open Source License

/**
 * Backup the current state of the relevant OpenGL state and change it to
 * what's needed to draw the curve./*from  w  w  w  . java2s.  com*/
 */
private RenderState startRender() {
    RenderState state = new RenderState();
    state.smoothedPoly = GL11.glGetBoolean(GL11.GL_POLYGON_SMOOTH);
    state.blendEnabled = GL11.glGetBoolean(GL11.GL_BLEND);
    state.depthEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_TEST);
    state.depthWriteEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_WRITEMASK);
    state.texEnabled = GL11.glGetBoolean(GL11.GL_TEXTURE_2D);
    state.texUnit = GL11.glGetInteger(GL13.GL_ACTIVE_TEXTURE);
    state.oldProgram = GL11.glGetInteger(GL20.GL_CURRENT_PROGRAM);
    state.oldArrayBuffer = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING);
    GL11.glDisable(GL11.GL_POLYGON_SMOOTH);
    GL11.glEnable(GL11.GL_BLEND);
    GL14.glBlendEquation(GL14.GL_FUNC_ADD);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthMask(true);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_TEXTURE_1D);
    GL11.glBindTexture(GL11.GL_TEXTURE_1D, staticState.gradientTexture);
    GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);

    GL20.glUseProgram(0);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();

    return state;
}

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

License:Open Source License

/**
 * Creates a Rendertarget with a Texture that it renders the color buffer in
 * and a renderbuffer that it renders the depth to.
 * @param width the width//from  ww w. j  av  a  2  s  .  c om
 * @param height the height
*/
public static Rendertarget createRTTFramebuffer(int width, int height) {
    int old_framebuffer = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
    int old_texture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
    Rendertarget buffer = new Rendertarget(width, height);
    buffer.bind();

    int fboTexture = buffer.textureID;
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, fboTexture);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, 4, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_INT,
            (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);

    EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, buffer.depthBufferID);
    EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT,
            GL11.GL_DEPTH_COMPONENT, width, height);
    EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
            EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT,
            buffer.depthBufferID);

    EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
            EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, fboTexture, 0);

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, old_texture);
    EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, old_framebuffer);

    return buffer;
}

From source file:itemrender.client.rendering.FBOHelper.java

License:MIT License

private void createFramebuffer() {
    framebufferID = EXTFramebufferObject.glGenFramebuffersEXT();
    textureID = GL11.glGenTextures();//from   w  w w .j  a va2 s  .c  om
    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);

    // 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>
 *//* ww w.  ja va  2s  .  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  w ww .j ava  2 s.c  om
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:jake2.desktop.LWJGLAdapter.java

License:Open Source License

@Override
public void glBindTexture(int target, int texture) {
    GL11.glBindTexture(target, texture);
}

From source file:jpcsp.graphics.RE.RenderingEngineLwjgl.java

License:Open Source License

@Override
public void bindTexture(int texture) {
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
}