using mouse cursor to draw lines

Hi I wonder how I could use the mouse cursor to draw lines - I know you have to use the gdi to implement this but how could I incorporate this in an opengl program - has anyone done anything like this - any example programs

cheers

YOu can certainyl use OpenGl to draw lines. All you have to do is tell it where to draw them . Get the location of the mouse, convert it into whatever coordinate system you are using, and draw away.

Chris

Originally posted by chennes:
[b]YOu can certainyl use OpenGl to draw lines. All you have to do is tell it where to draw them . Get the location of the mouse, convert it into whatever coordinate system you are using, and draw away.

Chris[/b]

Would this be interactive? also any code samples of how I can set up the mouse to draw lines - I know how to do it using the gdi but I need to know how to do it in opengl

thanx

The problem you’re having (im fairly certain) is converting the 2d points that your mouse is at to 3d points in your world (with ajustments for different panning, view angles, etc)… below is a good peice of code to get started, the idea all lies behind the glUnproject() function… its tricky but with tinkering you can get the desired effect.
http://www.codeguru.com/opengl/zooming.shtml

Nat

or you can just set up an ortho projection matrix that maps window coords to opengl coords.

GoatNat: How would this work with perspective view?

cheers

Hi

I’ve used the example above - I can get lines to show up but not where I’m drawing them - also the lines disappear, how can I get then to stay - and if I wanted to delete say the last line how would I do this?

cheers

Originally posted by fox:
[b]Hi

I’ve used the example above - I can get lines to show up but not where I’m drawing them - also the lines disappear, how can I get then to stay - and if I wanted to delete say the last line how would I do this?

cheers [/b]

You have to store the coordinates of the edge points in a data structure e.g. a list or an array. Then when you draw the scene in the main app, loop through the points and draw them using glBegin(GL_LINE_LOOP).

If you want to delete a line, just remove the last point from your data storage and wait for redrawing.

You can use gluUnProject(…) to convert mouse coordinates into world coordinates when a mouse click occurs.

If you are interested, I did a program with a similar problem of getting mouse coordinates into points and drawing lines. You can mail me, and I will send you the program and the code.

Bye

yes, i’ve e-mailed you scott