java - 没有通过公认的 API 方法 (glfwMakeContextCurrent) 使 OpenGL 上下文成为当前的
问题描述
我正在学习 LWJGL,但出现以下错误:线程“主”java.lang.IllegalStateException 中的异常:没有通过 GL.createCapabilities() 上公认的 API 方法 (glfwMakeContextCurrent) 使 OpenGL 上下文成为最新;
这是我的窗口课
public class window {
private int width, height;
private String title;
private long window;
public int frames;
public static long time;
public input input;
private float bcgR, bcgG, bcgB;
public window(int width, int height, String title) {
this.width = width;
this.height = height;
this.title = title;
}
public void create() {
if (! GLFW.glfwInit()) {
System.err.println("ERROR: GLFW isn't initializied");
return;
}
input = new input();
window = GLFW.glfwCreateWindow(width, height, title, 0, 0);
if (window == 0) {
System.err.println("ERROR: window wasn't created");
return;
}
GLFWVidMode videoMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
GLFW.glfwSetWindowPos(window, (videoMode.width() - width)/2, (videoMode.height() - height)/2);
GLFW.glfwMakeContextCurrent(window);
GL.createCapabilities();
GLFW.glfwShowWindow(window);
GLFW.glfwSetKeyCallback(window, input.getKeybaord());
GLFW.glfwSetCursorPosCallback(window,input.getMouseMove());
GLFW.glfwSetMouseButtonCallback(window, input.getMouseButtons());
GLFW.glfwSwapInterval(1);
time = System.currentTimeMillis();
}
public void update() {
GL11.glClearColor(bcgR, bcgG, bcgB, 1.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GLFW.glfwPollEvents();
frames ++;
if (System.currentTimeMillis() > time + 1000) {
GLFW.glfwSetWindowTitle(window, title + "|FPS: " + frames);
time = System.currentTimeMillis();
frames = 0;
}
}
public void swapBuffers() {
GLFW.glfwSwapBuffers(window);
}
public boolean shouldClose() {
return GLFW.glfwWindowShouldClose(window);
}
public void destroy() {
input.destory();
GLFW.glfwWindowShouldClose(window);
GLFW.glfwDestroyWindow(window);
GLFW.glfwTerminate();
}
public void setBcgColor(float r, float g, float b) {
bcgR = r;
bcgG = g;
bcgB = b;
}
}
这是我的主要课程
public class main implements Runnable {
public window window;
public final int WIDTH = 1200, HEIGHT = 800;
public void init() {
System.out.println("Initializing Game!");
window = new window(WIDTH, HEIGHT, "Game");
window.setBcgColor(1.0f, 0, 0);
window .create();
}
public void run() {
init();
while (!window.shouldClose()) {
GLFW.glfwWaitEvents();
update();
render();
if (input.isKeyDown(GLFW.GLFW_KEY_ESCAPE)) return;
}
window.destroy();
}
private void update() {
window.update();
if (input.isButtonDown(GLFW.GLFW_MOUSE_BUTTON_LEFT)) {
System.out.println("X: " + window.input.getMouseX() + "Y: " + window.input.getMouseY());
}
}
private void render() {
window.swapBuffers();
}
public static void main(String[] args) {
new main().run();
}
}
我正在尝试将背景颜色更改为红色。
请有人帮忙。
解决方案
推荐阅读
- vba - 计算 Excel 行中的颜色变化
- php - 将 Moodle 模块从资源转移到活动
- xml - ORA-06502: PL/SQL: 尝试将 XML 保存到文件时出现数字或值错误
- xml - 可以在嵌套结构 (xslt1.0) 上排序吗?
- angularjs - Angularjs UI-Router 状态更改更改 Google-API 指令的功能
- javascript - 从多个地方导入单例类时如何创建单例类?
- javascript - tryhandlebarsjs 注册 Helper 函数
- regex - 如何在 perl 中搜索和替换字符串中的非字符?
- apache2 - Apache2 Proxy Pass 包括 URL 上的所有参数
- angular - 在 Ionic3、Angular4 中检索当前位置并在地图上设置时无法正常工作