I am making a 3D game using LWJGL and I have a texture class with static variables so that I only need to load textures once, even if I need to use them more than once. I am using Slick Util for this. When I bind a texture it works fine, but then when I try to render something else after I have rendered the model with the texture, the texture is still being bound. How do I unbind the texture and set the rendermode to the one that was in use before any textures were bound? Some of my code is below. The problem I am having is the player texture is being used in the box drawn around the player after it the model has been rendered.


public class Model {

public List<Vector3f> vertices = new ArrayList<Vector3f>();
public List<Vector3f> normals = new ArrayList<Vector3f>();
public ArrayList<Vector2f> textureCoords = new ArrayList<Vector2f>();
public List<Face> faces = new ArrayList<Face>();

public static Model TREE;
public static Model PLAYER;

public static void loadModels() {
    try {
        TREE = OBJLoader.loadModel(new File("assets/model/tree_pine_0.obj"));
        PLAYER = OBJLoader.loadModel(new File("assets/model/player.obj"));
    } catch (Exception e) {

public void render(Vector3f position, Vector3f scale, Vector3f rotation, Texture texture, float shinyness) {

        glColor3f(1, 1, 1);
        glTranslatef(position.x, position.y, position.z);
        glScalef(scale.x, scale.y, scale.z);
        glRotatef(rotation.x, 1, 0, 0);
        glRotatef(rotation.y, 0, 1, 0);
        glRotatef(rotation.z, 0, 0, 1);

        glMaterialf(GL_FRONT, GL_SHININESS, shinyness);

            for (Face face : faces) {
                Vector2f t1 = textureCoords.get((int) face.textureCoords.x - 1);
                glTexCoord2f(t1.x, t1.y);
                Vector3f n1 = normals.get((int) face.normal.x - 1);
                glNormal3f(n1.x, n1.y, n1.z);
                Vector3f v1 = vertices.get((int) face.vertex.x - 1);
                glVertex3f(v1.x, v1.y, v1.z);

                Vector2f t2 = textureCoords.get((int) face.textureCoords.y - 1);
                glTexCoord2f(t2.x, t2.y);
                Vector3f n2 = normals.get((int) face.normal.y - 1);
                glNormal3f(n2.x, n2.y, n2.z);
                Vector3f v2 = vertices.get((int) face.vertex.y - 1);
                glVertex3f(v2.x, v2.y, v2.z);

                Vector2f t3 = textureCoords.get((int) face.textureCoords.z - 1);
                glTexCoord2f(t3.x, t3.y);
                Vector3f n3 = normals.get((int) face.normal.z - 1);
                glNormal3f(n3.x, n3.y, n3.z);
                Vector3f v3 = vertices.get((int) face.vertex.z - 1);
                glVertex3f(v3.x, v3.y, v3.z);



public class Textures {

public static Texture FLOOR;
public static Texture PLAYER;

public static Texture SKYBOX_TOP;
public static Texture SKYBOX_BOTTOM;
public static Texture SKYBOX_FRONT;
public static Texture SKYBOX_BACK;
public static Texture SKYBOX_LEFT;
public static Texture SKYBOX_RIGHT;

public static void loadTextures() {
    try {
        FLOOR = TextureLoader.getTexture("PNG", new FileInputStream(new File("assets/model/floor.png")));
        PLAYER = TextureLoader.getTexture("PNG", new FileInputStream(new File("assets/model/tree_pine_0.png")));

        SKYBOX_TOP = TextureLoader.getTexture("PNG", new FileInputStream(new File("assets/textures/skybox_top.png")));
        SKYBOX_BOTTOM = TextureLoader.getTexture("PNG", new FileInputStream(new File("assets/textures/skybox_bottom.png")));
        SKYBOX_FRONT = TextureLoader.getTexture("PNG", new FileInputStream(new File("assets/textures/skybox_front.png")));
        SKYBOX_BACK = TextureLoader.getTexture("PNG", new FileInputStream(new File("assets/textures/skybox_back.png")));
        SKYBOX_LEFT = TextureLoader.getTexture("PNG", new FileInputStream(new File("assets/textures/skybox_left.png")));
        SKYBOX_RIGHT = TextureLoader.getTexture("PNG", new FileInputStream(new File("assets/textures/skybox_right.png")));
    } catch (Exception e) {



public class Player {

private Vector3f position;
private float yaw;
private float moveSpeed;

public Player(float x, float y, float z, float yaw, float moveSpeed) {
    this.position = new Vector3f(x, y, z);
    this.yaw = yaw;
    this.moveSpeed = moveSpeed;

public void update() {
    if (Keyboard.isKeyDown(Keyboard.KEY_W))
    if (Keyboard.isKeyDown(Keyboard.KEY_S))
    if (Keyboard.isKeyDown(Keyboard.KEY_A))
    if (Keyboard.isKeyDown(Keyboard.KEY_D))

    if (Mouse.isButtonDown(0))
        yaw += Mouse.getDX();

    LowPolyRPG.getInstance().getCamera().setPosition(-position.x, -position.y, -position.z);

public void walkForward(float distance) {
    position.setX(position.getX() + distance * (float) Math.sin(Math.toRadians(yaw)));
    position.setZ(position.getZ() - distance * (float) Math.cos(Math.toRadians(yaw)));

public void walkBackwards(float distance) {
    position.setX(position.getX() - distance * (float) Math.sin(Math.toRadians(yaw)));
    position.setZ(position.getZ() + distance * (float) Math.cos(Math.toRadians(yaw)));

public void strafeLeft(float distance) {
    position.setX(position.getX() + distance * (float) Math.sin(Math.toRadians(yaw - 90)));
    position.setZ(position.getZ() - distance * (float) Math.cos(Math.toRadians(yaw - 90)));

public void strafeRight(float distance) {
    position.setX(position.getX() + distance * (float) Math.sin(Math.toRadians(yaw + 90)));
    position.setZ(position.getZ() - distance * (float) Math.cos(Math.toRadians(yaw + 90)));

public void render() {
    Model.PLAYER.render(new Vector3f(position.x, position.y + 12, position.z), new Vector3f(3, 3, 3), new Vector3f(0, -yaw + 90, 0), Textures.PLAYER, 128);

    GL11.glTranslatef(position.getX(), position.getY(), position.getZ());
    GL11.glRotatef(-yaw, 0, 1, 0);
    GL11.glScalef(5.8f, 21, 2.2f);



    GL11.glColor3f(1, 1, 1);

    glVertex3f(1f, 0f, -1f);
    glVertex3f(-1f, 0f, -1f);
    glVertex3f(-1f, 1f, -1f);
    glVertex3f(1f, 1f, -1f);

    glVertex3f(-1f, 0f, 1f);
    glVertex3f(1f, 0f, 1f);
    glVertex3f(1f, 1f, 1f);
    glVertex3f(-1f, 1f, 1f);

    glVertex3f(1f, 1f, -1f);
    glVertex3f(-1f, 1f, -1f);
    glVertex3f(-1f, 1f, 1f);
    glVertex3f(1f, 1f, 1f);

    glVertex3f(1f, 0f, 1f);
    glVertex3f(-1f, 0f, 1f);
    glVertex3f(-1f, 0f, -1f);
    glVertex3f(1f, 0f, -1f);

    glVertex3f(1f, 0f, 1f);
    glVertex3f(1f, 0f, -1f);
    glVertex3f(1f, 1f, -1f);
    glVertex3f(1f, 1f, 1f);

    glVertex3f(-1f, 0f, -1f);
    glVertex3f(-1f, 0f, 1f);
    glVertex3f(-1f, 1f, 1f);
    glVertex3f(-1f, 1f, -1f);




public Vector3f getPosition() {
    return new Vector3f(-position.x, -position.y, -position.z);

public float getX() {
    return position.getX();

public float getY() {
    return position.getY();

public float getZ() {
    return position.getZ();

public void setPosition(Vector3f position) {
    this.position = position;

public void setPosition(float x, float y, float z) {

Thanks for the help.


The quick way is enabling/disabling textures using glEnable(GL_TEXTURE_2D) / glDisable(GL_TEXTURE_2D). Whether it would be best to enable textures before rendering the player and then disabling them after or disabling them before the box and enabling them after, depends on the how/if the rest of your program uses textures throughout.

  • \$\begingroup\$ Most of my rendering is done using a texture so I tried disabling GL_TEXTURE_2D before I rendered the box around the player, and enabling it after but the texture still ends up being bound to the box when it is drawn. \$\endgroup\$ – user35753 Feb 20 '14 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy