public void render(Batcher batcher, Transform transform) { Mesh m = getMeshes().get(0); Material originalMaterial = SilenceEngine.graphics.getCurrentMaterial(); Texture originalTexture = Texture.CURRENT; SilenceEngine.graphics.useMaterial(m.getMaterial()); m.getMaterial().getDiffuseMap().bind(); if (transform != null) batcher.applyTransform(transform); batcher.begin(m.isWireFrame() ? Primitive.LINES : Primitive.TRIANGLES); { for (Mesh mesh : getMeshes()) { if (!m.getMaterial().equals(mesh.getMaterial())) { batcher.end(); SilenceEngine.graphics.useMaterial(mesh.getMaterial()); mesh.getMaterial().getDiffuseMap().bind(); m = mesh; if (transform != null) batcher.applyTransform(transform); batcher.begin(m.isWireFrame() ? Primitive.LINES : Primitive.TRIANGLES); } Color color = mesh.getMaterial().getDiffuse(); for (Face face : mesh.getFaces()) { batcher.vertex(mesh.getVertices().get((int) face.vertexIndex.x)); batcher.normal(mesh.getNormals().get((int) face.normalIndex.x)); batcher.texCoord(mesh.getTexcoords().get((int) face.texcoordIndex.x)); if (mesh.getMaterial().getDiffuseMap().getID() == Texture.EMPTY.getID()) batcher.color(color.x, color.y, color.z, mesh.getMaterial().getDissolve()); batcher.vertex(mesh.getVertices().get((int) face.vertexIndex.y)); batcher.normal(mesh.getNormals().get((int) face.normalIndex.y)); batcher.texCoord(mesh.getTexcoords().get((int) face.texcoordIndex.y)); if (mesh.getMaterial().getDiffuseMap().getID() == Texture.EMPTY.getID()) batcher.color(color.x, color.y, color.z, mesh.getMaterial().getDissolve()); batcher.vertex(mesh.getVertices().get((int) face.vertexIndex.z)); batcher.normal(mesh.getNormals().get((int) face.normalIndex.z)); batcher.texCoord(mesh.getTexcoords().get((int) face.texcoordIndex.z)); if (mesh.getMaterial().getDiffuseMap().getID() == Texture.EMPTY.getID()) batcher.color(color.x, color.y, color.z, mesh.getMaterial().getDissolve()); } } } batcher.end(); SilenceEngine.graphics.useMaterial(originalMaterial); originalTexture.bind(); }
public static void update() { if (displayWindow == null) return; displayWindow.swapBuffers(); GLFW3.pollEvents(); if (dirty) { // Force binding Program.CURRENT = null; Texture.CURRENT = null; dirty = false; } Program.DEFAULT.use(); Texture.EMPTY.bind(); }