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:junkdisplay.JunkDisplayLWJGL.java

private void drawBackground(Point locs) {
    if (LEVEL_EDITOR == false) {
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, levelmap.getSheetID());
        drawTile(e.GAME_BACKGROUND_RECT, levelmap.getSpriteLocation(e.GAME_BACKGROUND));

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, levelmap.getSheetID());
        drawTile(e.GAME_FOREGROUND_RECT, levelmap.getSpriteLocation(e.GAME_FOREGROUND));
    } else {// w ww  .  j  a v  a  2s  .co  m
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, levelmap.getSheetID());
        drawTile(edit.GAME_BACKGROUND_RECT, levelmap.getSpriteLocation(edit.GAME_BACKGROUND));

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, levelmap.getSheetID());
        drawTile(edit.GAME_FOREGROUND_RECT, levelmap.getSpriteLocation(edit.GAME_FOREGROUND));
    }
}

From source file:junkdisplay.JunkDisplayLWJGL.java

private void drawForeGround() {
    String r;/* w  ww. j a v a  2  s.com*/
    Rectangle bounds;
    ArrayList<Scenery> sceneries;
    if (LEVEL_EDITOR == false) {
        sceneries = e.getSceneries();
    } else {
        sceneries = edit.getSceneries();
    }
    for (DefaultCharacter scenery : sceneries) {
        if (scenery.getEditor() == false) {
            r = scenery.getTexture();
            bounds = scenery.getScreenPosition();
            if (scenery instanceof HealingScenery) {
                GL11.glBindTexture(GL11.GL_TEXTURE_2D, healingmap.getSheetID());

                drawTile(bounds, healingmap.getSpriteLocation(r));
            } else if (scenery instanceof PermeableScenery) {
                GL11.glBindTexture(GL11.GL_TEXTURE_2D, interactivemap.getSheetID());

                drawTile(bounds, interactivemap.getSpriteLocation(r));
            } else if (scenery instanceof Decoration) {
                GL11.glBindTexture(GL11.GL_TEXTURE_2D, decorationmap.getSheetID());

                drawTile(bounds, decorationmap.getSpriteLocation(r));
            } else {
                GL11.glBindTexture(GL11.GL_TEXTURE_2D, newscenerymap.getSheetID());

                drawTile(bounds, newscenerymap.getSpriteLocation(r));
            }
        }
    }
    if (!LEVEL_EDITOR) {
        ArrayList<MovingCharacter> characters = e.getCharacters();
        for (DefaultCharacter character : characters) {
            r = character.getTexture();
            bounds = character.getScreenPosition();
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, charactermap.getSheetID());

            drawTile(bounds, charactermap.getSpriteLocation(r));
        }
    }
    ArrayList<Threat> threats;
    if (LEVEL_EDITOR == false) {
        threats = e.getThreats();
    } else {
        threats = edit.getThreats();
    }

    for (DefaultCharacter threat : threats) {
        if (threat.getEditor() == false) {
            r = threat.getTexture();
            bounds = threat.getScreenPosition();
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, threatmap.getSheetID());

            drawTile(bounds, threatmap.getSpriteLocation(r));
        }
    }
}

From source file:junkdisplay.JunkDisplayLWJGL.java

private void drawShadow(Point locs) {
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, levelmap.getSheetID());
    if (LEVEL_EDITOR == false) {
        drawTile(e.GAME_SHADOW_RECT, levelmap.getSpriteLocation(e.GAME_SHADOW));
    } else {/*from  w  ww .j  a  v a 2s  .  co m*/
        drawTile(edit.GAME_SHADOW_RECT, levelmap.getSpriteLocation(edit.GAME_SHADOW));
    }
}

From source file:junkdisplay.JunkDisplayLWJGL.java

