I have been trying to use glLineWidth to draw a line based on the mouse XY.
Using ofLine, when you increase glLineWidth over 1 the line is visibly made up of segments and not a continuous line.
This makes sense actually but I tried using this:
glBegin(GL_LINE_STRIP);
for (int i = 0; i < vx.size(); i++) {
glVertex2f(vx[i], vy[i]);
//vectors with the coordinates from the mouse
}
glEnd();
and still the same although GL_LINE_STRIP is supposed to draw a continuous strip I believe.
The black line is actually ofCurve taken from the SVN, which appears to do the same. I guess you guys might have something in mind for dealing with line widths? ofLineWidth perhaps?
one solution is to draw circles of different widths wherever the vertices are. This can help smooth things out.
I’m sure there are other solutions - I’ll look around for some mitering algorithms
another solution is this one, which takes an array of points (ofVec3f - you can find this in the ofAddons svn or on chris sugrue’s website) and calculates tangents to draw a quad strip. it smooths out the angles a bit because especially with mouse drawn graphics you get alot of 90 degree angle changes (and 45 degress, etc) because of the integer input system. the width of the line is stored in the “Z” component of the ofVec3f
(which holds x,y,z)… it’s not perfect, but it could look better then opengl…
Yeah its a little bit surprising actually. Even the suggestion to turn off depth testing does not make a difference.
I’ve got ofVec3f (from here right?), but am at a bit of a loss as to how to use it. Do you mind posting a quick example of how I get the X Y and Z into it?
Hunting around for someways to handle mitering I came across the 2d graphics library Cairo. Just looking through the samples it seems you can do some pretty nice 2d rendering with it and also output vector/raster files.
More info here. It is open-source, cross-platform… What do you think?