J'apprends actuellement à créer de petits jeux Java avec OpenGl et lwjgl. Je travaille actuellement sur un système d'animation pour l'entité mais j'ai rencontré un problème.OpenGL et lwjgl L'animation ne fonctionne pas
Exception in thread "main" java.lang.RuntimeException: No OpenGL context found in the current thread.
at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124)
at org.lwjgl.opengl.GL30.glGenVertexArrays(GL30.java:1548)
at de.simagdo.simagdoRPG.openglObjects.Vao.create(Vao.java:21)
at de.simagdo.simagdoRPG.animation.models.AnimatedModelLoader.createVao(AnimatedModelLoader.java:73)
at de.simagdo.simagdoRPG.animation.models.AnimatedModelLoader.loadEntity(AnimatedModelLoader.java:28)
at de.simagdo.simagdoRPG.engineTester.SceneLoader.loadScene(SceneLoader.java:30)
at de.simagdo.simagdoRPG.engineTester.MainGameLoop.main(MainGameLoop.java:35)
Ceci est l'erreur que j'obtiens.
VAO Classe:
private static final int BYTES_PER_FLOAT = 4;
private static final int BYTES_PER_INT = 4;
public final int id;
private List<Vbo> dataVbos = new ArrayList<>();
private Vbo indexVbo;
private int indexCount;
public static Vao create() {
int id = GL30.glGenVertexArrays();
return new Vao(id);
}
private Vao(int id) {
this.id = id;
}
public int getIndexCount() {
return indexCount;
}
public void bind(int... attributes) {
bind();
for (int i : attributes) {
GL20.glEnableVertexAttribArray(i);
}
}
public void unbind(int... attributes) {
for (int i : attributes) {
GL20.glDisableVertexAttribArray(i);
}
unbind();
}
public void createIndexBuffer(int[] indices) {
this.indexVbo = Vbo.create(GL15.GL_ELEMENT_ARRAY_BUFFER);
indexVbo.bind();
indexVbo.storeData(indices);
this.indexCount = indices.length;
}
public void createAttribute(int attribute, float[] data, int attrSize) {
Vbo dataVbo = Vbo.create(GL15.GL_ARRAY_BUFFER);
dataVbo.bind();
dataVbo.storeData(data);
GL20.glVertexAttribPointer(attribute, attrSize, GL11.GL_FLOAT, false, attrSize * BYTES_PER_FLOAT, 0);
dataVbo.unbind();
dataVbos.add(dataVbo);
}
public void createIntAttribute(int attribute, int[] data, int attrSize) {
Vbo dataVbo = Vbo.create(GL15.GL_ARRAY_BUFFER);
dataVbo.bind();
dataVbo.storeData(data);
GL30.glVertexAttribIPointer(attribute, attrSize, GL11.GL_INT, attrSize * BYTES_PER_INT, 0);
dataVbo.unbind();
dataVbos.add(dataVbo);
}
public void delete() {
GL30.glDeleteVertexArrays(id);
for (Vbo vbo : dataVbos) {
vbo.delete();
}
indexVbo.delete();
}
private void bind() {
GL30.glBindVertexArray(id);
}
private void unbind() {
GL30.glBindVertexArray(0);
}
La méthode, où je l'utilise:
private static Vao createVao(MeshData data) {
Vao vao = Vao.create();
vao.bind();
vao.createIndexBuffer(data.getIndices());
vao.createAttribute(0, data.getVertices(), 3);
vao.createAttribute(1, data.getTextureCoords(), 2);
vao.createAttribute(2, data.getNormals(), 3);
vao.createIntAttribute(3, data.getJointIds(), 3);
vao.createAttribute(4, data.getVertexWeights(), 3);
vao.unbind();
return vao;
}
Nous vous remercions de votre aide. – Simagdo