Java tutorial
/* * Copyright (C) 2013 Clemens-Alexander Brust IT-Dienstleistungen * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.ikosa.mars.viewer.glviewer.engine; import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL30; import java.util.ArrayList; import java.util.List; public class GLMesh { private String name; private int vertexArrayObjectId; private int interleavedVboId; private boolean hasNormals, hasTexCoords; private List<GLSubMesh> subMeshes; public GLMesh(String name, int vertexArrayObjectId, int interleavedVboId, boolean hasNormals, boolean hasTexCoords) { this.name = name; this.vertexArrayObjectId = vertexArrayObjectId; this.interleavedVboId = interleavedVboId; this.hasNormals = hasNormals; this.hasTexCoords = hasTexCoords; subMeshes = new ArrayList<>(); } public void addSubMesh(GLSubMesh subMesh) { subMeshes.add(subMesh); } public String getName() { return name; } public GLSubMesh getSubMesh(int index) { return subMeshes.get(index); } public int getSubMeshCount() { return subMeshes.size(); } public boolean hasNormals() { return hasNormals; } public boolean hasTexCoords() { return hasTexCoords; } public void use() { GL30.glBindVertexArray(vertexArrayObjectId); GL20.glEnableVertexAttribArray(0); if (hasNormals) GL20.glEnableVertexAttribArray(1); else GL20.glDisableVertexAttribArray(1); if (hasTexCoords) GL20.glEnableVertexAttribArray(2); else GL20.glDisableVertexAttribArray(2); } }