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:dripdisplay.DripDisplayLWJGL.java

private void drawBackground(Point locs) {
    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));
}

From source file:dripdisplay.DripDisplayLWJGL.java

private void drawForeGround() {
    String r;//from ww w  .j  a  va 2  s.  c om
    Rectangle bounds;
    ArrayList<Scenery> sceneries = e.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 Tree) {
                GL11.glBindTexture(GL11.GL_TEXTURE_2D, treemap.getSheetID());

                drawTile(bounds, treemap.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, scenerymap.getSheetID());

                drawTile(bounds, scenerymap.getSpriteLocation(r));
            }
        }
    }
    if (!LEVEL_EDITOR) {
        ArrayList<Player> 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 = e.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:dripdisplay.DripDisplayLWJGL.java

private void drawShadow(Point locs) {
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, levelmap.getSheetID());
    drawTile(e.GAME_SHADOW_RECT, levelmap.getSpriteLocation(e.GAME_SHADOW));
}

From source file:dripdisplay.DripDisplayLWJGL.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 ww .j a  v a  2 s .  c om*/
            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(0, 600, 800, 200);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, leveleditormap.getSheetID());
        drawTile(bottombar, leveleditormap.getSpriteLocation("bottombar"));

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

        String r;
        Rectangle bounds;
        ArrayList<Scenery> sceneries = e.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 Tree) {
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, treemap.getSheetID());

                    drawTile(bounds, treemap.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, scenerymap.getSheetID());

                    drawTile(bounds, scenerymap.getSpriteLocation(r));
                }
            }
        }
        if (!LEVEL_EDITOR) {
            ArrayList<Player> 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 = e.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));
            }
        }
    }
    if (e.getPaused() == 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:dripdisplay.DripDisplayLWJGL.java

private void showLevelComplete() {

    Rectangle title = new Rectangle(272, counter, 256, 39);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, menumap.getSheetID());
    drawTile(title, menumap.getSpriteLocation("levelcomplete"));

    Rectangle pressspace = new Rectangle(311, counter + 50, 179, 16);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, menumap.getSheetID());
    drawTile(pressspace, menumap.getSpriteLocation("pressspacelight"));
    if (counter < 150) {
        counter++;/* w  w  w.j  a  va 2 s  .  c o  m*/
    }
}

From source file:edu.csun.ecs.cs.multitouchj.application.whiteboard.ui.InteractiveCanvas.java

License:Apache License

public void render() {
    synchronized (resizableBufferedImage) {
        Texture texture = getTexture();/*from  w w w . jav  a  2  s  .  co m*/
        if (texture == null) {
            try {
                Image image = getBufferedImageImage(resizableBufferedImage.getBufferedImage());
                texture = getTextureManager().createTexture("" + this.hashCode(), image, true);
                setTexture(texture);
            } catch (Exception exception) {
                log.debug("Failed to generate texture from ResizableBufferedImage.", exception);
            }
        }

        if (isDirty) {
            Image image = getBufferedImageImage(resizableBufferedImage.getBufferedImage());
            ByteBuffer imageData = prepareImage(image);

            GL11.glEnable(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT);
            GL11.glBindTexture(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, texture.getId().intValue());
            GL11.glTexSubImage2D(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, image.getWidth(),
                    image.getHeight(), (image.hasAlpha()) ? GL11.GL_RGBA : GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE,
                    imageData);
            isDirty = false;
        }
    }

    super.render();
}

From source file:edu.csun.ecs.cs.multitouchj.ui.control.FramedControl.java

License:Apache License

public void render() {
    // render with no texture
    Texture texture = getTexture();/*from   w ww . j a  v  a2s  .  co  m*/
    setTexture((Texture) null);

    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    super.render();
    GL11.glPopMatrix();

    setTexture(texture);

    // rendering texture
    if ((!isVisible()) || (texture == null)) {
        return;
    }

    Size controlSize = getSize();
    Size imageSize = texture.getImage().getSize();
    float margin = getMargin();
    if ((margin >= controlSize.getWidth()) || (margin >= controlSize.getHeight())) {
        margin = 0.0f;
    }

    Color color = getColor();
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4f(((float) color.getRed() / 255.0f), ((float) color.getGreen() / 255.0f),
            ((float) color.getBlue() / 255.0f), getOpacity());

    Point position = getOpenGlPosition();
    float halfWidth = (controlSize.getWidth() / 2.0f);
    float halfHeight = (controlSize.getHeight() / 2.0f);
    GL11.glTranslatef(position.getX(), position.getY(), 0.0f);

    float rotation = OpenGlUtility.getOpenGlRotation(getRotation());
    GL11.glRotatef(rotation, 0.0f, 0.0f, 1.0f);

    // render texture
    GL11.glEnable(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT);
    GL11.glBindTexture(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, texture.getId().intValue());

    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0.0f, 0.0f);
    GL11.glVertex3f(((-1 * halfWidth) + margin), ((-1 * halfHeight) + margin), 0.0f);

    GL11.glTexCoord2f(imageSize.getWidth(), 0.0f);
    GL11.glVertex3f((halfWidth - margin), ((-1 * halfHeight) + margin), 0.0f);

    GL11.glTexCoord2f(imageSize.getWidth(), imageSize.getHeight());
    GL11.glVertex3f((halfWidth - margin), (halfHeight - margin), 0.0f);

    GL11.glTexCoord2f(0.0f, imageSize.getHeight());
    GL11.glVertex3f(((-1 * halfWidth) + margin), (halfHeight - margin), 0.0f);
    GL11.glEnd();
}

