IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

3D Java Discussion :

[jogl]Problème avec TextRenderer


Sujet :

3D Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 12
    Par défaut [jogl]Problème avec TextRenderer
    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.

  2. #2
    Membre actif
    Homme Profil pro
    Inscrit en
    Octobre 2004
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France

    Informations forums :
    Inscription : Octobre 2004
    Messages : 41
    Par défaut
    C'est de l'OpenGL dont tu parles, pas de Java 3D. Le traitement n'est pas forcément le même vu que Java 3D est une surcouche à OpenGL notamment.
    Il vaudrait mieux poser ta question directement dans la partie OpenGL.

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 12
    Par défaut
    Comme indiqué dans le titre, je parle de jogl (et non de java 3d).

    C'est en utilisant TextRenderer au sein d'une aplli basée sur jogl que mon problème intervient, donc je pense être à la bonne place.

  4. #4
    Invité de passage
    Inscrit en
    Juillet 2005
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Juillet 2005
    Messages : 1
    Par défaut ca marche pour moi
    Salut,

    J'ai fait tourner ton code sur mon poste et ça marche, même avec
    NB_TEXT = 1000 Nom : 1000.jpg
Affichages : 86
Taille : 129,9 Ko
    ou même 10000 (il reste peu de noir à l'écran dans ce cas ) Nom : 10000.jpg
Affichages : 81
Taille : 180,1 Ko

    ca doit peut-être venir de ta carte graphique : pas assez récente ?

    Config :
    Ubuntu
    jdk 1.4 (he oui, ça marche avec ce vieux pépé)
    eclipse 3.2
    Intel dual Core 4300 @1.8Ghz
    2go ram

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 12
    Par défaut
    Je te remercie pour ta réponse.

Discussions similaires

  1. [OpenGL 3.x] [JOGL] Problème de multi-thread avec les VBO
    Par darksamus1 dans le forum OpenGL
    Réponses: 4
    Dernier message: 02/07/2013, 12h47
  2. [JOGL] Problème avec glTranslatef(x, y, z)
    Par VonDriguen dans le forum 3D
    Réponses: 6
    Dernier message: 22/02/2013, 10h13
  3. Problème avec la lumière (jogl:opengl)
    Par Alays dans le forum OpenGL
    Réponses: 4
    Dernier message: 31/10/2012, 13h12
  4. Problème avec la lumière (jogl:opengl)
    Par Alays dans le forum Général Java
    Réponses: 2
    Dernier message: 29/10/2012, 17h48
  5. [jogl]Problème avec glReadPixels
    Par GLDavid dans le forum OpenGL
    Réponses: 8
    Dernier message: 13/01/2009, 15h20

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo