Bonjour à vous,
j'ai un problème avec TextRenderer, j'affiche une JFrame avec un GLCanvas à l'intérieur.
Dans ce GLCanvas, j'affiche des textes aléatoire en utilisant TextRenderer.

Si le nombre de texte est très petit (~<10) tout va bien mais dès que j'augmente, rien ne va plus, l'écran clignote et le texte est affiché n'importe comment.

Je sais que cela est possible car dans la demo du textRenderer, il est possible d'afficher plus de 1000 textes.

Je vous join mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Random;
 
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
 
import com.sun.opengl.util.Animator;
import com.sun.opengl.util.j2d.TextRenderer;
 
public class testText extends JFrame implements GLEventListener {
 
    private TextRenderer renderer;
 
    private int TEXT_LENGTH = 5;
 
    private int NB_TEXT = 100;
 
    private int _width = 1000;
 
    private int _height = 800;
 
    private String[] texts;
 
    private int[][] coords;
 
    private GLU glu = new GLU();
 
    public testText() {
        super("test Text JOGL");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.getContentPane().setLayout(new BorderLayout());
        GLCanvas canvas = new GLCanvas();
        canvas.addGLEventListener(this);
        this.getContentPane().add(canvas, BorderLayout.CENTER);
        this.setSize(_width, _height);
 
        this.generateTexts();
 
        final Animator animator = new Animator(canvas);
        this.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                new Thread(new Runnable() {
                    public void run() {
                        animator.stop();
                        System.exit(0);
                    }
                }).start();
            }
        });
        this.setVisible(true);
        animator.start();
 
    }
 
    public void generateTexts() {
        texts = new String[NB_TEXT];
        coords = new int[NB_TEXT][3];
        for (int i = 0; i < NB_TEXT; i++) {
            texts[i] = randomText(TEXT_LENGTH);
            coords[i][0] = (int) (_width * Math.random());
            coords[i][1] = (int) (_height * Math.random());
            coords[i][2] = (int) (360 * Math.random());
        }
 
    }
 
    public String randomText(int length) {
        String res = "";
        while (res.length() < length)
            res += Long.toString(Math.abs(new Random().nextLong()), 36);
        return res.substring(0, length);
    }
 
    public void init(GLAutoDrawable drawable) {
 
        renderer = new TextRenderer(new Font("Arial", Font.PLAIN, 12), true,
                true);
 
        GL gl = drawable.getGL();
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        glu.gluOrtho2D(0, drawable.getWidth(), 0, drawable.getHeight());
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();
 
    }
 
    public void display(GLAutoDrawable drawable) {
 
        GL gl = drawable.getGL();
 
        gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        renderer.beginRendering(drawable.getWidth(), drawable.getHeight());
        gl.glClear(GL.GL_COLOR_BUFFER_BIT);
        renderer.setColor(Color.BLUE);
        gl.glMatrixMode(GL.GL_MODELVIEW);
        for (int i = 0; i < NB_TEXT; i++) {
            gl.glLoadIdentity();
            gl.glTranslatef(coords[i][0],coords[i][1],0);
            gl.glRotatef(coords[i][2], 0, 0, 1);
            renderer.draw(texts[i], 0, 0);
        }
        renderer.endRendering();
    }
 
    public void reshape(GLAutoDrawable drawable, int x, int y, int width,
            int height) {
    }
 
    public void displayChanged(GLAutoDrawable drawable, boolean modeChanged,
            boolean deviceChanged) {
    }
 
    public static void main(String[] args) {
 
        final testText app = new testText();
 
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                app.setVisible(true);
            }
        });
 
    }
}
Votre aide me serait d'un grand secours.

Je vous remercie par avance.