I am taking a tutorial on how to make flappy bird on eclipse (java). I followed all the instructions on this video, but it says this error :
Exception in thread "Game" java.lang.IllegalStateException: Please run the JVM with -XstartOnFirstThread.
at org.lwjgl.system.macosx.EventLoop.checkFirstThread(EventLoop.java:20)
at org.lwjgl.glfw.GLFW.glfwInit(GLFW.java:426)
at com.thecherno.flappy.Main.init(Main.java:37)
at com.thecherno.flappy.Main.run(Main.java:79)
at java.lang.Thread.run(Thread.java:745)
The file location is correct, but there was the error. Here is the Main class code :
package com.thecherno.flappy;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL13.*;
import static org.lwjgl.system.MemoryUtil.*;
import java.nio.ByteBuffer;
import org.lwjgl.glfw.GLFWvidmode;
import org.lwjgl.opengl.GLContext;
import com.thecherno.flappy.graphics.Shader;
import com.thecherno.flappy.input.Input;
import com.thecherno.flappy.level.Level;
import com.thecherno.flappy.maths.Matrix4f;
public class Main implements Runnable {
private int width = 1280;
private int height = 720;
private Thread thread;
private boolean running = false;
private long window;
private Level level;
public void start() {
running = true;
thread = new Thread(this, "Game");
thread.start();
}
private void init() {
if (glfwInit() != GL_TRUE) {
System.err.println("Could not initialize GLFW!");
return;
}
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
window = glfwCreateWindow(width, height, "Flappy", NULL, NULL);
if (window == NULL) {
System.err.println("Could not create GLFW window!");
return;
}
ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, (GLFWvidmode.width(vidmode) - width) / 2, (GLFWvidmode.height(vidmode) - height) / 2);
glfwSetKeyCallback(window, new Input());
glfwMakeContextCurrent(window);
glfwShowWindow(window);
GLContext.createFromCurrent();
glEnable(GL_DEPTH_TEST);
glActiveTexture(GL_TEXTURE1);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
System.out.println("OpenGL: " + glGetString(GL_VERSION));
Shader.loadAll();
Matrix4f pr_matrix = Matrix4f.orthographic(-10.0f, 10.0f, -10.0f * 9.0f / 16.0f, 10.0f * 9.0f / 16.0f, -1.0f, 1.0f);
Shader.BG.setUniformMat4f("pr_matrix", pr_matrix);
Shader.BG.setUniform1i("tex", 1);
Shader.BIRD.setUniformMat4f("pr_matrix", pr_matrix);
Shader.BIRD.setUniform1i("tex", 1);
Shader.PIPE.setUniformMat4f("pr_matrix", pr_matrix);
Shader.PIPE.setUniform1i("tex", 1);
level = new Level();
}
public void run() {
init();
long lastTime = System.nanoTime();
double delta = 0.0;
double ns = 1000000000.0 / 60.0;
long timer = System.currentTimeMillis();
int updates = 0;
int frames = 0;
while (running) {
long now = System.nanoTime();
delta += (now - lastTime) / ns;
lastTime = now;
if (delta >= 1.0) {
update();
updates++;
delta--;
}
render();
frames++;
if (System.currentTimeMillis() - timer > 1000) {
timer += 1000;
System.out.println(updates + " ups, " + frames + " fps");
updates = 0;
frames = 0;
}
if (glfwWindowShouldClose(window) == GL_TRUE)
running = false;
}
glfwDestroyWindow(window);
glfwTerminate();
}
private void update() {
glfwPollEvents();
level.update();
if (level.isGameOver()) {
level = new Level();
}
}
private void render() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
level.render();
int error = glGetError();
if (error != GL_NO_ERROR)
System.out.println(error);
glfwSwapBuffers(window);
}
public static void main(String[] args) {
new Main().start();
}
}
Thanks for your help, also, I am new to stack overflow. I'd be happy if you'd increase my reputation until it's 15 so I can increase other reputations.
Thanks,
-Mjl