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

OpenGL Discussion :

[VBO] Afficher des géométries différentes


Sujet :

OpenGL

  1. #1
    Expert confirmé
    Avatar de GLDavid
    Homme Profil pro
    Service Delivery Manager
    Inscrit en
    Janvier 2003
    Messages
    2 865
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Service Delivery Manager
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 865
    Points : 4 862
    Points
    4 862
    Par défaut [VBO] Afficher des géométries différentes
    Bonjour

    Voilà je cherche quelques conseils sur une question que je me pose concernant les VBO.
    Dans mon application, je dessine sans peine à l'aide de cette technique des carrés (GL_QUADS). Seulement, je veux maintenant lier ces carrés à l'aide de lignes (GL_LINES). Faut-il alors créer plusieurs buffers à l'aide de glGenBufer ? Ou y a t'il un moyen plus élégants ?

    Merci d'avance.

    @++

  2. #2
    Expert confirmé
    Avatar de GLDavid
    Homme Profil pro
    Service Delivery Manager
    Inscrit en
    Janvier 2003
    Messages
    2 865
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Service Delivery Manager
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 865
    Points : 4 862
    Points
    4 862
    Par défaut
    Ok, je pense avoir trouvé une solution mais je ne pense pas qu'elle soit optimale:
    1) Construire tous les buffers de mes carrés. Les mettre dans le tampon de noms.
    2) Dessiner mes carrés avec glMultiDrawArrays
    3) Vider mon tampon avec glDeleteBuffer
    4) Construire tous les buffers de mes liens. Les mettre dans le tampon de noms.
    5) Dessiner mes liens avec glMultiDrawArrays
    6) Vider mon tampon avec glDeleteBuffer
    7) goto 1
    Bon ça marche mais comme je le fais remarquer, ce n'est certainement pas la méthode la plus élégante. En effet, mon nombre de carrés et de liens pourra être très important et je crains des soucis en terme de rapidité d'affichage. Je suis donc ouvert à toutes suggestion

    @++

  3. #3
    Expert éminent

    Profil pro
    Fabricant et casseur d'avions
    Inscrit en
    Avril 2004
    Messages
    3 814
    Détails du profil
    Informations personnelles :
    Localisation : France, Tarn (Midi Pyrénées)

    Informations professionnelles :
    Activité : Fabricant et casseur d'avions
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Avril 2004
    Messages : 3 814
    Points : 7 642
    Points
    7 642
    Par défaut
    Salut

    Pourquoi ne pas dessiner tes quads avec des GL_LINES?

  4. #4
    Expert confirmé
    Avatar de GLDavid
    Homme Profil pro
    Service Delivery Manager
    Inscrit en
    Janvier 2003
    Messages
    2 865
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Service Delivery Manager
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 865
    Points : 4 862
    Points
    4 862
    Par défaut
    Salut Plegat

    Et bien, tout simplement parce que je veux des carrés "pleins": mes carrés doivent contenir une couleur ou une texture.

    @++

  5. #5
    Membre expérimenté

    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2006
    Messages
    450
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2006
    Messages : 450
    Points : 1 630
    Points
    1 630
    Par défaut
    Tu peux aussi afficher tes carres en mode filaire comme ca ca te fera des lignes ? Et tu n'auras plus qu'un buffer d'indices (la geometrie c'est ton buffer de points, la topologie c'est ton buffer d'indices...).

  6. #6
    Expert confirmé
    Avatar de GLDavid
    Homme Profil pro
    Service Delivery Manager
    Inscrit en
    Janvier 2003
    Messages
    2 865
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Service Delivery Manager
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 865
    Points : 4 862
    Points
    4 862
    Par défaut
    Citation Envoyé par TanEk Voir le message
    Tu peux aussi afficher tes carres en mode filaire comme ca ca te fera des lignes ? Et tu n'auras plus qu'un buffer d'indices (la geometrie c'est ton buffer de points, la topologie c'est ton buffer d'indices...).
    Bonjour

    Mais dans ce cas, comment faire pour appliquer une couleur ?

    @++

  7. #7
    Membre expérimenté

    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2006
    Messages
    450
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2006
    Messages : 450
    Points : 1 630
    Points
    1 630
    Par défaut
    Comment ca ? Le fait de rendre en filaire ne change rien pour OpenGL a sa maniere de faire le rendu. Si tu textures ton mesh et que tu lui appliques une lumiere, ce sera pareil en filaire seulement il n'y aura que des aretes...

  8. #8
    Expert confirmé
    Avatar de GLDavid
    Homme Profil pro
    Service Delivery Manager
    Inscrit en
    Janvier 2003
    Messages
    2 865
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Service Delivery Manager
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 865
    Points : 4 862
    Points
    4 862
    Par défaut
    Salut TanEk

    Hmmm, j'admets ne pas trop suivre . Je vais tâcher de trouver un exemple par rapport à ton propos. Je suis encore débutant en VBO et je dispose d'encore trop de références sur le rendu immédiat et de méthodes classiques.
    Cela étant, je te remercie car c'est une optimisation à suivre.
    Je suis enfin satisfait de voir que personne ne trouve à redire sur le "pseudocode"
    Merci à vous tous

    @++

  9. #9
    Expert confirmé
    Avatar de GLDavid
    Homme Profil pro
    Service Delivery Manager
    Inscrit en
    Janvier 2003
    Messages
    2 865
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Service Delivery Manager
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 865
    Points : 4 862
    Points
    4 862
    Par défaut
    Bonjour

    Chose promise, chose dûe. Je poste ici un petit code de démo sur commet afficher plusieurs géométries différentes. Le code fonctionne pour Java 5-6 avec JOGL 1.1.1:
    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
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
     
     
    import com.sun.opengl.util.Animator;
    import com.sun.opengl.util.BufferUtil;
    import java.awt.BorderLayout;
    import java.awt.event.MouseWheelEvent;
    import java.awt.event.MouseWheelListener;
    import java.nio.ByteBuffer;
    import java.nio.FloatBuffer;
    import java.nio.IntBuffer;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    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;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /**
     *
     * @author dbourgais
     */
    public class MultiObjectVBO {
     
        public static void main(String[]args){
            GLCanvas canvas = new GLCanvas();
            MultiOVBOTest demo = new MultiOVBOTest();
            canvas.addGLEventListener(demo);
     
            final Animator animator = new Animator(canvas);
            animator.start();
     
            JFrame frame = new JFrame("MultiObjectVBO");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new BorderLayout());
            canvas.setSize(400, 400);
            frame.add(canvas, BorderLayout.CENTER);
            frame.pack();
            frame.setVisible(true);
            canvas.requestFocus();
        }
     
    }
     
    class MultiOVBOTest implements GLEventListener, MouseWheelListener {
     
        private float zoom = -20;
        private List<Square>squares;
        private List<Line>lines;
        private float[]centers = {
            -5, 5, 0,
            5, 5, 0,
            5, -5, 0,
            -5, -5, 0
        };
        private float[]dots = {
            -5, 5, 0, 5, -5, 0,
            5, 5, 0, -5, -5, 0
        };
        private IntBuffer bufferName;
        private FloatBuffer positionData;
        private FloatBuffer colorData;
        private IntBuffer starts;
        private IntBuffer counts;
        private FloatBuffer positionLineData;
        private FloatBuffer colorLineData;
        private IntBuffer startsLine;
        private IntBuffer countsLine;
        private final int LIMIT = 4;
     
        public MultiOVBOTest(){
            squares = new ArrayList<Square>();
            lines = new ArrayList<Line>();
            for(int i=0; i<centers.length; i+=3){
                squares.add(new Square(centers[i], centers[i+1], centers[i+2]));
            }
            for(int i=0; i<dots.length; i+=6){
                lines.add(new Line(dots[i], dots[i+1], dots[i+2], dots[i+3], dots[i+4], dots[i+5]));
            }
            this.bufferName = BufferUtil.newIntBuffer(LIMIT);
        }
     
        public void init(GLAutoDrawable drawable) {
            final GL gl = drawable.getGL();
     
            drawable.addMouseWheelListener(this);
     
            gl.glShadeModel(gl.GL_SMOOTH);
            gl.glEnable(gl.GL_DEPTH_TEST);
     
            gl.glGenBuffers(LIMIT, bufferName);
     
            int constant = squares.size() * BufferUtil.SIZEOF_FLOAT;
            this.positionData = BufferUtil.newFloatBuffer(12 * constant);
            this.colorData = BufferUtil.newFloatBuffer(4 * constant);
            this.starts = BufferUtil.newIntBuffer(squares.size());
            this.counts = BufferUtil.newIntBuffer(squares.size());
     
            constant = lines.size() * BufferUtil.SIZEOF_FLOAT;
            this.positionLineData = BufferUtil.newFloatBuffer(6 * constant);
            this.colorLineData = BufferUtil.newFloatBuffer(4 * constant);
            this.startsLine = BufferUtil.newIntBuffer(lines.size());
            this.countsLine = BufferUtil.newIntBuffer(lines.size());
     
            pushNodesDataBuffers(gl);
            pushLinesDataBuffers(gl);
        }
     
        private void pushNodesDataBuffers(final GL gl){
            Iterator<Square> it = this.squares.iterator();
            int i = 0;
            int j = 4;
            while (it.hasNext()) {
                Square square = it.next();
                this.positionData.put(square.getBufferVertices());
                this.colorData.put(square.getBufferColor());
                starts.put(i);
                counts.put(j);
                i = i + square.getBufferIndicesSize();
                j = j + square.getBufferIndicesSize();
            }
            this.positionData.rewind();
            this.colorData.rewind();
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            gl.glBufferData(gl.GL_ARRAY_BUFFER, 
                    this.squares.get(0).sizeofBufferVertices() *
                        this.squares.size() * BufferUtil.SIZEOF_FLOAT,
                    positionData,
                    gl.GL_STATIC_DRAW);
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(1));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.squares.get(0).sizeofBufferColor() *
                        this.squares.size() * BufferUtil.SIZEOF_FLOAT,
                    colorData,
                    gl.GL_STATIC_DRAW);
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
     
            this.starts.rewind();
            this.counts.rewind();
        }
     
        private void pushLinesDataBuffers(final GL gl){
            Iterator<Line> it = this.lines.iterator();
            int i = 0;
            int j = 2;
            while (it.hasNext()) {
                Line line = it.next();
                this.positionLineData.put(line.getBufferVertices());
                this.colorLineData.put(line.getBufferColor());
                startsLine.put(i);
                countsLine.put(j);
                i = i + line.getBufferIndicesSize();
                j = j + line.getBufferIndicesSize();
            }
            this.positionLineData.rewind();
            this.colorLineData.rewind();
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(2));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.lines.get(0).sizeofBufferVertices() *
                        this.lines.size() * BufferUtil.SIZEOF_FLOAT,
                    positionLineData,
                    gl.GL_STATIC_DRAW);
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(3));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.lines.get(0).sizeofBufferColor() *
                        this.lines.size() * BufferUtil.SIZEOF_FLOAT,
                    colorLineData,
                    gl.GL_STATIC_DRAW);
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
     
            this.startsLine.rewind();
            this.countsLine.rewind();
        }
     
        public void display(GLAutoDrawable drawable) {
            final GL gl = drawable.getGL();
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            gl.glClearColor(1, 1, 1, 0);
     
            gl.glMatrixMode(gl.GL_MODELVIEW);
            gl.glLoadIdentity();
            gl.glTranslatef(0, 0, zoom);
     
     
            gl.glLineWidth(2f);
     
            gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
            gl.glEnableClientState(GL.GL_COLOR_ARRAY);
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(1));
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
            gl.glMultiDrawArrays(gl.GL_QUADS, starts, counts, this.squares.size());
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(2));
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(3));
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
            gl.glMultiDrawArrays(gl.GL_LINES, startsLine, countsLine, this.lines.size());
     
            gl.glFlush();
        }
     
        public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
            final int maxZ = 1000;
            GL gl = drawable.getGL();
            gl.glViewport(0, 0, width, height);
            /*For the camera*/
            gl.glMatrixMode(gl.GL_PROJECTION);
            gl.glLoadIdentity();
            //Change this by glOrtho
            new GLU().gluPerspective(45., (float) width / height, 1., maxZ);
            /*Model & view*/
            gl.glMatrixMode(gl.GL_MODELVIEW);
            gl.glLoadIdentity();
        }
     
        public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
        }
     
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getWheelRotation() > 0) {
                zoom += 0.5;
            } else {
                zoom -= 0.5;
            }
        }
     
    }
     
    class Square{
     
        private final float side = 0.5f;
        private float x, y, z;
        final private byte[]indices = {0, 1, 2, 3};
        float[]coords;
        private int sizeOfBufferVertices;
        private FloatBuffer nodeVertices;
        private int sizeOfBufferColor;
        private FloatBuffer nodeColor;
        private ByteBuffer nodeIndices;
     
        public Square(float x, float y, float z){
            this.x = x;
            this.y = y;
            this.z = z;
            setCoordinates();
            setupNodeVerticesBuffer();
            setupNodeColorBuffer();
            setupNodeIndicesBuffer();
        }
     
        public FloatBuffer getBufferVertices(){
            return this.nodeVertices;
        }
     
        public int sizeofBufferVertices(){
            return this.sizeOfBufferVertices;
        }
     
        public FloatBuffer getBufferColor(){
            return this.nodeColor;
        }
     
        public int sizeofBufferColor(){
            return this.sizeOfBufferColor;
        }
     
        public int getBufferIndicesSize(){
            return this.indices.length;
        }
     
        private void setCoordinates(){
            coords = new float[12];
            coords[0] = x-side;
            coords[1] = y+side;
            coords[2] = z;
            coords[3] = x+side;
            coords[4] = y+side;
            coords[5] = z;
            coords[6] = x+side;
            coords[7] = y-side;
            coords[8] = z;
            coords[9] = x-side;
            coords[10] = y-side;
            coords[11] = z;
        }
     
        private void setupNodeVerticesBuffer(){
            int bufferVerticesSize = coords.length;
            this.sizeOfBufferVertices = bufferVerticesSize * BufferUtil.SIZEOF_FLOAT;
            nodeVertices = BufferUtil.newFloatBuffer(bufferVerticesSize);
            nodeVertices.put(coords);
            nodeVertices.rewind();
        }
     
        private void setupNodeColorBuffer(){
            float[]colorComponds = {1, 0, 0, 0};
            int bufferColorSize = colorComponds.length * this.indices.length;
            this.sizeOfBufferColor = bufferColorSize * BufferUtil.SIZEOF_FLOAT;
            float[]allColorComponds = new float[bufferColorSize];
            int j=0;
            for(int i=0; i<allColorComponds.length; i++){
                allColorComponds[i] = colorComponds[j++];
                if(j==colorComponds.length){
                    j=0;
                }
            }
            nodeColor = BufferUtil.newFloatBuffer(allColorComponds.
                    length);
            nodeColor.put(allColorComponds);
            nodeColor.rewind();
        }
     
        private void setupNodeIndicesBuffer(){
            nodeIndices = BufferUtil.newByteBuffer(this.indices.length);
            nodeIndices.put(this.indices);
            nodeIndices.rewind();
        }
     
    }
     
    class Line{
     
        private float x0, y0, z0;
        private float x1, y1, z1;
        final private byte[]indices = {0, 1};
        float[]coords;
        private int sizeOfBufferVertices;
        private FloatBuffer nodeVertices;
        private int sizeOfBufferColor;
        private FloatBuffer nodeColor;
        private ByteBuffer nodeIndices;
     
        public Line(float x0, float y0, float z0, float x1, float y1, float z1){
            this.x0 = x0;
            this.y0 = y0;
            this.z0 = z0;
            this.x1 = x1;
            this.y1 = y1;
            this.z1 = z1;
            setCoordinates();
            setupNodeVerticesBuffer();
            setupNodeColorBuffer();
            setupNodeIndicesBuffer();
        }
     
        public FloatBuffer getBufferVertices(){
            return this.nodeVertices;
        }
     
        public int sizeofBufferVertices(){
            return this.sizeOfBufferVertices;
        }
     
        public FloatBuffer getBufferColor(){
            return this.nodeColor;
        }
     
        public int sizeofBufferColor(){
            return this.sizeOfBufferColor;
        }
     
        public int getBufferIndicesSize(){
            return this.indices.length;
        }
     
        private void setCoordinates(){
            coords = new float[6];
            coords[0] = x0;
            coords[1] = y0;
            coords[2] = z0;
            coords[3] = x1;
            coords[4] = y1;
            coords[5] = z1;
        }
     
        private void setupNodeVerticesBuffer(){
            int bufferVerticesSize = coords.length;
            this.sizeOfBufferVertices = bufferVerticesSize * BufferUtil.SIZEOF_FLOAT;
            nodeVertices = BufferUtil.newFloatBuffer(bufferVerticesSize);
            nodeVertices.put(coords);
            nodeVertices.rewind();
        }
     
        private void setupNodeColorBuffer(){
            float[]colorComponds = {0, 0, 1, 0};
            int bufferColorSize = colorComponds.length * this.indices.length;
            this.sizeOfBufferColor = bufferColorSize * BufferUtil.SIZEOF_FLOAT;
            float[]allColorComponds = new float[bufferColorSize];
            int j=0;
            for(int i=0; i<allColorComponds.length; i++){
                allColorComponds[i] = colorComponds[j++];
                if(j==colorComponds.length){
                    j=0;
                }
            }
            nodeColor = BufferUtil.newFloatBuffer(allColorComponds.
                    length);
            nodeColor.put(allColorComponds);
            nodeColor.rewind();
        }
     
        private void setupNodeIndicesBuffer(){
            nodeIndices = BufferUtil.newByteBuffer(this.indices.length);
            nodeIndices.put(this.indices);
            nodeIndices.rewind();
        }
     
    }
    Si les admins veulent le mettre sur la partie "sources", pas de soucis

    @++

  10. #10
    Expert confirmé
    Avatar de GLDavid
    Homme Profil pro
    Service Delivery Manager
    Inscrit en
    Janvier 2003
    Messages
    2 865
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Service Delivery Manager
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 865
    Points : 4 862
    Points
    4 862
    Par défaut
    Hello

    Suite à une erreur repérée voici le même code sans l'erreur (provoquant du parasitage sur de hauts nombre de géomtries):

    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
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
     
    import com.sun.opengl.util.Animator;
    import com.sun.opengl.util.BufferUtil;
    import java.awt.BorderLayout;
    import java.awt.event.MouseWheelEvent;
    import java.awt.event.MouseWheelListener;
    import java.nio.ByteBuffer;
    import java.nio.FloatBuffer;
    import java.nio.IntBuffer;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    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;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /**
     *
     * @author dbourgais
     */
    public class MultiObjectVBO {
     
        public static void main(String[]args){
            GLCanvas canvas = new GLCanvas();
            MultiOVBOTest demo = new MultiOVBOTest();
            canvas.addGLEventListener(demo);
     
            final Animator animator = new Animator(canvas);
            animator.start();
     
            JFrame frame = new JFrame("MultiObjectVBO");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new BorderLayout());
            canvas.setSize(400, 400);
            frame.add(canvas, BorderLayout.CENTER);
            frame.pack();
            frame.setVisible(true);
            canvas.requestFocus();
        }
     
    }
     
    class MultiOVBOTest implements GLEventListener, MouseWheelListener {
     
        private float zoom = -20;
        private List<Square>squares;
        private List<Line>lines;
        private float[]centers = {
            -5, 5, 0,
            5, 5, 0,
            5, -5, 0,
            -5, -5, 0
        };
        private float[]dots = {
            -5, 5, 0, 5, -5, 0,
            5, 5, 0, -5, -5, 0
        };
        private IntBuffer bufferName;
        private FloatBuffer positionData;
        private FloatBuffer colorData;
        private IntBuffer starts;
        private IntBuffer counts;
        private FloatBuffer positionLineData;
        private FloatBuffer colorLineData;
        private IntBuffer startsLine;
        private IntBuffer countsLine;
        private final int LIMIT = 4;
     
        public MultiOVBOTest(){
            squares = new ArrayList<Square>();
            lines = new ArrayList<Line>();
            for(int i=0; i<centers.length; i+=3){
                squares.add(new Square(centers[i], centers[i+1], centers[i+2]));
            }
            for(int i=0; i<dots.length; i+=6){
                lines.add(new Line(dots[i], dots[i+1], dots[i+2], dots[i+3], dots[i+4], dots[i+5]));
            }
            this.bufferName = BufferUtil.newIntBuffer(LIMIT);
        }
     
        public void init(GLAutoDrawable drawable) {
            final GL gl = drawable.getGL();
     
            drawable.addMouseWheelListener(this);
     
            gl.glShadeModel(gl.GL_SMOOTH);
            gl.glEnable(gl.GL_DEPTH_TEST);
     
            gl.glGenBuffers(LIMIT, bufferName);
     
            int constant = squares.size() * BufferUtil.SIZEOF_FLOAT;
            this.positionData = BufferUtil.newFloatBuffer(12 * constant);
            this.colorData = BufferUtil.newFloatBuffer(4 * constant);
            this.starts = BufferUtil.newIntBuffer(squares.size());
            this.counts = BufferUtil.newIntBuffer(squares.size());
     
            constant = lines.size() * BufferUtil.SIZEOF_FLOAT;
            this.positionLineData = BufferUtil.newFloatBuffer(6 * constant);
            this.colorLineData = BufferUtil.newFloatBuffer(4 * constant);
            this.startsLine = BufferUtil.newIntBuffer(lines.size());
            this.countsLine = BufferUtil.newIntBuffer(lines.size());
     
            pushNodesDataBuffers(gl);
            pushLinesDataBuffers(gl);
        }
     
        private void pushNodesDataBuffers(final GL gl){
            Iterator<Square> it = this.squares.iterator();
            int i = 0;
            int j = 4;
            while (it.hasNext()) {
                Square square = it.next();
                this.positionData.put(square.getBufferVertices());
                this.colorData.put(square.getBufferColor());
                starts.put(i);
                counts.put(j);
                i = i + square.getBufferIndicesSize();
                j = square.getBufferIndicesSize();
            }
            this.positionData.rewind();
            this.colorData.rewind();
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            gl.glBufferData(gl.GL_ARRAY_BUFFER, 
                    this.squares.get(0).sizeofBufferVertices() *
                        this.squares.size() * BufferUtil.SIZEOF_FLOAT,
                    positionData,
                    gl.GL_STATIC_DRAW);
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(1));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.squares.get(0).sizeofBufferColor() *
                        this.squares.size() * BufferUtil.SIZEOF_FLOAT,
                    colorData,
                    gl.GL_STATIC_DRAW);
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
     
            this.starts.rewind();
            this.counts.rewind();
        }
     
        private void pushLinesDataBuffers(final GL gl){
            Iterator<Line> it = this.lines.iterator();
            int i = 0;
            int j = 2;
            while (it.hasNext()) {
                Line line = it.next();
                this.positionLineData.put(line.getBufferVertices());
                this.colorLineData.put(line.getBufferColor());
                startsLine.put(i);
                countsLine.put(j);
                i = i + line.getBufferIndicesSize();
                j = line.getBufferIndicesSize();
            }
            this.positionLineData.rewind();
            this.colorLineData.rewind();
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(2));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.lines.get(0).sizeofBufferVertices() *
                        this.lines.size() * BufferUtil.SIZEOF_FLOAT,
                    positionLineData,
                    gl.GL_STATIC_DRAW);
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
     
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(3));
            gl.glBufferData(gl.GL_ARRAY_BUFFER,
                    this.lines.get(0).sizeofBufferColor() *
                        this.lines.size() * BufferUtil.SIZEOF_FLOAT,
                    colorLineData,
                    gl.GL_STATIC_DRAW);
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
     
            this.startsLine.rewind();
            this.countsLine.rewind();
        }
     
        public void display(GLAutoDrawable drawable) {
            final GL gl = drawable.getGL();
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            gl.glClearColor(1, 1, 1, 0);
     
            gl.glMatrixMode(gl.GL_MODELVIEW);
            gl.glLoadIdentity();
            gl.glTranslatef(0, 0, zoom);
     
     
            gl.glLineWidth(2f);
     
            gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
            gl.glEnableClientState(GL.GL_COLOR_ARRAY);
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(0));
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(1));
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
            gl.glMultiDrawArrays(gl.GL_QUADS, starts, counts, this.squares.size());
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(2));
            gl.glVertexPointer(3, gl.GL_FLOAT, 0, 0);
            gl.glBindBuffer(gl.GL_ARRAY_BUFFER, bufferName.get(3));
            gl.glColorPointer(4, gl.GL_FLOAT, 0, 0);
            gl.glMultiDrawArrays(gl.GL_LINES, startsLine, countsLine, this.lines.size());
     
            gl.glFlush();
        }
     
        public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
            final int maxZ = 1000;
            GL gl = drawable.getGL();
            gl.glViewport(0, 0, width, height);
            /*For the camera*/
            gl.glMatrixMode(gl.GL_PROJECTION);
            gl.glLoadIdentity();
            //Change this by glOrtho
            new GLU().gluPerspective(45., (float) width / height, 1., maxZ);
            /*Model & view*/
            gl.glMatrixMode(gl.GL_MODELVIEW);
            gl.glLoadIdentity();
        }
     
        public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
        }
     
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getWheelRotation() > 0) {
                zoom += 0.5;
            } else {
                zoom -= 0.5;
            }
        }
     
    }
     
    class Square{
     
        private final float side = 0.5f;
        private float x, y, z;
        final private byte[]indices = {0, 1, 2, 3};
        float[]coords;
        private int sizeOfBufferVertices;
        private FloatBuffer nodeVertices;
        private int sizeOfBufferColor;
        private FloatBuffer nodeColor;
        private ByteBuffer nodeIndices;
     
        public Square(float x, float y, float z){
            this.x = x;
            this.y = y;
            this.z = z;
            setCoordinates();
            setupNodeVerticesBuffer();
            setupNodeColorBuffer();
            setupNodeIndicesBuffer();
        }
     
        public FloatBuffer getBufferVertices(){
            return this.nodeVertices;
        }
     
        public int sizeofBufferVertices(){
            return this.sizeOfBufferVertices;
        }
     
        public FloatBuffer getBufferColor(){
            return this.nodeColor;
        }
     
        public int sizeofBufferColor(){
            return this.sizeOfBufferColor;
        }
     
        public int getBufferIndicesSize(){
            return this.indices.length;
        }
     
        private void setCoordinates(){
            coords = new float[12];
            coords[0] = x-side;
            coords[1] = y+side;
            coords[2] = z;
            coords[3] = x+side;
            coords[4] = y+side;
            coords[5] = z;
            coords[6] = x+side;
            coords[7] = y-side;
            coords[8] = z;
            coords[9] = x-side;
            coords[10] = y-side;
            coords[11] = z;
        }
     
        private void setupNodeVerticesBuffer(){
            int bufferVerticesSize = coords.length;
            this.sizeOfBufferVertices = bufferVerticesSize * BufferUtil.SIZEOF_FLOAT;
            nodeVertices = BufferUtil.newFloatBuffer(bufferVerticesSize);
            nodeVertices.put(coords);
            nodeVertices.rewind();
        }
     
        private void setupNodeColorBuffer(){
            float[]colorComponds = {1, 0, 0, 0};
            int bufferColorSize = colorComponds.length * this.indices.length;
            this.sizeOfBufferColor = bufferColorSize * BufferUtil.SIZEOF_FLOAT;
            float[]allColorComponds = new float[bufferColorSize];
            int j=0;
            for(int i=0; i<allColorComponds.length; i++){
                allColorComponds[i] = colorComponds[j++];
                if(j==colorComponds.length){
                    j=0;
                }
            }
            nodeColor = BufferUtil.newFloatBuffer(allColorComponds.
                    length);
            nodeColor.put(allColorComponds);
            nodeColor.rewind();
        }
     
        private void setupNodeIndicesBuffer(){
            nodeIndices = BufferUtil.newByteBuffer(this.indices.length);
            nodeIndices.put(this.indices);
            nodeIndices.rewind();
        }
     
    }
     
    class Line{
     
        private float x0, y0, z0;
        private float x1, y1, z1;
        final private byte[]indices = {0, 1};
        float[]coords;
        private int sizeOfBufferVertices;
        private FloatBuffer nodeVertices;
        private int sizeOfBufferColor;
        private FloatBuffer nodeColor;
        private ByteBuffer nodeIndices;
     
        public Line(float x0, float y0, float z0, float x1, float y1, float z1){
            this.x0 = x0;
            this.y0 = y0;
            this.z0 = z0;
            this.x1 = x1;
            this.y1 = y1;
            this.z1 = z1;
            setCoordinates();
            setupNodeVerticesBuffer();
            setupNodeColorBuffer();
            setupNodeIndicesBuffer();
        }
     
        public FloatBuffer getBufferVertices(){
            return this.nodeVertices;
        }
     
        public int sizeofBufferVertices(){
            return this.sizeOfBufferVertices;
        }
     
        public FloatBuffer getBufferColor(){
            return this.nodeColor;
        }
     
        public int sizeofBufferColor(){
            return this.sizeOfBufferColor;
        }
     
        public int getBufferIndicesSize(){
            return this.indices.length;
        }
     
        private void setCoordinates(){
            coords = new float[6];
            coords[0] = x0;
            coords[1] = y0;
            coords[2] = z0;
            coords[3] = x1;
            coords[4] = y1;
            coords[5] = z1;
        }
     
        private void setupNodeVerticesBuffer(){
            int bufferVerticesSize = coords.length;
            this.sizeOfBufferVertices = bufferVerticesSize * BufferUtil.SIZEOF_FLOAT;
            nodeVertices = BufferUtil.newFloatBuffer(bufferVerticesSize);
            nodeVertices.put(coords);
            nodeVertices.rewind();
        }
     
        private void setupNodeColorBuffer(){
            float[]colorComponds = {0, 0, 1, 0};
            int bufferColorSize = colorComponds.length * this.indices.length;
            this.sizeOfBufferColor = bufferColorSize * BufferUtil.SIZEOF_FLOAT;
            float[]allColorComponds = new float[bufferColorSize];
            int j=0;
            for(int i=0; i<allColorComponds.length; i++){
                allColorComponds[i] = colorComponds[j++];
                if(j==colorComponds.length){
                    j=0;
                }
            }
            nodeColor = BufferUtil.newFloatBuffer(allColorComponds.
                    length);
            nodeColor.put(allColorComponds);
            nodeColor.rewind();
        }
     
        private void setupNodeIndicesBuffer(){
            nodeIndices = BufferUtil.newByteBuffer(this.indices.length);
            nodeIndices.put(this.indices);
            nodeIndices.rewind();
        }
     
    }
    @++

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 10/10/2014, 10h10
  2. afficher des informations différentes aux utilisateurs anonymes et connectés
    Par Kirikou12 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 6
    Dernier message: 09/05/2012, 11h26
  3. [WD11] Affiché des données différents dans une cellule d'une table
    Par teledeclaration dans le forum WinDev
    Réponses: 11
    Dernier message: 15/08/2010, 10h27
  4. Réponses: 2
    Dernier message: 07/06/2007, 16h07

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