Lines and Index Buffers

Hi Folks,

I am trying to create a series of line segments using a small number of points and a larger number of segments.  It seems like I should be able to specify the vertices using a vertex buffer and the connectivity using an index buffer.  It appears, though, that I can specify no more indices than the number of vertices I have.

The following simple code example illustrates the issue.  I have 4 vertices and want to draw 3 segments between them.  I specify this by setting the index buffer to 0, 1, 2, 3, 1, 2.  However, I only get segments from 0 to 1 and 2 to 3.  Is there a way to get all 3 segments to show up without having to repeat vertices?

package sandbox;

import java.nio.*;

import com.jme.renderer.ColorRGBA;
import com.jme.scene.Line;
import com.jme.scene.state.MaterialState;
import com.jme.util.geom.BufferUtils;

public class LineTest extends SimpleGame
    protected void simpleInitGame()
        Line foo = new Line("LINE");
        FloatBuffer vertices = BufferUtils.createVector3Buffer(4);
        //4 vertices
        vertices.put(new float[]{-1.0f, -1.0f, 0.0f});
        vertices.put(new float[]{ 1.0f, -1.0f, 0.0f});
        vertices.put(new float[]{ 1.0f,  1.0f, 0.0f});
        vertices.put(new float[]{-1.0f,  1.0f, 0.0f});
        IntBuffer indices = BufferUtils.createIntBuffer(6);
        //3 pairs--I want 3 segments, but I only get 2
        indices.put(new int[]{0, 1, 2, 3, 1, 2});
        foo.setVertexBuffer(0, vertices);
        foo.setIndexBuffer(indices, 0);
        MaterialState ms = display.getRenderer().createMaterialState();
    public static void main(String[] args)
        new LineTest().start();


the index buffers size has to be the size of the vertices as far as i know … if you want to draw a line from 1 to 4 over 2 and 3 your indes buffer is {0, 1, 2, 3}.

If you want to make better looking lines you could use the TrailMesh or Ribbon.



so long,

Hmm,actually that's a limit set in the renderer… we could probably change that

Yeah, that would be cool.  Right now I have to set every vertex in the vertex buffer (with many repeats) and then create an int array from [0, size-1], which is pretty pointless.  Thanks!

Should this get filed as a bug report, or is it more of a feature request?  Based on expected OpenGL vertex buffer behavior I would think this was a bug.

I've also problems with this.

Any change it will be fixed in SVN?