drawing lines

Hi

I trying to use the mouse cursor to draw lines on the floor in opengl
the code below draws the grid on the floor
[ccode]
glBegin(GL_POINTS);
for(GLfloat vertx=-20.0; vertx <=20.0; vertx +=0.25)
for(GLfloat horz=-20.0; horz <=20.0; horz +=0.25)
{
glVertex3d(vertx,-3.0, horz);
glVertex3d(vertx,-3.0, horz);
}
glEnd();
[/ccode]

what I need is a function which will draw, display and store the lines drawn - I know that I have to use gluProject/gluUnproject to select the dots but how do I set about creating an array structure to store the lines?

cheers

There are two basic approaches. The first is vector-based (like a drawing program) and the second is raster-based (like a paint program).

The vector approach uses connected lines or curves constructed from the sample of mouse points. For lines, just use glBegin(GL_LINES), assuming you want the path connected. Since OpenGL is an immediate-mode environment, all geometry and state changes must be submitted every frame (well, for the most part). If your geometry and state changes don’t change between frames, then you can use a display list to store them, but it sounds like your trying to write a 3D drawing program that allows the user to draw lines on surfaces, in which case the geometry would change frequently (making display lists useless). So, you’ll need to store the lines’ vertices in your own data structure.

The raster approach uses dynamic textures, and is more akin to a paint program’s pixels than a drawing program’s objects (i.e. lines, polygons, etc). It’s basically what games like Quake do when you shoot at walls, leaving a mark. The bullet hole is overlayed over the wall’s texture, essentially painting the bullet hole onto the wall. So, in your app when the user draws on the floor, you can either dynamically update the floor’s texture (if there is one) or update a transparent texture overlaid over the floor, making opaque the pixels where the user has dragged. Your data structure in this case is simply the texture’s pixels.

There are two basic approaches. The first is vector-based (like a drawing program) and the second is raster-based (like a paint program).

The vector approach uses connected lines or curves constructed from the sample of mouse points. For lines, just use glBegin(GL_LINES), assuming you want the path connected. Since OpenGL is an immediate-mode environment, all geometry and state changes must be submitted every frame (well, for the most part). If your geometry and state changes don’t change between frames, then you can use a display list to store them, but it sounds like your trying to write a 3D drawing program that allows the user to draw lines on surfaces, in which case the geometry would change frequently (making display lists useless). So, you’ll need to store the lines’ vertices in your own data structure.

The raster approach uses dynamic textures, and is more akin to a paint program’s pixels than a drawing program’s objects (i.e. lines, polygons, etc). It’s basically what games like Quake do when you shoot at walls, leaving a mark. The bullet hole is overlayed over the wall’s texture, essentially painting the bullet hole onto the wall. So, in your app when the user draws on the floor, you can either dynamically update the floor’s texture (if there is one) or update a transparent texture overlaid over the floor, making opaque the pixels where the user has dragged. Your data structure in this case is simply the texture’s pixels.

yes, I think I need the vector based line drawing application

how can I set a data structure for it

cheers

any examples/ sample code?