private void drawUI() {
    if (!LEVEL_EDITOR) {
        int health = e.getPlayerHealth();
        String texture, firstNumberTexture, secondNumberTexture;
        if (health == 1000) {
            texture = "100";
        } else if (health >= 900) {
            texture = "90";
        } else if (health >= 800) {
            texture = "80";
        } else if (health >= 700) {
            texture = "70";
        } else if (health >= 600) {
            texture = "60";
        } else if (health >= 500) {
            texture = "50";
        } else if (health >= 400) {
            texture = "40";
        } else if (health >= 300) {
            texture = "30";
        } else if (health >= 200) {
            texture = "20";
        } else if (health >= 100) {
            texture = "10";
        } else {/*from  w w w  .  ja va  2s . com*/
            texture = "0";
        }
        if (health > 100) {
            Rectangle bounds = new Rectangle(10, 10, 64, 64);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, healthmap.getSheetID());
            drawTile(bounds, healthmap.getSpriteLocation(texture));
        }
        Rectangle bounds2 = new Rectangle(10, 10, 64, 64);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, healthmap.getSheetID());
        drawTile(bounds2, healthmap.getSpriteLocation("porthole"));

        int healthTens = (health / 100) % 100;
        switch (healthTens) {
        case 1:
            firstNumberTexture = "1";
            break;
        case 2:
            firstNumberTexture = "2";
            break;
        case 3:
            firstNumberTexture = "3";
            break;
        case 4:
            firstNumberTexture = "4";
            break;
        case 5:
            firstNumberTexture = "5";
            break;
        case 6:
            firstNumberTexture = "6";
            break;
        case 7:
            firstNumberTexture = "7";
            break;
        case 8:
            firstNumberTexture = "8";
            break;
        case 9:
            firstNumberTexture = "9";
            break;
        case 0:
            firstNumberTexture = "0";
            break;
        default:
            if (health == 1000) {
                firstNumberTexture = "0";
            } else {
                firstNumberTexture = "blank";
            }
            break;
        }
        int healthOnes = (health % 100) / 10;
        switch (healthOnes) {
        case 1:
            secondNumberTexture = "1";
            break;
        case 2:
            secondNumberTexture = "2";
            break;
        case 3:
            secondNumberTexture = "3";
            break;
        case 4:
            secondNumberTexture = "4";
            break;
        case 5:
            secondNumberTexture = "5";
            break;
        case 6:
            secondNumberTexture = "6";
            break;
        case 7:
            secondNumberTexture = "7";
            break;
        case 8:
            secondNumberTexture = "8";
            break;
        case 9:
            secondNumberTexture = "9";
            break;
        case 0:
            secondNumberTexture = "0";
            break;
        default:
            secondNumberTexture = "0";

        }
        if (health != 1000) {
            Rectangle num1 = new Rectangle(29, 28, 13, 26);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, numbermap.getSheetID());
            drawTile(num1, numbermap.getSpriteLocation(firstNumberTexture));

            Rectangle num2 = new Rectangle(42, 28, 13, 26);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, numbermap.getSheetID());
            drawTile(num2, numbermap.getSpriteLocation(secondNumberTexture));
        }

        int temper = e.getPlayerTemperature();
        String textemp;
        if (temper >= 800) {
            textemp = "temp90";
        } else if (temper >= 700) {
            textemp = "temp80";
        } else if (temper >= 600) {
            textemp = "temp70";
        } else if (temper >= 500) {
            textemp = "temp60";
        } else if (temper >= 400) {
            textemp = "temp50";
        } else if (temper >= 350) {
            textemp = "temp40";
        } else if (temper >= 300) {
            textemp = "temp30";
        } else if (temper >= 200) {
            textemp = "temp20";
        } else if (temper >= 0) {
            textemp = "temp10";
        } else {
            textemp = "temp10";
        }

        Rectangle temperature = new Rectangle(16, 88, 23, 74);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, temperaturemap.getSheetID());
        drawTile(temperature, temperaturemap.getSpriteLocation(textemp));
    } else {
        /**
         * THIS IS WHERE LEVEL EDITOR SIDE BARS GO
         */
        Rectangle bottombar = new Rectangle(500, 600, 800, 200);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, leveleditormap.getSheetID());
        drawTile(bottombar, leveleditormap.getSpriteLocation("bottombar"));

        Rectangle sidebar = new Rectangle(1300, 0, 200, 800);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, leveleditormap.getSheetID());
        drawTile(sidebar, leveleditormap.getSpriteLocation("sidebar"));

        String r;
        Rectangle bounds;
        ArrayList<Scenery> sceneries;
        if (!LEVEL_EDITOR) {
            sceneries = e.getSceneries();
        } else {
            sceneries = edit.getSceneries();
        }
        for (DefaultCharacter scenery : sceneries) {
            if (scenery.getEditor() == true) {
                r = scenery.getTexture();
                bounds = scenery.getScreenPosition();
                if (scenery instanceof HealingScenery) {
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, healingmap.getSheetID());

                    drawTile(bounds, healingmap.getSpriteLocation(r));
                } else if (scenery instanceof PermeableScenery) {
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, interactivemap.getSheetID());

                    drawTile(bounds, interactivemap.getSpriteLocation(r));
                } else if (scenery instanceof Decoration) {
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, decorationmap.getSheetID());

                    drawTile(bounds, decorationmap.getSpriteLocation(r));
                } else {
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, newscenerymap.getSheetID());

                    drawTile(bounds, newscenerymap.getSpriteLocation(r));
                }
            }
        }
        if (!LEVEL_EDITOR) {
            ArrayList<MovingCharacter> characters = e.getCharacters();
            for (DefaultCharacter character : characters) {
                r = character.getTexture();
                bounds = character.getScreenPosition();
                GL11.glBindTexture(GL11.GL_TEXTURE_2D, playermap.getSheetID());

                drawTile(bounds, playermap.getSpriteLocation(r));
            }
        }
        ArrayList<Threat> threats;
        if (!LEVEL_EDITOR) {
            threats = e.getThreats();
        } else {
            threats = edit.getThreats();
        }
        for (DefaultCharacter threat : threats) {
            if (threat.getEditor() == true) {
                r = threat.getTexture();
                bounds = threat.getScreenPosition();
                GL11.glBindTexture(GL11.GL_TEXTURE_2D, threatmap.getSheetID());

                drawTile(bounds, threatmap.getSpriteLocation(r));
            }
        }
    }
    boolean paused;
    if (!LEVEL_EDITOR) {
        paused = e.getPaused();
    } else {
        paused = edit.getPaused();
    }
    if (paused == true) {
        Rectangle grey = new Rectangle(0, 0, 800, 600);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, menumap.getSheetID());
        drawTile(grey, menumap.getSpriteLocation("darken"));

        Rectangle title = new Rectangle(300, 220, 200, 72);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, menumap.getSheetID());
        drawTile(title, menumap.getSpriteLocation("paused"));

        Rectangle options = new Rectangle(357, 300, 86, 28);
        if (checkHover(options) == true) {
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, menumap.getSheetID());
            drawTile(options, menumap.getSpriteLocation("optionslight"));
        } else {
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, menumap.getSheetID());
            drawTile(options, menumap.getSpriteLocation("optionsdark"));
        }

        Rectangle quit = new Rectangle(377, 335, 46, 32);
        if (checkHover(quit) == true) {
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, menumap.getSheetID());
            drawTile(quit, menumap.getSpriteLocation("quitlight"));
        } else {
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, menumap.getSheetID());
            drawTile(quit, menumap.getSpriteLocation("quitdark"));
        }
    }
}

