当我试图将lwjgl程序的矩阵模式设置为gl_投影时,出现了一个错误。
glMatrixMode(GL_PROJECTION);
错误是:
线程“main”java.lang.IllegalStateException中的异常:不支持函数
在org.lwjgl.bufferchecks.checkfunctionaddress(bufferchecks.java:58)
网址:org.lwjgl.opengl.gl11.glmatrixmode(gl11.java:2075)
……
我已经把这个错误追踪到我展示的时候了。当我删除我的contextribs时,我的代码不会显示错误并呈现!(当我注释掉需要contextribs的代码时)
这是我的代码:
显示代码:
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中的所有函数和变量。