问题
我无法使用 LWJGL 3 渲染任何东西。它不会渲染任何东西,同时创建 GLFW 显示并成功清除颜色。
工具
- Eclipse 霓虹灯(Java IDE)
- LWJGL 3.1.1 build 16 与 GLFW、JAWT 和 OPENGL 绑定、本地人。
编码
package init;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.nio.IntBuffer;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL;
import org.lwjgl.system.MemoryStack;
import exception.ExceptionHandler;
import util.Time;
import static org.lwjgl.glfw.Callbacks.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryStack.*;
public class DisplayInstance {
public String title = "The SuperMatrix";
public GraphicsDevice gd;
public Game game;
public Config conf;
private long display;
private GLFWErrorCallback glfwerrorcallback;
public DisplayInstance(Game game) {
this.gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
this.game = game;
this.conf = Config.returnConfig(this);
this.glfwerrorcallback = GLFWErrorCallback.createPrint(System.err);
this.glfwerrorcallback.set();
this.start();
}
public void start() {
if (!glfwInit())
ExceptionHandler.handleException(new IllegalStateException("Cannot initialize GLFW"));
glfwDefaultWindowHints();
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
this.display = glfwCreateWindow(this.conf.width, this.conf.height, this.title, 0, 0);
if (this.display == 0L) {
ExceptionHandler.handleException(new RuntimeException("Cannot create GLFW window"));
}
System.out.println(this.display);
try (MemoryStack stack = stackPush()) {
IntBuffer pWidth = stack.mallocInt(1);
IntBuffer pHeight = stack.mallocInt(1);
glfwGetWindowSize(this.display, pWidth, pHeight);
GLFWVidMode mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(this.display,
(mode.width()-pWidth.get(0))/2,
(mode.height()-pHeight.get(0))/2
);
} catch (Exception e) {
ExceptionHandler.handleException(e);
}
glfwMakeContextCurrent(this.display);
glfwSwapInterval(1);
glfwShowWindow(this.display);
this.loop();
}
public void loop() {
GL.createCapabilities();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,this.conf.width, 0, this.conf.height, -1, 1);
glMatrixMode(GL_MODELVIEW);
glDisable(GL_DEPTH_TEST);
Time time = new Time();
while(!glfwWindowShouldClose(this.display)) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glfwSwapBuffers(this.display);
glfwPollEvents();
glPushMatrix();
glBegin(GL_QUADS);
glColor3f(1,0,1);
glVertex2f(0, 0);
glVertex2f(0, 64);
glVertex2f(64, 64);
glVertex2f(64, 0);
glEnd();
glPopMatrix();
float deltaSeconds = time.getDelta()/Time.SECOND;
float fps = deltaSeconds;
System.out.println(fps);
}
this.destroy();
}
public void destroy() {
glfwFreeCallbacks(this.display);
glfwDestroyWindow(this.display);
glfwTerminate();
this.glfwerrorcallback.free();
this.game.stopGame();
}
}
谢谢你。绝对任何帮助将不胜感激。