your problem is in this code PLACE
Texture texture = new Texture("head");
to solve it make it you can make an other abstract method at your Window class and call it once before while(!glfwWindowShouldClose(this.window)) {
and after GL.createCapabilities();
and make your Texture
object at Starter
class not on new Window("[LWJGL 3] Pong", 640, 480, true) {
Texture texture = new Texture("head");
//some code
}
and give it a value in the new abstract method at Window
your final code will look like this
package doryan_bessiere.pong.com;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL;
public abstract class Window {
protected String title;
protected int width, height;
protected boolean resizable;
protected long window;
public Window(String title, int width, int height, boolean resizable) {
this.title = title;
this.width = width;
this.height = height;
this.resizable = resizable;
}
public void show() {
if(!glfwInit()) {
throw new IllegalStateException("Failed to initialize GLFW!");
}
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
this.window = glfwCreateWindow(this.width, this.height, this.title, 0,0);
if(this.window == 0) {
throw new IllegalStateException("Failed to create window !");
}
GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(this.window, (videoMode.width() - this.width) / 2, (videoMode.height() - this.height) / 2);
glfwShowWindow(this.window);
glfwMakeContextCurrent(window);
GL.createCapabilities();
init();
while(!glfwWindowShouldClose(this.window)) {
glfwPollEvents();
glClear(GL_COLOR_BUFFER_BIT);
render();
glfwSwapBuffers(window);
}
glfwTerminate();
}
public boolean getKey(int key) {
return glfwGetKey(this.width, key) == GLFW_TRUE;
}
public boolean getMouse(int button) {
return glfwGetMouseButton(this.width, button) == GLFW_TRUE;
}
public void close() {
glfwSetWindowShouldClose(window, true);
}
public abstract void render();
public abstract void init();
}
public class Starter {
public static Texture texture;
public static void main(String[] args) {
new Window("[LWJGL 3] Pong", 640, 480, true) {
@Override
public void init(){
texture = new Texture("head");
}
@Override
public void render() {
texture.bind();
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(-0.5f, 0.5f);
glTexCoord2f(0,1);
glVertex2f(0.5f, 0.5f);
glTexCoord2f(1,1);
glVertex2f(0.5f, -0.5f);
glTexCoord2f(1,0);
glVertex2f(-0.5f, -0.5f);
glEnd();
}
}.show();
}
}
and there are to many solutions to fix this it's simple one.
Can you give me an email to connect with you?