Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
263 views
in Technique[技术] by (71.8m points)

java - Libgdx gl10.glLineWidth()

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...