本文介绍了TextRenderer不显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是GLEventListener
的实现方法出于某种原因,屏幕上没有显示文字?
我其余的关卡对象都可以正常绘制. (除了它们都被染成红色)
Following are implementation methods of GLEventListener
For some reason, no text is shown on screen?
The rest of my level objects draw fine. (with the exception of they all being tinted red)
private TextRenderer renderer;
public void init(GLAutoDrawable gLDrawable) {
GL2 gl = gLDrawable.getGL().getGL2();
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glShadeModel(GL2.GL_SMOOTH);
gl.glEnable(GL.GL_TEXTURE_2D);
renderer = new TextRenderer(new Font("SansSerif", Font.BOLD, 36));
}
public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) {
final GL2 gl = gLDrawable.getGL().getGL2();
if (height <= 0) { // avoid a divide by zero error!
height = 1;
}
final float h = (float) width / (float) height;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(170.0f, h, 1.0, 20.0);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void display(GLAutoDrawable gLDrawable) {
renderer.beginRendering(gLDrawable.getWidth(), gLDrawable.getHeight());
renderer.setColor(1.0f, 0.2f, 0.2f, 0.8f);
renderer.draw("Text to draw", 0, 0);
renderer.endRendering();
// draw squares, circles in the level etc
level.draw(gLDrawable);
}
推荐答案
我在level.draw()
中有gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
一旦在文本渲染之前将其移开,就可以很好地看到它.
@Andon,我会考虑您关于fov的其他观点
I had gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
inside level.draw()
Once I moved this before my text rendering, I could see it fine.
@Andon, I'll take your other points into consideration about fov
这篇关于TextRenderer不显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!