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:fr.def.iss.vd2.lib_v3d.element.V3DSprite.java

License:Open Source License

@Override
protected void doDisplay(V3DCamera camera) {

    if (!enableColor) {
        GL11.glPushAttrib(GL11.GL_CURRENT_BIT);
        GL11.glColor4f(1, 1, 1, opacity);
    }/*from   w w  w.  j a v  a  2s  .  c  o m*/

    GL11.glEnable(GL11.GL_TEXTURE_2D);

    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);

    GL11.glAlphaFunc(GL11.GL_GREATER, 0.1f);
    GL11.glEnable(GL11.GL_ALPHA_TEST);

    if (disableRotation) {
        camera.disableRotation();
    }

    float w = 0.5f * size.x * image.getWidth();
    float h = 0.5f * size.y * image.getHeight();

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getID());
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0.0f, 0.0f);
    GL11.glVertex3f(-w, -h, 0.0f);
    GL11.glTexCoord2f(1.0f, 0.0f);
    GL11.glVertex3f(w, -h, 0.0f);
    GL11.glTexCoord2f(1.0f, 1.0f);
    GL11.glVertex3f(w, h, 0.0f);
    GL11.glTexCoord2f(0.0f, 1.0f);
    GL11.glVertex3f(-w, h, 0.0f);
    GL11.glEnd();

    if (disableRotation) {
        camera.enableRotation();
    }

    GL11.glDisable(GL11.GL_ALPHA_TEST);
    GL11.glDisable(GL11.GL_TEXTURE_2D);

    if (!enableColor) {
        GL11.glPopAttrib();
    }
}

From source file:fr.guillaume.prive.viper.core.graphic.GraphicMotor.java

public static void draw() {
    GraphicMotor.checkInstance();//w  w  w .  j a v a 2  s . c o m

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL20.glUseProgram(instance.shipShaderId);

    GL20.glUniform1i(instance.useTextureLocation, instance.drawPolygonFrame ? 0 : 1);
    int drawStyle = instance.drawPolygonFrame ? GL11.GL_LINE_LOOP : GL11.GL_TRIANGLES;

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, instance.shipTextureId);
    GL30.glBindVertexArray(instance.shipVaoId);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);
    GL20.glEnableVertexAttribArray(3);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, instance.shipVboiId);
    GL11.glDrawElements(drawStyle, instance.shipVboiLenght, GL11.GL_UNSIGNED_INT, 0);

    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL20.glDisableVertexAttribArray(3);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);
    GL20.glUseProgram(0);
}

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.primitive.DensityFieldPrimitiveRenderer.java

License:Open Source License

/**
 * Rendering of polygons/*  w  ww  .  j a  va 2  s .c  o  m*/
 * 
 * @param viewport
 * @param polygon
 */
