LWJGL在制作显示器时是否需要ContextArribs?

时间:2014-12-04 23:44:38

标签: lwjgl

我遇到了问题,我已经查看了所有地方,所以我要问一下:你需要ContextAttribs吗?运行程序时出现此错误:

org.lwjgl.LWJGLException: Could not create context (WGL_ARB_create_context)
at org.lwjgl.opengl.WindowsContextImplementation.nCreate(Native Method)
at org.lwjgl.opengl.WindowsContextImplementation.create(WindowsContextImplementation.java:50)
at org.lwjgl.opengl.ContextGL.<init>(ContextGL.java:132)
at org.lwjgl.opengl.Display.create(Display.java:850)
at org.lwjgl.opengl.Display.create(Display.java:797)
at renderEngine.DisplayManager.createDisplay(DisplayManager.java:22)
at engineTester.MainGameLoop.main(MainGameLoop.java:10)
Exception in thread "main" java.lang.IllegalStateException: Cannot determine close requested state of uncreated window
at org.lwjgl.opengl.Display.isCloseRequested(Display.java:549)
at engineTester.MainGameLoop.main(MainGameLoop.java:12)

这是我的代码(主类):

import org.lwjgl.opengl.Display;

import renderEngine.DisplayManager;

public class MainGameLoop {

public static void main(String[] args) {
    DisplayManager.createDisplay();

    if (Display.isCloseRequested())
        DisplayManager.closeDisplay();
    while (true)
    {
        DisplayManager.updateDisplay();
    }
}

展示班级:

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.ContextAttribs;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.PixelFormat;
import org.omg.CORBA.Context;


public class DisplayManager {

private static final int WIDTH = 1200;
private static final int HEIGHT = 650;
private static final int FPS_CAP = 60;

public static void createDisplay()  { 
    ContextAttribs attribs = new ContextAttribs(3,2).withProfileCore(true).withForwardCompatible(true);

    try {
        Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
        Display.create(new PixelFormat(), new ContextAttribs(3,2).withProfileCore(true).withForwardCompatible(true));
        Display.setTitle("Knights of the Lord's Realm");
    } catch (LWJGLException e) {
        e.printStackTrace();
    }

}
public static void updateDisplay() { 
    Display.sync(FPS_CAP);
}
public static void closeDisplay() { 
    Display.destroy();
}

}

除了显卡问题之外的任何想法,或者即使我必须使用&#34; ContextAttribs&#34; 谢谢!

1 个答案:

答案 0 :(得分:1)

ContextAttribs attribs = new ContextAttribs(3,2).withProfileCore(true).withForwardCompatible(true);

我假设您正在关注&#34; ThinMatrix&#34; Youtube教程替换了那一行 ContextAttribs attribs = new ContextAttribs(3,2); attribs.withForwardCompatible(true); attribs.withProfileCompatibility(true);