2012-04-13 21 views
2

我有這樣的功能呈現在我的畫布上的文字:JOGL/OpenGL的:「 n」(新行)不工作的文本渲染

public void renderString(String s, int x, int y){ 
     gl.glMatrixMode(GL.GL_PROJECTION); 
     gl.glPushMatrix(); 
     gl.glLoadIdentity(); 
     gl.glOrtho(0,WIDTH,0,HEIGHT,-1, 1); 
     gl.glMatrixMode(GL.GL_MODELVIEW); 
     gl.glPushMatrix(); 
      gl.glLoadIdentity(); 
      gl.glTranslatef(x,y,0); 
      gl.glScalef(textScalingFactor, textScalingFactor, 1f); 
      glut.glutStrokeString(GLUT.STROKE_ROMAN, s); 
      gl.glMatrixMode(GL.GL_PROJECTION); 
      gl.glPopMatrix(); 
     gl.glMatrixMode(GL.GL_MODELVIEW); 
     gl.glPopMatrix(); 
} 

問題是,換行符(\ n)是沒有工作,所有的以下字符串:

String s1 = "bla"+"\n"+"bla"; 
String s2 = "bla\nbla"; 

char newLine = new char(10); 
String s3 = "bla"+newLine+"bla"; 

會以類似:

布拉布拉

有什麼想法?

P.S.標籤(\ t)不能正常工作。

P.P.S.與glutBitmapString,glutBitmapCharacter,glutStrokeCharacter相同的問題。

回答

3

看起來是just not implemented因爲你的榜樣運行此代碼...)翻譯總是轉移x,從來沒有y。我縮短了下面的代碼。

public void glutStrokeString(int font, String string) { 
    /* setup */ 
    for (int pos = 0; pos < len; pos++) { 
     /* single char setup */ 
     StrokeCharRec ch = fontinfo.ch[c]; 
     if (ch != null) {    
      /* draw strokes */ 
     } 
     gl.glTranslatef(ch.right, 0.0f, 0.0f); 
    } 
} 

這很可能是其他方法共享相同的問題。

無論如何,你可以自己拆分字符串,用增加的y班次繪製每個部分,並用一些額外的x偏移替換\t