From source file:kuake2.render.lwjgl.Image.java

License:Open Source License

void GL_Bind(int texnum) {

    if ((gl_nobind.value != 0) && (draw_chars != null)) {
        // performance evaluation option
        texnum = draw_chars.texnum;//from  w  ww .jav  a  2 s.c  o m
    }
    if (gl_state.currenttextures[gl_state.currenttmu] == texnum)
        return;

    gl_state.currenttextures[gl_state.currenttmu] = texnum;
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texnum);
}

From source file:main.EntityRenderer.java

private void prepareTextureModel(TextureModel model) {
    RawModel rawModel = model.getRawModel();
    GL30.glBindVertexArray(rawModel.getVaoId());
    GL20.glEnableVertexAttribArray(0);//from   w ww.  j  a va 2s.  c o m
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);
    ModelTexture texture = model.getTexture();
    shader.loadShineVariables(texture.getShineDamper(), texture.getReflectivity());
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, model.getTexture().getTextureId());
}

From source file:main.java.com.YeAJG.game.entity.Entity.java

License:Open Source License

@Override
public void Render(float interpolation) {

    GL20.glUseProgram(pId);//ww  w .  ja v a  2 s.c o  m

    // Bind the texture
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);

    // Bind to the VAO that has all the information about the vertices
    GL30.glBindVertexArray(vaoId);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);

    // Bind to the index VBO that has all the information about the order of the vertices
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);

    // Draw the vertices
    GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);

    // Put everything back to default (deselect)
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL30.glBindVertexArray(0);

    GL20.glUseProgram(0);

    Game.exitOnGLError("renderCycle");
}

From source file:main.java.com.YeAJG.game.io.FileIOHandler.java

License:Open Source License

public static int loadPNGTexture(String filename, int textureUnit) throws IOException {
    ByteBuffer buf = null;//from  w w  w  .j  a v a  2 s.  c  o m
    int tWidth = 0;
    int tHeight = 0;

    try {
        // Open the PNG file as an InputStream
        InputStream in = new FileInputStream(filename);
        // 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, PNGDecoder.RGBA);
        buf.flip();

        in.close();
    } catch (IOException e) {
        throw new IOException(e.getMessage());
    }

    // 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_RGBA, 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_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);

    Game.exitOnGLError("loadPNGTexture");

    return texId;
}

From source file:main.TerrainRenderer.java

private void prepareTerrain(Terrain terrain) {
    RawModel rawModel = terrain.getModel();
    GL30.glBindVertexArray(rawModel.getVaoId());
    GL20.glEnableVertexAttribArray(0);//from  w  w  w . j  a v a2 s  . c  om
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);
    ModelTexture texture = terrain.getTexture();
    shader.loadShineVariables(texture.getShineDamper(), texture.getReflectivity());
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureId());
}

From source file:map.GameMap.java

License:Open Source License

private void renderMinimap() {
    int size = MINIMAP_SIZE;
    Texture tex = new Texture("ground");
    miniMap = new Material(name + "_minimap");
    int[] viewport = GLUtils.getViewport();
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();//from  ww  w.j a v  a  2 s .co m
    GL11.glOrtho(0, size, size, 0, -10, 10);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    GL11.glViewport(0, 0, size, size);

    GL11.glClearColor(0.0f, 0, 0, 1.0f);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glScalef(size / tiles.length, size / tiles.length, size / tiles.length);

    GLUtils.glLightPos(1.0f, 1.0f, 1.0f);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_CULL_FACE);
    draw(null);
    GL11.glEnable(GL11.GL_CULL_FACE);

    IntBuffer addr = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
    GL11.glGenTextures(addr);
    tex.setID(addr.get(0));
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getID());

    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.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, 0, 0, size, size, 0);

    miniMap.setTexture(0, tex);
    GL11.glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
}