8

I have this line: Gdx.gl10.glLineWidth(width); Now, I do intend to draw a pretty thick line, and, unfortunately when I type in small values like 1 or 5 the line is obviously small. But once I surpass soemthing like 10, it no longer gets larger. I am passing in direct values in these instances, and so, I am under the impression that GL has a limit or something.... Would I be correct? Here's my code:

Gdx.gl.glClearColor(0,0,0,1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    batch.setProjectionMatrix(cam.combined);
    batch.begin();
    batch.draw(bg,0,0,WIDTH,HEIGHT);
    for(Spell a : spells){
        a.draw(batch);
    }
    lc.draw(batch);
    batch.end();
    //((ppux+ppuy)/2f)*4
    Gdx.gl10.glLineWidth(50);//average and then say 1/4 a unit)
    renderer.setProjectionMatrix(cam.combined);
    renderer.begin(ShapeType.Line);
    lp.drawLines(renderer);
    renderer.end();
    batch.begin();
    lp.draw(batch);
    batch.end();

lp.drawLines(renderer) calls the following(I just call set color, and draw line):

renderer.setColor(1,1,1,1);
    Elem a = elems.get(spellcombo.get(0));
    Vector2 last = new Vector2(a.x(),a.y());
    for(int i = 1; i < spellcombo.size(); i++){
        a = elems.get(spellcombo.get(i));
        Vector2 cur = new Vector2(a.x(),a.y());
        renderer.line(last.x, last.y, cur.x, cur.y);
        last = cur;
    }
    renderer.line(last.x,last.y,mx,my);
    Gdx.gl.glEnable(GL10.GL_BLEND);
    Gdx.gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    renderer.setColor(1, 0, 0, .2f);
    for(Elem e : elems){
        int id = elems.indexOf(e);
        if(ComboManager.validSpell(spellcombo,id))
            renderer.line(last.x,last.y,e.x(),e.y());
    }

Screenshots:
Image with glLineWidth() set to 1 Image with glLineWidth() set to 1 Image with glLineWidth() set to 5 Image with glLineWidth() set to 5 Image with glLineWidth() set to 10 Image with glLineWidth() set to 10 Image with glLineWidth() set to 20 Image with glLineWidth() set to 20 Image with glLineWidth() set to 200 Image with glLineWidth() set to 200

I don't really know how to fix, and google wasn't particularily helpfull. Thanks!

csga5000
  • 4,062
  • 4
  • 39
  • 52
  • 1
    OpenGL docs "Not all widths can be supported when line antialiasing is enabled. If an unsupported width is requested, the nearest supported width is used." – arynaq May 21 '13 at 23:41
  • Libgdx is an openGL wrapper on most operating systems(I think theres one or two on which it's not... could be wrong) Ok, cool, have you any idea how I would turn it of using libgdx? I haven't seen anything under Gdx.gl10, which is where most stuff like that is, and google hasn't shown me much of anything, except for something in the android launcher(these screenshots were taken from Desktop) and I don't even know if that would work.. – csga5000 May 22 '13 at 00:26
  • 1
    No unfortuntately I don't, just wanted to point out the docs describe the behavior you are seeing ,it is intended for some reason. You could draw a rectangle, it is essentially a line with a given width. – arynaq May 22 '13 at 00:43
  • Yeah, but it's rotated. Obviously I could probably rotate it using tan, but, still, I like the idea of just using a line. We'll see if anyone can help me, otherwise, I might have to rotate a rectange. Anyway, thanks! – csga5000 May 22 '13 at 01:32

2 Answers2

6

From libgdx 1.0 on there is also the ShapeRenderer's rectLine method available. See a simple example.

ShapeRenderer shapeRenderer = new ShapeRenderer();
shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.rectLine(x1, y1, x2, y2, width);
shapeRenderer.end();

That seems to be the easiest way to draw thick lines now.

donfuxx
  • 11,277
  • 6
  • 44
  • 76
  • 1
    Life saver! for drawing diagonal thick lines which can,t be achieved using rectangles.or polygon using shape renderer class only. – kingAm Jul 05 '15 at 11:10
3

In Libgdx the Gdx.gl10 object is the wrapper for the OpenGL 1.x API. So, the calls there are all (basically) calls into OpenGL ES (on Android) or regular OpenGL (on the desktop). Sometimes the Java layer makes changes to the API, but generally its a pretty straightforward mapping. (On the Desktop, Libgdx tries to emulate the ES variant so the API presented contains only ES-relevant APIs.)

The line-drawing support in OpenGL ES is one place where ES changes from regular OpenGL. Both have limitations on supported line width, though in regular OpenGL the limitations seem to apply only to anti-aliased lines.

Regular OpenGL

http://www.opengl.org/sdk/docs/man/xhtml/glLineWidth.xml

There is a range of supported line widths. Only width 1 is guaranteed to be supported; others depend on the implementation. To query the range of supported widths, call glGet with argument GL_ALIASED_LINE_WIDTH_RANGE.

OpenGL ES

http://www.khronos.org/opengles/sdk/docs/man/xhtml/glLineWidth.xml

There is a range of supported line widths. Only width 1 is guaranteed to be supported; others depend on the implementation. To query the range of supported widths, call glGet with argument GL_ALIASED_LINE_WIDTH_RANGE.

To query the limits in Libgdx, use something like this:

int[] results = new int[1];
Gdx.gl10.glGetIntegerv(GL20.GL_ALIASED_LINE_WIDTH_RANGE, results, 0); 

The upshot of all of this though, is that because line drawing (other than width 1.0) on OpenGL ES has different run-time limitations on different platforms, you probably should use a different scheme (like rectangles) to draw fat lines.

P.T.
  • 24,557
  • 7
  • 64
  • 95
  • Alright thanks tons. So I would use renderer.rotate(point1XYZ,angleToPoint2) And then draw a rect from point1 to the right with a length of distanceToPoint2, and a given width? – csga5000 May 22 '13 at 22:44