View Full Version : drawing a stroke

12-20-2009, 11:37 PM

Was wondering how I draw a stroke in 3D space using the mouse.
Currently I draw using gl_Line_Strip(with my own coding to make it follow the mouse motion path). The problem now is that I do not want to have only a line, because a line gives me only the x,y coordinates of every point through the line, but what I want is to have a stroke.

For example, the stroke is of 5 pixels wide and I draw it across 100 pixels. I want to have all the x,y coordinates within this 5*100 area.How to I achieve that.

Below is the code of the draw stroke method(current its just line). the draw drawstroke is called in display(), called by mouse drag events.

public void drawStroke(GL gl) {

if (startX == 999f) {
startX = tmpX;
startY = tmpY;
endX = (float) wcoord[0];
endY = (float) wcoord[1];


gl.glVertex3f(startX, startY,3.0f);
gl.glVertex3f(endX, endY,3.0f);
//System.out.println("Line draw at: "+ startX +", "+startY);
startX = endX;
startY = endY;



public void calObjectCoor(GL gl,float mousex,float mousey,float z) {

float x = mousex, y = mousey;

gl.glGetIntegerv(GL.GL_VIEWPORT, viewport,0);
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix,0);
gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);

/* note viewport[3] is height of window in pixels */
realy = viewport[3] - (int) y;
glu.gluUnProject((double) x, (double) realy, z, //
mvmatrix, 0,
projmatrix, 0,
viewport, 0,
wcoord, 0);

Actually Im working on the siggraph paper(modelling by examples). Any form of help on this topic would be greatly appreciated.