6

I want to draw a line and then generate a texture (with libgdx). I found out that creating a texture from circles, rectangles and lines is simple with pixmap. But I didn't find out how to set the linewidth of the drawn shape. Is there any possibility to set the linewidth for pixmap?

Here is the code I got so far: (I tried to draw two filled circles and to connect them with a line)

Pixmap pixmap = new Pixmap( 16, 16, Format.RGBA8888 );
pixmap.setColor(Color.BLUE);
pixmap.fillCircle(x1, y1, 10);
pixmap.fillCircle(x2, y2, 10);
pixmap.drawLine(x2, y2, x1, y1); // this line is very thin
Texture pixmaptex = new Texture( pixmap );
pixmap.dispose();
Daahrien
  • 10,190
  • 6
  • 39
  • 71
IstaLibera
  • 580
  • 5
  • 22
  • possible duplicate of [Libgdx gl10.glLineWidth()](http://stackoverflow.com/questions/16680908/libgdx-gl10-gllinewidth) – P.T. Dec 07 '13 at 16:50

1 Answers1

2

Linewidth isn't reliably supported by OpenGL implementations. To draw "fat" lines, draw a rectangle.

See Libgdx gl10.glLineWidth()

Community
  • 1
  • 1
P.T.
  • 24,557
  • 7
  • 64
  • 95
  • But for a rectangle I just can specify the x and y coordinates for the first corner - I somehow want to draw a "fat" line between two coordinates. – IstaLibera Dec 07 '13 at 17:13
  • Yeah, its a bit more work. You need to offset the rectangle such that the point you want is in the middle of the rectangle. And you'll need compute the rotation and supply that. See http://stackoverflow.com/questions/7854043/drawing-rectangle-between-two-points-with-arbitrary-width – P.T. Dec 07 '13 at 17:55
  • Thanks for the help. I solved my task using a FrameBuffer instead of the Pixmap (already answered here: http://stackoverflow.com/questions/20095957/libgdx-draw-bitmapfont-to-intermediate-location-spritebatch – IstaLibera Dec 08 '13 at 09:54