trying to draw a simple white 3d Line, prob :(

Guys, newbie member here.

I have a problem when trying to generate a 3d line in openGL and using C. I can draw simple 2d lines using

glVertex2f(x1,y1);
glVertex2f(x2,y2);

But when changeing it to 3d i.e using glVertex3f it doesnt want to draw.

I dont know what i am doing as such, i have afgair idea but not sure, i read that maybe i need to do something with a projection matrix maybe.

I hope i am clear and i thank anyone in advance for helping me out iwth this.

You do indeed have to do something with the projection matrix.
I think you’ll find NeHe useful.

When you use the 2 dimensional version of glVertex* the z dimension is there (as well as the w), it’s only 0. Try to look if your variables are of the correct type. I’m not sure if this could cause a problem but check it out. I mean don’t use:

int x1, y1, z1;
int x2, y2, z2;
// .. assign proper values to x1, y1, z1, etc.

glBegin(GL_LINES);
// Following lines might be wrong.
glVertex3f(x1, y1, z1);
glVertex3f(x2, y2, z2);
//Instead use
glVertex3i(x1, y1, z1);

…you get the picture. If you’re changing the z dimension of your lines, maybe you’re just drawing them outside of the view volume. I agree, with the post above, check out the link, or buy a good book on OpenGL if you can afford it.

ah ok, i think i get what you mean, i have tried NeHe but have had problems trying to follow the code, as i am working in linux and most of what has been put is for windows, i do believe, (correct me if i am wrong)

There are different ways to do certain things that NeHe has said, so i just got confused, will try again and see if i can plow through it.

As for the l;ast poster, i see what you are getting at, but they are all floats that i am using.

Thanks for the help, if i cant find what i need i will ask again.

The drawing part of the nehe.gamedev.net examples are same, just the opening the window setup is diffrent between windows and openGL.

Also note that he has linux versions of his examples at the bottom of each example page.

What valus are you giving the Z axis in the glVertex3f(x, y, z)?
You could be drawing the line outside the viewing space set in the projection matrix.

Originally posted by Andrew Davey:
[b]ah ok, i think i get what you mean, i have tried NeHe but have had problems trying to follow the code, as i am working in linux and most of what has been put is for windows, i do believe, (correct me if i am wrong)

There are different ways to do certain things that NeHe has said, so i just got confused, will try again and see if i can plow through it.

As for the l;ast poster, i see what you are getting at, but they are all floats that i am using.

Thanks for the help, if i cant find what i need i will ask again.[/b]

i am randomly assigning some values to the z’s. i.e. i have 6 lines and i think the values are either these or close enough what i mean by values is that is the difference when drawing the line. e.g. z1=0 z2=100

100
0
1
3
-3
10

Something like that anyway.

I will check out that linux thing that you have said, didnt think to look at that.

Cheers

What projection mode are you using and settings, ortho and perspective?

wasnt using any as i didnt know what i shjould have been doing.

Will look into what you said. Can you please however explain what they are, basics i suppose as no doubt there are many topics on this forum that i can read later.

Cheers

When openGL renders a scene, it uses a set Z-distance, in other words on a set area of 3D space is rendered. So anything drawn out of the set area is not draw.

In the projection matrix we set the area in which to be rendered. I think the default is Z = -1 to 1 in the z space rendered, so a line drawn from 1 to 100, would look like a dot or not drawn at all.

The model matrix is setting up of how our objects are located in the area to be rendered.

// Here is an example of how I setup the matrix before drawing a scene.

glMatrixMode (GL_PROJECTION); // Tell opengl that we are doing project matrix work
glLoadIdentity(); // Clear the matrix
glOrtho(-8.0, 8.0, -8.0, 8.0, 0.0, 30.0); // Setup an Ortho view (x/y top corner, x/y bottom corner, z rendering area is from 0 to 30 openGL units
glMatrixMode(GL_MODELVIEW); // Tell opengl that we are doing model matrix work. (drawing)
glLoadIdentity(); // Clear the model matrix

Originally posted by Andrew Davey:
[b]wasnt using any as i didnt know what i shjould have been doing.

Will look into what you said. Can you please however explain what they are, basics i suppose as no doubt there are many topics on this forum that i can read later.

Cheers[/b]

cool, thanks i think i understand what you are saying.

So does the ortho view give me a cube of space that if anything falls into that space it will draw? is that right, as i think that is what i understrand by what you have said.

====================

Also just a quick one, where is 0,0,0 ? as 0,0 in 2d space is bottom left ( i think )?

would 0,0,0 be in te centre of the screen?

Cheers for all the help guys