Problems with a multi-textured cube

Hey guys, I am trying to make a cube that has a different texture on each side, but for some reason I’m getting exceptions when I tell the display to update. Not sure if I’m allowed to bind textures when I am.


    /** Draws a cube with six different textures covering it
     * The textures are ordered FrontBackTopBottomLeftRight in the array
     * WARNING - Array must be at least length 6
     * WARNING - Make sure to be in 3D mode first!
     * @param texts An array of texture locations for each side
     * @param x The x location of the bottom left corner
     * @param y The y location of the bottom left corner
     * @param z The z location of the bottom left corner
     * @param w The width along the x axis
     * @param h The height along the y axis
     * @param d The depth along the z axis*/
    public static void glCube(String[] texs, float x, float y, float z, float w, float h, float d)
    {
    		try
		{
    			Texture[] texture = new Texture[texs.length];
    			for (int i = 0; i < texture.length; i++)
    				texture[i] = BestGameEver.textureLoader.getTexture(texs[i]);
	    		ImageViewer.glColor(255,255,255,255);
	    		GL11.glBegin(GL11.GL_QUADS);
	    		
	    		// Front Face
	    		texture[0].bind();
	    		GL11.glTexCoord2f(0.0f, 0.0f);
	    		GL11.glVertex3f(x,y+h,z); // Bottom Left Of The Texture and Quad
	    		GL11.glTexCoord2f(texture[0].getWidth(), 0.0f);
	    		GL11.glVertex3f(x+w,y+h,z); // Bottom Right Of The Texture and Quad
	    		GL11.glTexCoord2f(texture[0].getWidth(), texture[0].getHeight());
	    		GL11.glVertex3f(x+w,y,z); // Top Right Of The Texture and Quad
	    		GL11.glTexCoord2f(0.0f, texture[0].getHeight());
	    		GL11.glVertex3f(x,y,z); // Top Left Of The Texture and Quad
	    		
	    		// Back Face
	    		texture[1].bind();
	    		GL11.glTexCoord2f(texture[1].getWidth(), 0.0f);
	    		GL11.glVertex3f(x+w,y+h,z-d); // Bottom Right Of The Texture and Quad
	    		GL11.glTexCoord2f(texture[1].getWidth(), texture[1].getHeight());
	    		GL11.glVertex3f(x+w,y,z-d); // Top Right Of The Texture and Quad
	    		GL11.glTexCoord2f(0.0f, texture[1].getHeight());
	    		GL11.glVertex3f(x,y,z-d); // Top Left Of The Texture and Quad
	    		GL11.glTexCoord2f(0.0f, 0.0f);
	    		GL11.glVertex3f(x,y+h,z-d); // Bottom Left Of The Texture and Quad
	    		
	    		// Top Face
	    		texture[2].bind();
	    		GL11.glTexCoord2f(0.0f, texture[2].getHeight());
	    		GL11.glVertex3f(x,y,z-d); // Top Left Of The Texture and Quad
	    		GL11.glTexCoord2f(0.0f, 0.0f);
	    		GL11.glVertex3f(x,y,z); // Bottom Left Of The Texture and Quad
	    		GL11.glTexCoord2f(texture[2].getWidth(), 0.0f);
	    		GL11.glVertex3f(x+w,y,z); // Bottom Right Of The Texture and Quad
	    		GL11.glTexCoord2f(texture[2].getWidth(), texture[2].getHeight());
	    		GL11.glVertex3f(x+w,y,z-d); // Top Right Of The Texture and Quad
	    		
	    		// Bottom Face
	    		texture[3].bind();
	    		GL11.glTexCoord2f(texture[3].getWidth(), texture[3].getHeight());
	    		GL11.glVertex3f(x+w,y+h,z-d); // Top Right Of The Texture and Quad
	    		GL11.glTexCoord2f(0.0f, texture[3].getHeight());
	    		GL11.glVertex3f(x,y+h,z-d); // Top Left Of The Texture and Quad
	    		GL11.glTexCoord2f(0.0f, 0.0f);
	    		GL11.glVertex3f(x,y+h,z); // Bottom Left Of The Texture and Quad
	    		GL11.glTexCoord2f(texture[3].getWidth(), 0.0f);
	    		GL11.glVertex3f(x+w,y+h,z); // Bottom Right Of The Texture and Quad
	    		
	    		// Right face
	    		texture[4].bind();
	    		GL11.glTexCoord2f(texture[4].getWidth(), 0.0f);
	    		GL11.glVertex3f(x+w,y+h,z); // Bottom Right Of The Texture and Quad
	    		GL11.glTexCoord2f(texture[4].getWidth(), texture[4].getHeight());
	    		GL11.glVertex3f(x+w,y,z); // Top Right Of The Texture and Quad
	    		GL11.glTexCoord2f(0.0f, texture[4].getHeight());
	    		GL11.glVertex3f(x+w,y,z-d); // Top Left Of The Texture and Quad
	    		GL11.glTexCoord2f(0.0f, 0.0f);
	    		GL11.glVertex3f(x+w,y+h,z-d); // Bottom Left Of The Texture and Quad
	    		
	    		// Left Face
	    		texture[5].bind();
	    		GL11.glTexCoord2f(0.0f, 0.0f);
	    		GL11.glVertex3f(x,y+h,z-d); // Bottom Left Of The Texture and Quad
	    		GL11.glTexCoord2f(texture[5].getWidth(), 0.0f);
	    		GL11.glVertex3f(x,y+h,z); // Bottom Right Of The Texture and Quad
	    		GL11.glTexCoord2f(texture[5].getWidth(), texture[5].getHeight());
	    		GL11.glVertex3f(x,y,z); // Top Right Of The Texture and Quad
	    		GL11.glTexCoord2f(0.0f, texture[5].getHeight());
	    		GL11.glVertex3f(x,y,z-d); // Top Left Of The Texture and Quad
	    		GL11.glEnd();
		}
		catch (Exception e) {e.printStackTrace();}
    }

Basically I pass it an array of strings, create textures of those strings, and then bind each of them. Any idea why it’s having issues?

You must bind the textures outside glBegin / glEnd block.

I guessed that might be the case, so I already tried to have a glBegin and glEnd before and after each quad, but it still gave me an error…

Oh you know what? I was doing what I said, but I still had bind texture inside one out of six of the glBegin’s. Didn’t copy and paste it out. Stupud mistake. Thanks for the help.