经过两个多小时(是的,一个弗里芬很长时间!)试图调试此代码,我似乎有一个线条渲染文本,似乎弄脏了它后面的一切(或东西)。UnicodeFont渲染似乎阻止渲染的一切吗?
我试图在该方法上绘制的文本工作正常,但无论出于何种原因,似乎没有其他渲染。
我用if (true) return;
行做了两个实验。
第一个实验是这样的:
,第二个是这样的:
public static void render() {
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glMatrixMode(GL_PROJECTION);
glLoadMatrix(orthographicProjectionMatrix);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glDisable(GL_LIGHTING);
width = Display.getWidth()/2;
height = Display.getHeight()/2;
int ch = Display.getHeight()/10;
// int locationY = 100;
//if (true) return;
//if (true) return;
String msg = loadMessage;
if (msg.contains("RED")){
msg = msg.replace("RED", "");
int offset = font.getWidth(msg)/2;
if (true) return;
font.drawString(Display.getWidth()/2 - offset, Display.getHeight()/2, msg, Color.red);
}else if (msg.contains("YELLOW")){
msg = msg.replace("YELLOW", "");
int offset = font.getWidth(msg)/2;
if (true) return;
font.drawString(Display.getWidth()/2 - offset, Display.getHeight()/2, msg, Color.yellow);
}else{
int offset = font.getWidth(msg)/2;
if (true) return;
font.drawString(Display.getWidth()/2 - offset, Display.getHeight()/2, msg, Color.magenta);
}
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnable(GL_LIGHTING);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glLoadMatrix(perspectiveProjectionMatrix);
glMatrixMode(GL_MODELVIEW);
}
有了第一个,没什么渲染(编辑:现在文本渲染,但是仍然只是蓝色背后)。
随着第二个,除了这个特定的方法渲染的文本以外的所有东西都完美地工作。
那么,有什么区别?我无法理解它。而我无法修复它。
试验1的结果: 试验2的结果:
其他相关的代码:
static void setUpFonts() {
java.awt.Font awtFont = new java.awt.Font("Times New Roman", java.awt.Font.BOLD, 18);
font = new UnicodeFont(awtFont);
font.getEffects().add(new ColorEffect(java.awt.Color.white));
font.addAsciiGlyphs();
try {
font.loadGlyphs();
} catch (SlickException e) {
e.printStackTrace();
cleanUp();
}
}
调用方法:
ready2D();
TextDemo.setUpCamera();
TextDemo.render();
camSetup();
ready3D();
调用方法的变化(建议在评论中)没有任何区别:
ready2D();
glPushMatrix();
TextDemo.setUpCamera();
TextDemo.render();
glPopMatrix();
ready3D();
准备推出2D:
static void ready2D()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLU.gluOrtho2D(0.0f, 1, 1, 0.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.375f, 0.375f, 0.0f);
glDisable(GL_DEPTH_TEST);
}
就绪3D:
static void ready3D()
{
glViewport(0, 0, Display.getWidth(),Display.getHeight());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLU.gluPerspective(45, (float) Display.getWidth()/Display.getHeight(), 0.1f, 5000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
}
Ready2D和Ready3D已知的工作,因为我使用它们进一步下跌的代码来实现的健康吧以上截图中的一个没有问题。
如果需要更多信息,请告诉我。我希望我已经足够了。
什么是TerrainDemo.reg? – immibis
@immibis - 已编辑。 – Joehot200
那么'if(true)return;如果(TerrainDemo.reg)总是返回,但是if(TerrainDemo.reg){if(true)return;'如果TerrainDemo.reg'为false将不会返回。问题出现在'if'语句之后,当函数返回时会跳过。 – immibis