2017-06-05 3 views
-1

Ich lerne gerade, mit OpenGl und lwjgl kleine Java-Spiele zu erstellen. Ich arbeite gerade an einem Animationssystem für die Entität, aber ich stieß auf ein Problem.OpenGL und lwjgl Animation funktioniert nicht

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) 

Dies ist der Fehler, den ich bekomme.

VAO Klasse:

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); 
} 

Das Verfahren, in dem ich es verwenden:

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; 
} 

Antwort

0

Sie haben opengl eine ihrer Funktionalitäten vor der Verwendung zu initialisieren.

In LWJGL2:

Display.setDisplayMode(new DisplayMode(800, 600)); 
Display.create(); 

In LWJGL3 (im Grunde GLFW) Sie rufen:

glfwInit(); 

Wenn Sie opengl initialisiert haben Sie versuchen, opengl Funktion von einem anderen Thread zu nennen.

Auch wäre der gleiche Fehler, wenn Sie versuchen, etwas vor Ihren Initaufrufen zu verwenden.

Wenn dies nicht hilft, Ihren centext bezogenen Code zu veröffentlichen, auch wenn glGenVertexArrays(); verursacht das Problem "Kein OpenGL-Kontext im aktuellen Thread gefunden." ist ein klarer Fehler.

+0

Vielen Dank für Ihre Hilfe. – Simagdo