i am currently learning to create small java games with OpenGl and lwjgl. I am currently working on an animation system for the entity but i ran into a problem.
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)
This is the error i am getting.
VAO Class:
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);
}
The method, where i use it:
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;
}
You have to initialize opengl before use any of its functionalities.
In LWJGL2:
Display.setDisplayMode(new DisplayMode(800, 600));
Display.create();
In LWJGL3(basically GLFW) you have to call:
glfwInit();
If you have initialized opengl you are trying to call opengl function from a different thread.
Also would be the same error if you are trying to use anything before your init calls.
If this does not help post your centext related code, even if glGenVertexArrays(); causing the problem "No OpenGL context found in the current thread." is a clear error.