@Override public void init() throws Exception { renderer.init(); float[] positions = new float[]{ -0.5f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f, 0.5f, 0.5f, 0.0f,}; int[] indices = new int[]{ 0, 1, 3, 3, 1, 2,}; mesh = new Mesh(positions, indices); }
public void cleanup() { int numMeshes = this.meshes != null ? this.meshes.length : 0; for (int i = 0; i < numMeshes; i++) { this.meshes[i].cleanUp(); } }
public void render() { initRender(); glDrawElements(GL_TRIANGLES, getVertexCount(), GL_UNSIGNED_INT, 0); endRender(); }
public void render() { // Draw the mesh glBindVertexArray(getVaoId()); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glDrawElements(GL_TRIANGLES, getVertexCount(), GL_UNSIGNED_INT, 0); // Restore state glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glBindVertexArray(0); }
private void renderHud(Window window, IHud hud) { hudShaderProgram.bind(); Matrix4f ortho = transformation.getOrthoProjectionMatrix(0, window.getWidth(), window.getHeight(), 0); for (GameItem gameItem : hud.getGameItems()) { Mesh mesh = gameItem.getMesh(); // Set ortohtaphic and model matrix for this HUD item Matrix4f projModelMatrix = transformation.getOrtoProjModelMatrix(gameItem, ortho); hudShaderProgram.setUniform("projModelMatrix", projModelMatrix); hudShaderProgram.setUniform("colour", gameItem.getMesh().getMaterial().getAmbientColour()); hudShaderProgram.setUniform("hasTexture", gameItem.getMesh().getMaterial().isTextured() ? 1 : 0); // Render the mesh for this HUD item mesh.render(); } hudShaderProgram.unbind(); }
private static Mesh processMesh(AIMesh aiMesh, List<Material> materials) { List<Float> vertices = new ArrayList<>(); List<Float> textures = new ArrayList<>(); List<Float> normals = new ArrayList<>(); List<Integer> indices = new ArrayList(); processVertices(aiMesh, vertices); processNormals(aiMesh, normals); processTextCoords(aiMesh, textures); processIndices(aiMesh, indices); Mesh mesh = new Mesh(Utils.listToArray(vertices), Utils.listToArray(textures), Utils.listToArray(normals), Utils.listIntToArray(indices)); Material material; int materialIdx = aiMesh.mMaterialIndex(); if (materialIdx >= 0 && materialIdx < materials.size()) { material = materials.get(materialIdx); } else { material = new Material(); } mesh.setMaterial(material); return mesh; }
public SkyBox(String objModel, Vector4f colour) throws Exception { super(); Mesh skyBoxMesh = OBJLoader.loadMesh(objModel); Material material = new Material(colour, 0); skyBoxMesh.setMaterial(material); setMesh(skyBoxMesh); setPosition(0, 0, 0); } }
public Hud(String statusText) throws Exception { this.statusTextItem = new TextItem(statusText, FONT_TEXTURE, FONT_COLS, FONT_ROWS); this.statusTextItem.getMesh().getMaterial().setAmbientColour(new Vector4f(1, 1, 1, 1)); gameItems = new GameItem[]{statusTextItem}; }
public void setText(String text) { this.text = text; this.getMesh().deleteBuffers(); this.setMesh(buildMesh()); } }
public void setText(String text) { this.text = text; Texture texture = this.getMesh().getMaterial().getTexture(); this.getMesh().deleteBuffers(); this.setMesh(buildMesh(texture, numCols, numRows)); } }
public void renderTest(ShadowBuffer shadowMap) { testShaderProgram.bind(); testShaderProgram.setUniform("texture_sampler[0]", 0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, shadowMap.getDepthMapTexture().getIds()[0]); quadMesh.render(); testShaderProgram.unbind(); }
private void initRender() { Texture texture = material.getTexture(); if (texture != null) { // Activate firs texture bank glActiveTexture(GL_TEXTURE0); // Bind the texture glBindTexture(GL_TEXTURE_2D, texture.getId()); } // Draw the mesh glBindVertexArray(getVaoId()); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); }
public void render() { // Draw the mesh glBindVertexArray(getVaoId()); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glDrawElements(GL_TRIANGLES, getVertexCount(), GL_UNSIGNED_INT, 0); // Restore state glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glBindVertexArray(0); }
private void renderHud(Window window, IHud hud) { hudShaderProgram.bind(); Matrix4f ortho = transformation.getOrthoProjectionMatrix(0, window.getWidth(), window.getHeight(), 0); for (GameItem gameItem : hud.getGameItems()) { Mesh mesh = gameItem.getMesh(); // Set ortohtaphic and model matrix for this HUD item Matrix4f projModelMatrix = transformation.buildOrtoProjModelMatrix(gameItem, ortho); hudShaderProgram.setUniform("projModelMatrix", projModelMatrix); hudShaderProgram.setUniform("colour", gameItem.getMesh().getMaterial().getAmbientColour()); hudShaderProgram.setUniform("hasTexture", gameItem.getMesh().getMaterial().isTextured() ? 1 : 0); // Render the mesh for this HUD item mesh.render(); } hudShaderProgram.unbind(); }
private static Mesh processMesh(AIMesh aiMesh, List<Material> materials) { List<Float> vertices = new ArrayList<>(); List<Float> textures = new ArrayList<>(); List<Float> normals = new ArrayList<>(); List<Integer> indices = new ArrayList(); processVertices(aiMesh, vertices); processNormals(aiMesh, normals); processTextCoords(aiMesh, textures); processIndices(aiMesh, indices); Mesh mesh = new Mesh(Utils.listToArray(vertices), Utils.listToArray(textures), Utils.listToArray(normals), Utils.listIntToArray(indices)); Material material; int materialIdx = aiMesh.mMaterialIndex(); if (materialIdx >= 0 && materialIdx < materials.size()) { material = materials.get(materialIdx); } else { material = new Material(); } mesh.setMaterial(material); return mesh; }
public SkyBox(String objModel, Vector4f colour) throws Exception { super(); Mesh skyBoxMesh = OBJLoader.loadMesh(objModel); Material material = new Material(colour, 0); skyBoxMesh.setMaterial(material); setMesh(skyBoxMesh); setPosition(0, 0, 0); } }
public Hud(String statusText) throws Exception { FontTexture fontTexture = new FontTexture(FONT, CHARSET); this.statusTextItem = new TextItem(statusText, fontTexture); this.statusTextItem.getMesh().getMaterial().setAmbientColour(new Vector4f(0.5f, 0.5f, 0.5f, 10f)); // Create list that holds the items that compose the HUD gameItems = new GameItem[]{statusTextItem}; }
public void setText(String text) { this.text = text; this.getMesh().deleteBuffers(); this.setMesh(buildMesh()); } }
public void setText(String text) { this.text = text; Texture texture = this.getMesh().getMaterial().getTexture(); this.getMesh().deleteBuffers(); this.setMesh(buildMesh(texture, numCols, numRows)); } }
public void renderTest(ShadowBuffer shadowMap) { testShaderProgram.bind(); testShaderProgram.setUniform("texture_sampler[0]", 0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, shadowMap.getDepthMapTexture().getIds()[0]); quadMesh.render(); testShaderProgram.unbind(); }