BTW, your whole logic is wrong, sorry I just noticed it now.
Sorry, it's hard to explain, there are fundamental flaws in your program.
OpenGL is not like DOS and EGA/VGA etc, where you can paint over-and over the scene and it will remain there like a canvas and everything will instantly get drawn on it. In OpenGL, commands are buffered, so you have to insert glFlush/glFinnish to force openGL to actually draw the stuff on the screen. Or you have to swap the buffers if you have double-buffer. Which you have (at least you use swappbuffers).
BUT:
You shouldn't (or better: mustn't) mix rendering with logic. You have rendering in your mouse handler logic, and you have logic stuff (reading and converting mouse coordinates) in your rendering. This thing can entirely screw rendering and logic, maybe it only works by accident in your case (we should see the WindProc to decide).
Frankly, the rendering and the logic is scattered all over the place, it's very hard to follow the program flow.
So:
Store the transformed (world) coordinates in a vector where you clicked with the mouse, then in the renderer, render the scene with the lines (you read the coordinates from the vector).
The most important thing is to decouple the logic from the render.
Maybe it's not clear at all, but honestly there are so many flaws in your program that it would be easier just to write the program for you than to explain it.
A note for rendering the lines: you should disable writing to the depth buffer (
glDepthMask(false) ) so that you don't read the depth values of an already drawn line (unless you want that of course, but I doubt it).
Other problems: with lines, it's pretty much useless to use lighting. Lighting doesn't make things 3D as the comment in your code suggests. Maybe you copied it from a sloppy tutorial. Lighting makes the scene
look 3D, if there are polygons. Lighting requires normals. You don't specify any normals, and how would you do for lines anyway? This may cause that the lines you draw are black, since 0,0,0 is the default value of a normal (since the normals' coordinates are state variables, unlike vertex coordinates).
Maybe you are doing too much things at once. The thing you want to do is not the most beginner openGL topic IMHO, but you do seem like a total beginner (I'm sorry if I sound harsh).
Edited by szecs, 23 May 2012 - 12:31 AM.