private void renderSurface(Viewport viewport, ParameterizedPolygon polygon, Integer texIndex) {
    boolean texCoord = polygon.hasTextureCoordinates() && texIndex != null;
    //        System.err.println("pol " + polygon.hashCode() + " " + polygon.hasTextureCoordinates() + " " + texIndex);
    if (texCoord) {
        GL11.glColor4f(1.f, 1.f, 1.f, 1.f);
        GL11.glEnable(GL_TEXTURE_2D);
        GL11.glBindTexture(GL_TEXTURE_2D, texIndex);
    } else {
        GLTools.glColor(GLTools.glRandomColor());
        GL11.glDisable(GL_TEXTURE_2D);
    }
    // tesselation
    GLUtessellator tesselator = gluNewTess();
    // Set callback functions
    TessCallback callback = new TessCallback();
    tesselator.gluTessCallback(GLU_TESS_VERTEX, callback);
    tesselator.gluTessCallback(GLU_TESS_BEGIN, callback);
    tesselator.gluTessCallback(GLU_TESS_END, callback);
    tesselator.gluTessCallback(GLU_TESS_COMBINE, callback);
    tesselator.gluTessProperty(GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_POSITIVE);

    //        System.err.println("DensityFieldPrimitiveRenderer : outer frontier points count = " + polygon.getOuterFrontier().size());
    tesselator.gluTessBeginPolygon(null);
    // outer frontier
    tesselator.gluTessBeginContour();
    for (int outerFrontierPointIndex = 0; outerFrontierPointIndex < polygon.getOuterFrontier()
            .size(); outerFrontierPointIndex++) {
        Point2d outerFrontierPoint = polygon.getOuterFrontier().get(outerFrontierPointIndex); // screen coordinates

        // point coordinates
        double coords[] = new double[6];
        coords[0] = outerFrontierPoint.x;
        coords[1] = outerFrontierPoint.y;
        coords[2] = 0;
        // use internal texture coordinates
        if (texCoord) {
            Point2d outerFrontierTextureCoordinates = polygon
                    .getOuterFrontierTextureCoordinates(outerFrontierPointIndex);
            coords[3] = outerFrontierTextureCoordinates.x;
            coords[4] = outerFrontierTextureCoordinates.y;
            coords[5] = 0;
        } else {
            coords[3] = 0;
            coords[4] = 0;
            coords[5] = 0;

        }
        //            System.err.println("------------------------------------------------ " + outerFrontierTextureCoordinates);
        tesselator.gluTessVertex(coords, 0, coords);
    }
    tesselator.gluTessEndContour();

    for (int innerFrontierIndex = 0; innerFrontierIndex < polygon
            .getInnerFrontierCount(); innerFrontierIndex++) {

        List<Point2d> innerFrontier = polygon.getInnerFrontier(innerFrontierIndex);
        tesselator.gluTessBeginContour();

        for (int innerFrontierPointIndex = 0; innerFrontierPointIndex < innerFrontier
                .size(); innerFrontierPointIndex++) {
            Point2d innerFrontierPoint = innerFrontier.get(innerFrontierPointIndex);

            double[] coords = new double[6];
            // point coordinates
            coords[0] = innerFrontierPoint.x;
            coords[1] = innerFrontierPoint.y;
            coords[2] = 0;
            // use internal texture coordinates
            if (texCoord) {
                Point2d innerFrontierTextureCoordinates = polygon
                        .getInnerFrontierTextureCoordinates(innerFrontierIndex, innerFrontierPointIndex);
                coords[3] = innerFrontierTextureCoordinates.x;
                coords[4] = innerFrontierTextureCoordinates.y;
                coords[5] = 0;
            } else {
                coords[3] = 0;
                coords[4] = 0;
                coords[5] = 0;

            }
            //                System.err.println(innerFrontierPoint.x + ";" + innerFrontierTextureCoordinates.x + ";;" + innerFrontierPoint
            //                        + innerFrontierTextureCoordinates.y);
            //        coords[3] = texCoord ? innerFrontierTextureCoordinates.x / 1000. : innerFrontierPoint.x;
            //        coords[4] = texCoord ? innerFrontierTextureCoordinates.y / 1000. : innerFrontierPoint.y;
            coords[5] = 0;
            tesselator.gluTessVertex(coords, 0, coords);
        }

        tesselator.gluTessEndContour();
    }

    tesselator.gluTessEndPolygon();

}

From source file:fr.theshark34.sharkengine.ui.components.Checkbox.java

License:Apache License

/**
 * Draw the checkbox/*from w  w w .j a va  2  s  . co  m*/
 */
public void draw() {
    // Enabling blending
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    // Being sure that texturing is disabled
    GL11.glDisable(GL11.GL_TEXTURE_2D);

    // Picking white color
    GL11.glColor3f(1.0F, 1.0F, 1.0F);

    // Drawing the checkbox
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glVertex2f(x, y);
        GL11.glVertex2f(x + width, y);
        GL11.glVertex2f(x + width, y + height);
        GL11.glVertex2f(x, y + height);
    }
    GL11.glEnd();

    // Drawing the text
    this.font.drawString(x + 25, y + (this.height - this.font.getHeight(text)) / 2, text);

    // Being sure that texturing is enabled
    GL11.glEnable(GL11.GL_TEXTURE_2D);

    // If the mouse is on the checkbox
    if (Mouse.getX() > this.x && Mouse.getX() < this.x + this.width
            && Mouse.getY() < Display.getHeight() - this.y
            && Mouse.getY() > Display.getHeight() - this.y - this.height)
        // If the mouse clicked and clicked is false, setting coched
        // to its oposite and setting clicked to true, so it will do
        // it one time
        if (Mouse.isButtonDown(0)) {
            if (!clicked) {
                clicked = true;
                coched = !coched;
            }
        } else
            // If mouse isn't on it, setting clicked to false
            clicked = false;

    // Checking if the checkbox is coched
    if (coched) {
        // Drawing coched checkbox texture
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, cochedcb.getTextureID());

        // Drawing the image
        GL11.glBegin(GL11.GL_QUADS);
        {
            GL11.glTexCoord2f(0.0f, 0.0f);
            GL11.glVertex2f(x, y);
            GL11.glTexCoord2f(1.0f, 0.0f);
            GL11.glVertex2f(x + width, y);
            GL11.glTexCoord2f(1.0f, 1.0f);
            GL11.glVertex2f(x + width, y + height);
            GL11.glTexCoord2f(0.0f, 1.0f);
            GL11.glVertex2f(x, y + height);
        }
        GL11.glEnd();
    }

    // Disabling texture
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    // Disabling blending
    GL11.glDisable(GL11.GL_BLEND);
}

