@Override public void draw(GL10 gl) { super.draw(gl); // gl = (GL10) GLDebugHelper.wrap(gl, GLDebugHelper.CONFIG_CHECK_GL_ERROR, log); // do positioning: gl.glScalef(model.scale, model.scale, model.scale); gl.glTranslatef(model.xpos, model.ypos, model.zpos); gl.glRotatef(model.xrot, 1, 0, 0); gl.glRotatef(model.yrot, 0, 1, 0); gl.glRotatef(model.zrot, 0, 0, 1); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_NORMAL_ARRAY); // first draw non textured groups gl.glDisable(GL10.GL_TEXTURE_2D); int cnt = nonTexturedGroups.length; for (int i = 0; i < cnt; i++) { Group group = nonTexturedGroups[i]; Material mat = group.getMaterial(); if (mat != null) { gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR, mat.specularlight); gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, mat.ambientlight); gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, mat.diffuselight); gl.glMaterialf(GL10.GL_FRONT_AND_BACK, GL10.GL_SHININESS, mat.shininess); } gl.glVertexPointer(3, GL10.GL_FLOAT, 0, group.vertices); gl.glNormalPointer(GL10.GL_FLOAT, 0, group.normals); gl.glDrawArrays(GL10.GL_TRIANGLES, 0, group.vertexCount); } // now we can continue with textured ones gl.glEnable(GL10.GL_TEXTURE_2D); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); cnt = texturedGroups.length; for (int i = 0; i < cnt; i++) { Group group = texturedGroups[i]; Material mat = group.getMaterial(); if (mat != null) { gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR, mat.specularlight); gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, mat.ambientlight); gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, mat.diffuselight); gl.glMaterialf(GL10.GL_FRONT_AND_BACK, GL10.GL_SHININESS, mat.shininess); if (mat.hasTexture()) { gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, group.texcoords); gl.glBindTexture(GL10.GL_TEXTURE_2D, textureIDs.get(mat).intValue()); } } gl.glVertexPointer(3, GL10.GL_FLOAT, 0, group.vertices); gl.glNormalPointer(GL10.GL_FLOAT, 0, group.normals); gl.glDrawArrays(GL10.GL_TRIANGLES, 0, group.vertexCount); } gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); gl.glDisableClientState(GL10.GL_NORMAL_ARRAY); gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); }
@Override public void draw(GL10 gl) { super.draw(gl); gl.glScalef(model.scaleRatio, model.scaleRatio, model.scaleRatio); gl.glTranslatef(model.translationX, model.translationY, model.translationZ); gl.glRotatef(model.rotationX, 1, 0, 0); gl.glRotatef(model.rotationY, 0, 1, 0); gl.glRotatef(model.rotationZ, 0, 0, 1); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_NORMAL_ARRAY); gl.glDisable(GL10.GL_TEXTURE_2D); int counter = nonTexturedGroups.length; for (int i = 0; i < counter; i++) { Group group = nonTexturedGroups[i]; Material material = group.getMaterial(); if (material != null) { gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR, material.specularLight); gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, material.ambientLight); gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, material.diffuseLight); gl.glMaterialf(GL10.GL_FRONT_AND_BACK, GL10.GL_SHININESS, material.shininess); } gl.glVertexPointer(3, GL10.GL_FLOAT, 0, group.vertices); gl.glNormalPointer(GL10.GL_FLOAT, 0, group.normals); gl.glDrawArrays(GL10.GL_TRIANGLES, 0, group.vertexCount); } gl.glEnable(GL10.GL_TEXTURE_2D); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); counter = texturedGroups.length; for (int i = 0; i < counter; i++) { Group group = texturedGroups[i]; Material material = group.getMaterial(); if (material != null) { gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR, material.specularLight); gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, material.ambientLight); gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, material.diffuseLight); gl.glMaterialf(GL10.GL_FRONT_AND_BACK, GL10.GL_SHININESS, material.shininess); if (material.hasTexture()) { gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, group.textureCoordinates); gl.glBindTexture(GL10.GL_TEXTURE_2D, textureIDs.get(material)); } } gl.glVertexPointer(3, GL10.GL_FLOAT, 0, group.vertices); gl.glNormalPointer(GL10.GL_FLOAT, 0, group.normals); gl.glDrawArrays(GL10.GL_TRIANGLES, 0, group.vertexCount); } gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); gl.glDisableClientState(GL10.GL_NORMAL_ARRAY); gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); }