显示 ContextAttribs 和 GL11 投影矩阵模式 - 不支持功能
Display ContextAttribs and GL11 Projection Matrix Mode - Function is not supported
当我尝试将我的 LWJGL 程序的矩阵模式设置为 GL_Projection 时出现错误。
glMatrixMode(GL_PROJECTION);
错误是:
Exception in thread "main" java.lang.IllegalStateException: Function is not supported
at org.lwjgl.BufferChecks.checkFunctionAddress(BufferChecks.java:58)
at org.lwjgl.opengl.GL11.glMatrixMode(GL11.java:2075)
....
我已经追踪到制作显示器时的错误。当我删除我的 ContexAttribs 时,我的代码不显示错误并呈现! (当我注释掉需要上下文属性的代码时)
这是我的代码:
显示代码:
Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
ContextAttribs attribs = new ContextAttribs(3, 2).withProfileCore(true).withForwardCompatible(true);
Display.create(new PixelFormat().withDepthBits(24).withSamples(4), attribs);
Display.setTitle(TITLE);
Display.setInitialBackground(1, 1, 1);
GL11.glEnable(GL13.GL_MULTISAMPLE);
GL11.glViewport(0, 0, WIDTH, HEIGHT);
初始化方法:
glMatrixMode(GL_PROJECTION);
glOrtho(0, width, height, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glClearColor(0, 1, 0, 0);
textureID = loadTexture("res/hud.png");
glEnable(GL_TEXTURE_2D);
渲染方法:
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPushMatrix();
glTranslatef(0, 0, 0);
glBindTexture(GL_TEXTURE_2D, textureID);
glBegin(GL_QUADS);
{
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(1, 0);
glVertex2f(width, 0);
glTexCoord2f(1, 1);
glVertex2f(width, height);
glTexCoord2f(0, 1);
glVertex2f(0, height);
}
glEnd();
glPopMatrix();
有谁知道如何让这段代码与 contextAttribs 一起工作?
提前致谢!
编辑 1:我静态导入了 GL11 中的所有函数和变量。
首先,使用 glBegin
/glEnd
序列绘图已被弃用 10 多年了。有关最先进的渲染方式,请参阅 Vertex Specification。
同线
ContextAttribs attribs = new ContextAttribs(3, 2).withProfileCore(true).withForwardCompatible(true);
生成了一个OpenGL core profile Context with Forward compatibility位集。
在此上下文中,所有已弃用的函数,如 glBegin
/glEnd
序列、矩阵堆栈 (glMatrixMode
)、标准光模型等都将被删除。这会导致错误。
另见 Fixed Function Pipeline and OpenGL Context
跳过向前兼容位(.withForwardCompatible(true)
)的设置来解决问题。
当我尝试将我的 LWJGL 程序的矩阵模式设置为 GL_Projection 时出现错误。
glMatrixMode(GL_PROJECTION);
错误是:
Exception in thread "main" java.lang.IllegalStateException: Function is not supported at org.lwjgl.BufferChecks.checkFunctionAddress(BufferChecks.java:58) at org.lwjgl.opengl.GL11.glMatrixMode(GL11.java:2075) ....
我已经追踪到制作显示器时的错误。当我删除我的 ContexAttribs 时,我的代码不显示错误并呈现! (当我注释掉需要上下文属性的代码时)
这是我的代码:
显示代码:
Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
ContextAttribs attribs = new ContextAttribs(3, 2).withProfileCore(true).withForwardCompatible(true);
Display.create(new PixelFormat().withDepthBits(24).withSamples(4), attribs);
Display.setTitle(TITLE);
Display.setInitialBackground(1, 1, 1);
GL11.glEnable(GL13.GL_MULTISAMPLE);
GL11.glViewport(0, 0, WIDTH, HEIGHT);
初始化方法:
glMatrixMode(GL_PROJECTION);
glOrtho(0, width, height, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glClearColor(0, 1, 0, 0);
textureID = loadTexture("res/hud.png");
glEnable(GL_TEXTURE_2D);
渲染方法:
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPushMatrix();
glTranslatef(0, 0, 0);
glBindTexture(GL_TEXTURE_2D, textureID);
glBegin(GL_QUADS);
{
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(1, 0);
glVertex2f(width, 0);
glTexCoord2f(1, 1);
glVertex2f(width, height);
glTexCoord2f(0, 1);
glVertex2f(0, height);
}
glEnd();
glPopMatrix();
有谁知道如何让这段代码与 contextAttribs 一起工作?
提前致谢!
编辑 1:我静态导入了 GL11 中的所有函数和变量。
首先,使用 glBegin
/glEnd
序列绘图已被弃用 10 多年了。有关最先进的渲染方式,请参阅 Vertex Specification。
同线
ContextAttribs attribs = new ContextAttribs(3, 2).withProfileCore(true).withForwardCompatible(true);
生成了一个OpenGL core profile Context with Forward compatibility位集。
在此上下文中,所有已弃用的函数,如 glBegin
/glEnd
序列、矩阵堆栈 (glMatrixMode
)、标准光模型等都将被删除。这会导致错误。
另见 Fixed Function Pipeline and OpenGL Context
跳过向前兼容位(.withForwardCompatible(true)
)的设置来解决问题。