From source file:fr.theshark34.sharkengine.ui.components.Image.java

License:Apache License

/**
 * Draw it//  ww  w  .j  a va 2 s  .c  om
 */
@Override
public void draw() {
    // Without this, image can render strangely
    GL11.glColor3f(1.0F, 1.0F, 1.0F);

    // Enabling blend and texture
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID());

    // Drawing the image
    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glTexCoord2f(0.0f, 0.0f);
        GL11.glVertex2f(x, y);
        GL11.glTexCoord2f(1.0f, 0.0f);
        GL11.glVertex2f(x + width, y);
        GL11.glTexCoord2f(1.0f, 1.0f);
        GL11.glVertex2f(x + width, y + height);
        GL11.glTexCoord2f(0.0f, 1.0f);
        GL11.glVertex2f(x, y + height);
    }
    GL11.glEnd();

    // Disabling blend and texture
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
}

From source file:game.engine.gfx.Texture.java

License:Open Source License

/**
 * Calls glBindTexture() on this texture.
 */
public void glBindTexture() {
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, slickTexture.getTextureID());
}

From source file:game.entity.lwjgl.EntityRenderer.java

private void prepareTexturedModel(TexturedModel model) {
    RawModel rawModel = model.getRawModel();
    if (rawModel.doesContainInvertedNormals()) {
        GL11.glDisable(GL11.GL_CULL_FACE);
    }/*w  ww  .  j  a va2 s  . c o  m*/
    GL30.glBindVertexArray(rawModel.getVaoID());
    GL20.glEnableVertexAttribArray(VERTEX_POSITIONS);
    GL20.glEnableVertexAttribArray(TEXTURE_COORDS);
    GL20.glEnableVertexAttribArray(NORMAL_VECTORS);
    this.loadUniformFloat("shineDamper", model.getModelTexture().getShineDamper());
    this.loadUniformFloat("reflectivity", model.getModelTexture().getReflectivity());
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, model.getModelTexture().getTextureID());

}

From source file:game.skybox.lwjgl.SkyboxRenderer.java

public void render() {
    GL30.glBindVertexArray(cube.getVaoID());
    GL20.glEnableVertexAttribArray(0);/*from ww  w . j  a v a 2  s . co m*/
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texture);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, cube.getVertexCount());
    GL20.glDisableVertexAttribArray(0);
    GL30.glBindVertexArray(0);
}

From source file:game.terrain.lwjgl.TerrainRenderer.java

/**
 *
 * @param terrain//from   w w  w .j  av  a  2s  . c  o  m
 */
private void bindTextures(Terrain terrain) {
    TerrainTexturePack texturePack = terrain.getTexturePack();
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texturePack.getBackgroundTexture().getTextureID());
    GL13.glActiveTexture(GL13.GL_TEXTURE1);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texturePack.getrTexture().getTextureID());
    GL13.glActiveTexture(GL13.GL_TEXTURE2);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texturePack.getgTexture().getTextureID());
    GL13.glActiveTexture(GL13.GL_TEXTURE3);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texturePack.getbTexture().getTextureID());
    GL13.glActiveTexture(GL13.GL_TEXTURE4);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, terrain.getBlendMap().getTextureID());
}