Text in GLES2

Hi, I have to port a Panda3D application to GLES2. I have used OnscreenTexts in the original application, but they aren’t rendered correctly in GLES2. What approach do you suggest in order to have working texts in GLES2? Thank you very much!

Create a shader that displays the input texture, then apply it to the text.

Thank you, rdb! How can I get the texture from the OnscreenText object? I tried:


but it returns None.

I also tried extracting the texture from myOnscreenText.textNode.getInternalGeom(), but I couldn’t retrieve it. How can I do that?

Thank you!

You don’t need to extract the Texture object. Just use “uniform sampler2D p3d_Texture0;” in the shader.

Thank you, I have this code:

vertexShader = '''
uniform mat4 p3d_ModelViewProjectionMatrix;
attribute vec4 p3d_Vertex;
attribute vec4 p3d_MultiTexCoord0;
varying vec2 textureCoord;
void main() {
  gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;
  textureCoord = vec2(p3d_MultiTexCoord0);

fragmentShader = '''
varying vec2 textureCoord;
uniform sampler2D p3d_Texture0;
void main() {
  gl_FragColor = texture2D(p3d_Texture0, textureCoord);

from panda3d.core import *
loadPrcFileData('', 'load-display pandagles2')
from direct.gui.OnscreenText import OnscreenText
import direct.directbase.DirectStart
textureShader = Shader.make(Shader.SLGLSL, vertexShader, fragmentShader)

It works (i.e. the text is correctly shown) if I set load-display pandagl, but it doesn’t work if I set load-display pandagles2. The same shader works with models/actors/images, but it doesn’t work with OnscreenText in GLES2. Where is my error? Thanks!

Ok, it looks like that the texture filtering was the problem, since this works:

f = loader.loadFont(myFontPath)
t = OnscreenText(text='panda')