From source file:edu.csun.ecs.cs.multitouchj.ui.control.TexturedControl.java

License:Apache License

public void render() {
    if (!isVisible()) {
        return;/* w  w  w  .j  ava  2 s  .  com*/
    }

    Size controlSize = getSize();
    Size imageSize = null;
    if (texture != null) {
        imageSize = texture.getImage().getSize();
    }

    Color color = getColor();
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4f(((float) color.getRed() / 255.0f), ((float) color.getGreen() / 255.0f),
            ((float) color.getBlue() / 255.0f), getOpacity());

    Point position = getOpenGlPosition();
    float halfWidth = (controlSize.getWidth() / 2.0f);
    float halfHeight = (controlSize.getHeight() / 2.0f);
    GL11.glTranslatef(position.getX(), position.getY(), 0.0f);

    float rotation = OpenGlUtility.getOpenGlRotation(getRotation());
    GL11.glRotatef(rotation, 0.0f, 0.0f, 1.0f);

    if (texture != null) {
        GL11.glEnable(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT);
        GL11.glBindTexture(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, texture.getId().intValue());
    } else {
        GL11.glDisable(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT);
    }

    // bl -> br -> tr -> tl
    GL11.glBegin(GL11.GL_QUADS);
    if (texture != null) {
        GL11.glTexCoord2f(0.0f, 0.0f);
    }
    GL11.glVertex3f((-1 * halfWidth), (-1 * halfHeight), 0.0f);

    if (texture != null) {
        GL11.glTexCoord2f(imageSize.getWidth(), 0.0f);
    }
    GL11.glVertex3f(halfWidth, (-1 * halfHeight), 0.0f);

    if (texture != null) {
        GL11.glTexCoord2f(imageSize.getWidth(), imageSize.getHeight());
    }
    GL11.glVertex3f(halfWidth, halfHeight, 0.0f);

    if (texture != null) {
        GL11.glTexCoord2f(0.0f, imageSize.getHeight());
    }
    GL11.glVertex3f((-1 * halfWidth), halfHeight, 0.0f);
    GL11.glEnd();
}

From source file:edu.csun.ecs.cs.multitouchj.ui.graphic.image.TextureHandler.java

License:Apache License

public Texture generateTexture(Image image) {
    Integer textureId = generateTextureId();
    ByteBuffer imageData = prepareImage(image);

    GL11.glEnable(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT);
    GL11.glBindTexture(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, textureId.intValue());

    GL11.glTexParameteri(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, GL11.GL_TEXTURE_MIN_FILTER,
            GL11.GL_NEAREST);/*from w  w w . j  ava 2  s.c o m*/
    GL11.glTexParameteri(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, GL11.GL_TEXTURE_MAG_FILTER,
            GL11.GL_NEAREST);
    // GL11.glTexParameteri(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT,
    // GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
    // GL11.glTexParameteri(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT,
    // GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
    GL11.glTexImage2D(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, 0,
            (image.hasAlpha()) ? GL11.GL_RGBA8 : GL11.GL_RGB8, image.getWidth(), image.getHeight(), 0,
            (image.hasAlpha()) ? GL11.GL_RGBA : GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, imageData);

    System.out.println("Texture generated: " + textureId);

    return new Texture(textureId, image);
}

From source file:edu.csun.ecs.cs.multitouchj.ui.graphic.image.TextureHandler.java

License:Apache License

public Texture updateTexture(Texture texture, Image image) {
    ByteBuffer imageData = prepareImage(image);

    GL11.glEnable(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT);
    GL11.glBindTexture(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, texture.getId().intValue());

    GL11.glTexSubImage2D(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, image.getWidth(),
            image.getHeight(), (image.hasAlpha()) ? GL11.GL_RGBA : GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE,
            imageData);//from  w w  w .  ja  v a 2 s .c o m

    return new Texture(texture.getId(), image);
}