我正在尝试通过3D游戏将简单的GUI元素渲染到我的屏幕上。当我运行我的程序时,我得到一个IllegalStateException,说不支持该函数。它在drawRect方法的GUI类中抛出:
package renderEngine;
import org.lwjgl.opengl.GL11;
public class GUI {
public float getRedFromHex(int color) {
return (float)(color >> 16 & 0xFF) / 255F;
}
public float getGreenFromHex(int color) {
return (float)(color >> 8 & 0xFF) / 255F;
}
public float getBlueFromHex(int color) {
return (float)(color & 0xFF) / 255F;
}
public float getAlphaFromHex(int color) {
return (float)(color >> 24 & 0xFF) / 255F;
}
public void drawRect(float x, float y, float width, float height, int color) {
float r = this.getRedFromHex(color);
float g = this.getGreenFromHex(color);
float b = this.getBlueFromHex(color);
float a = this.getAlphaFromHex(color);
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glColor4f(r, g, b, a);
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2f(x, y);
GL11.glVertex2f(x + width, y);
GL11.glVertex2f(x + width, y + height);
GL11.glVertex2f(x, y + height);
GL11.glEnd();
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
}
我在渲染类中调用方法:
private GUI gui = new GUI();
public void render(Light sun, Camera camera) {
prepare();
shader.start();
shader.loadSkyColour(RED,GREEN,BLUE);
shader.loadLight(sun);
shader.loadViewMatrix(camera);
renderer.render(entities);
shader.stop();
terrainShader.start();
terrainShader.loadLight(sun);
terrainShader.loadViewMatrix(camera);
terrainShader.loadSkyColour(RED,GREEN,BLUE);
terrainRenderer.render(terrains);
terrainShader.stop();
gui.drawRect(100, 100, 300, 300, 0x00000000);
terrains.clear();
entities.clear();
}
我做错了什么?
编辑:
这是堆栈跟踪:P
Exception in thread "main" java.lang.IllegalStateException: Function is not supported
at org.lwjgl.BufferChecks.checkFunctionAddress(BufferChecks.java:58)
at org.lwjgl.opengl.GL11.glColor4f(GL11.java:893)
at renderEngine.GUI.drawRect(GUI.java:28)
at renderEngine.MasterRenderer.render(MasterRenderer.java:85)
at engineTester.MainGameLoop.main(MainGameLoop.java:147)
答案 0 :(得分:0)
从版本3.0开始,Opengl引入了弃用模型,不推荐使用glVertex,glColor,glTexCoord等函数。
这些已弃用的功能将在核心配置文件中删除,它们不再存在,因此您会受到该例外的欢迎。
你需要做的是阅读现代的opengl,VBOs和VAOs。