Thickness of DrawNode line?

I m using v3.3, eclipse, android

I tried stackoverflow also but didn’t get the solution.

1) To make line thick
Some suggested to use glLineWidth(5); but it didn’t help
Any workable solution when I am usingg DrawNode::create() API to draw a line.

2) Also, for me this line is not getting smooth.
Again I searched the forums and stackoverflow but didn’t get solution.
Also, I followed Line Primitives Look Terrible, Smooth Lines? but didn’t help.

  1. Use DrawNode::drawSegment() This takes a radius (width) parameter.
  2. I have a fix for this. I will post it shortly.

I think you also need to multiply by content scale factor.
glLineWidth(3.0 * CC_CONTENT_SCALE_FACTOR());

No didn’t help.

Here is my code.

Color3B clr = Color3B::MAGENTA;
Color4F clrb = Color4F(clr);
glLineWidth(5.0 * CC_CONTENT_SCALE_FACTOR());
DrawNode *ln = DrawNode::create();
ln->drawLine(Vec2(300,200),Vec2(500,300),clrb);
this->addChild(ln);

And as @code_game_chef said, only plain simple rough line is being drawn

I am not sure whether it is the issue of different versions of openGL.
But whatever, it would have been a lot better if cocos2d-x would have provided arguments for setting width and smoothness boolean.
AFAIK, cocos2dJS draw API functions didn’t create any problem.

@siddharthshekar

I also tried and it was same as earlier.

@IslandPlaya

I tried your post at

Sorry, you told that it should work but for me it is same as before.

@catch_up
Are you making any other changes too?
Just see above post in case it workds for you and please reply if it works.

Using drawSeqment with radius should work for you. Note that glLineWidth needs to be called only within the customCommand callback (like DrawNode’s onDrawXXXX methods) or just before glDrawXXXX methods are called (see: onDrawGLLine method in DrawNode.cpp).

Color3B clr = Color3B::MAGENTA;
Color4F clrb = Color4F(clr);
float lineWidth = 5.0 * CC_CONTENT_SCALE_FACTOR();
// has no affect here
//glLineWidth(lineWidth);
DrawNode *ln = DrawNode::create();
ln->drawSegment(Vec2(300,200), Vec2(500,300), lineWidth, clrb);
this->addChild(ln);

Yes, you’re correct. Actually glLineWidth works not independently but along with the other variables defined in that like buffer count and other things. So that is why it was not making impact at the position I used it.

And I don’t think so that this would be necessary to put inside callback. I am not sure of the other way though.

@code_game_chef

Yeah, I did some changes according to @IslandPlaya post and it made the lines satisfactory smooth lines. And I used drawSegment as he told.
Note that they cannot be further smoothen because I guess that depends upon the resolution.
But they are quite good.

@stevetranby
I was just wondering if there is a way to make a line between 2 points but not all of a sudden but
in animation where line has started from one of the points and moving towards the other?
What do you think could be the efficient way for this?

Well I use a custom action “ResizeTo” that expands a LayerColor. You’ll probably have to create your own animation with a scheduled update that draws on top or clears and redraws the DrawNode. There are a two ways I can think of. The first would be keep track of animation and redraw DrawNode every frame. The other idea would be to cut your segments into further segments.

So if you have 5 segments for a line you might break that into 25 sub-fragments. Then you could draw them in order from start to end one segment per update loop. If you redraw everything it’s similar except instead of 5 segments per line you would just draw the last visible segment with shorter width/height.

So the redraw would likely be the most fluid since you could have every update call expand the last visible segment in 1px increments. I don’t think this would be a hit on performance since it should only be a clear on the vector and re-drawing only a few segments (verts) into the buffer.

I’m sure there are other means. If you’re making a drawing app or something with extensive use of this then creating your own custom DrawNode would be the better way to go since you could manage everything and write out to OpenGL directly.