經過兩個多小時(是的,一個弗裏芬很長時間!)試圖調試此代碼,我似乎有一個線條渲染文本,似乎弄髒了它後面的一切(或東西)。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