for (int i = 0; i < t.getNumberOfUnits(); i++) {
for (int i = 0; i < TextureState.getNumberOfUnits(); i++) {
    private void predrawGeometry(Geometry t) {        // set world matrix        Quaternion rotation = t.getWorldRotation();        Vector3f translation = t.getWorldTranslation();        Vector3f scale = t.getWorldScale();        float rot = rotation.toAngleAxis(vRot);        GL11.glMatrixMode(GL11.GL_MODELVIEW);        GL11.glPushMatrix();        GL11.glTranslatef(translation.x, translation.y, translation.z);        GL11.glRotatef(rot, vRot.x, vRot.y, vRot.z);        GL11.glScalef(scale.x, scale.y, scale.z);        if (!(scale.x == 1 && scale.y == 1 && scale.z == 1))            GL11.glEnable(GL11.GL_NORMALIZE); // since we are using        // glScalef, we should enable        // this to keep normals        // working.        VBOInfo vbo = t.getVBOInfo();        if (vbo != null && capabilities.GL_ARB_vertex_buffer_object) {            prepVBO(t);            ignoreVBO = false;        } else            ignoreVBO = true;        // render the object        FloatBuffer verticies = t.getVertexBuffer();        if (prevVerts != verticies) {            GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);            if (!ignoreVBO && vbo.isVBOVertexEnabled()) {                usingVBO = true;                ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vbo.getVBOVertexID());                GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);            } else {                if (usingVBO)                	ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 0);                verticies.rewind();                GL11.glVertexPointer(3, 0, verticies);            }        }        prevVerts = verticies;        FloatBuffer normals = t.getNormalBuffer();        if (prevNorms != normals) {            if (normals != null || (!ignoreVBO && vbo.getVBONormalID() > 0)) {                GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);                if (!ignoreVBO && vbo.isVBONormalEnabled()) {                    usingVBO = true;                    ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vbo.getVBONormalID());                    GL11.glNormalPointer(GL11.GL_FLOAT, 0, 0);                } else {                    if (usingVBO)                    	ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 0);                    normals.rewind();                    GL11.glNormalPointer(0, normals);                }            } else {                GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);            }        }        prevNorms = normals;        FloatBuffer colors = t.getColorBuffer();        if (colors == null || prevColor != colors) {            if (colors != null || (!ignoreVBO && vbo.getVBOColorID() > 0)) {                GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);                if (!ignoreVBO && vbo.isVBOColorEnabled()) {                    usingVBO = true;                    ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vbo.getVBOColorID());                    GL11.glColorPointer(4, GL11.GL_FLOAT, 0, 0);                } else {                    if (usingVBO)                    	ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 0);                    colors.rewind();                    GL11.glColorPointer(4, 0, colors);                }                prevColor = colors;            } else {                GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);                ColorRGBA defCol = t.getDefaultColor();                if (defCol != null)                    GL11.glColor4f(defCol.r, defCol.g, defCol.b, defCol.a);            }        }        for (int i = 0; i < t.getNumberOfUnits(); i++) {            FloatBuffer textures = t.getTextureBuffer(i);            if (prevTex[i] != textures && textures != null) {                if (capabilities.GL_ARB_multitexture && capabilities.OpenGL13) {                    GL13.glClientActiveTexture(GL13.GL_TEXTURE0 + i);                }                if (textures != null || (!ignoreVBO && vbo.getVBOTextureID(i) > 0)) {                    GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);                    if (!ignoreVBO && vbo.isVBOTextureEnabled()) {                        usingVBO = true;                        ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vbo.getVBOTextureID(i));                        GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);                    } else {                        if (usingVBO)                        	ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 0);                        textures.rewind();                        GL11.glTexCoordPointer(2, 0, textures);                    }                } else {                    GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);                }            } else if (prevTex[i] != textures && textures == null) {                GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);            }            prevTex[i] = textures;        }    }   