We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Simple Workaround for round line joins
Page Index Toggle Pages: 1
Simple Workaround for round line joins (Read 1085 times)
Simple Workaround for round line joins
May 5th, 2008, 7:10pm
 
I found a Workaround for Caps and Joins for lines in OpenGL by tom garden a few month back but it does not seem to be online anymore. Anyways I found a really simple way for round Joins.
Maybe its nothing new but I find it very useful:

Code:

import javax.media.opengl.*;
import processing.opengl.*;

PGraphicsOpenGL pgl;
GL gl;

int count = 10;
int[] xcoords = new int[count];
int[] ycoords = new int[count];
int[] zcoords = new int[count];

void setup(){
size(400, 400, OPENGL);
hint(ENABLE_OPENGL_4X_SMOOTH);
colorMode(RGB, 1.0, 1.0, 1.0);

pgl = (PGraphicsOpenGL) g;
gl = pgl.beginGL();

for(int i=0; i<count; i++){
xcoords[i] = (int) random(width);
ycoords[i] = (int) random(width);
zcoords[i] = (int) random(-200, 200);
}
}
void draw(){
background(1);
pgl.beginGL();
gl.glEnable(GL.GL_LINE_SMOOTH); //Antialiasing
gl.glEnable(GL.GL_LINE_STIPPLE);
gl.glHint (GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST);

gl.glEnable(GL.GL_POINT_SMOOTH); //This is important so that the joins are round

gl.glColor3f(0,0,0);
gl.glLineWidth(10); //line width and pointsize Should have the same value
gl.glPointSize(10.0);
gl.glRotatef(frameCount, 1,1,1);

//draw the lines
gl.glBegin(GL.GL_LINE_STRIP);
for(int i=1; i<count; i++){
//strokeWeight(10 * sin((HALF_PI / count) * i));
//line(xcoords[i], ycoords[i], zcoords[i], xcoords[i-1], ycoords[i-1], zcoords[i-1]);
gl.glVertex3f(xcoords[i], ycoords[i], zcoords[i]);
}
gl.glEnd();

//draw the round points as joins

gl.glBegin(GL.GL_POINTS);
for(int i=1; i<count; i++){
//strokeWeight(10 * sin((HALF_PI / count) * i));
//line(xcoords[i], ycoords[i], zcoords[i], xcoords[i-1], ycoords[i-1], zcoords[i-1]);
gl.glVertex3f(xcoords[i], ycoords[i], zcoords[i]);
}
gl.glEnd();
pgl.endGL();
}


if anybody knows a better way pls let me know.
Re: Simple Workaround for round line joins
Reply #1 - May 11th, 2008, 7:12am
 
Oi not bad. This can be incorporated into the SVG library as well. I remember reading Ben's post on strokeweights in 3D ("omg how do lines join in 3D") but I'm not sure if he's changed opinions on that.

What's the stipple for? I see no stippling in your lines.
Re: Simple Workaround for round line joins
Reply #2 - May 11th, 2008, 11:13am
 
I've played around with gl.glPointSize in the past and I don't think it's consistent across nVidia/ATI cards the maximum size you can go. So yo might encounter problems.
Re: Simple Workaround for round line joins
Reply #3 - May 11th, 2008, 11:36pm
 
mflux wrote on May 11th, 2008, 7:12am:
Oi not bad. This can be incorporated into the SVG library as well. I remember reading Ben's post on strokeweights in 3D ("omg how do lines join in 3D") but I'm not sure if he's changed opinions on that.

What's the stipple for I see no stippling in your lines.



I think I missed to delete that line Smiley
Re: Simple Workaround for round line joins
Reply #4 - May 16th, 2008, 6:31pm
 
Quote:
I've played around with gl.glPointSize in the past and I don't think it's consistent across nVidia/ATI cards the maximum size you can go. So yo might encounter problems.

Right you are - and on some cards, points don't show up at all (my old Powerbook G3 was one of those - my Macbook Pro now shows them fine, which is odd since those both have nVidia cards, just different ones).  Furthermore, in some cases they will show up, but only if the transform matrix is just right, and you'll get weird results if you try to render a grid of points - some will show up, some won't, it's all very confusing!

Implementations of points are so flaky and inconsistent in OpenGL that the functionality might as well not exist, which is a shame.
Re: Simple Workaround for round line joins
Reply #5 - May 20th, 2008, 7:57am
 
I understand that OpenGL features are not spread evenly throughout video-cards but isn't there a way we can simply implement this as a Processing call and simply draw the points manually using ellipse? How hard can that be?

Why not just make an ellipse, set it to a display list, and plop them out whenever you need a rounded join? Why bother, at all, with broken OpenGL commands?
Re: Simple Workaround for round line joins
Reply #6 - May 20th, 2008, 9:48am
 
sure that would be another way. anyways I found this article which might help. My main problem with lines is that the dont taper in space. Sure you could also do a workaround for that using line width but using triangle/quad Stips here is propably the better way to go. Anyways for people who want to work on getting line joins to work in OpenGL I can recommend this small article:

http://www.opengl.org/resources/code/samples/sig99/advanced99/notes/node281.html
Page Index Toggle Pages: 1