Sign in to follow this  
Noxir

glVertex3f??!

Recommended Posts

Noxir    100
Could anyone explain how glVertex3f(x,y,z) works? I don't get it. How I know which point I'm editing? [edit] I'm MAKING? [Edited by - Noxir on October 22, 2005 7:12:29 PM]

Share this post


Link to post
Share on other sites
Sneftel    1788
There is no such thing as "editing" points in OpenGL. OpenGL is not a scene graph library; it does not keep track of any geometry. OpenGL does one thing and one thing only: It draws where you tell it to draw. The glVertex passes a vertex to OpenGL to be drawn; it doesn't edit anything. Next frame, if you still want the vertex to be visible, you have to call glVertex again.

Share this post


Link to post
Share on other sites
rip-off    10979
Quote:
Original post by Noxir
Could anyone explain how glVertex3f(x,y,z) works? I don't get it. How I know which point I'm editing?


i think you have a few more problems if you dont know which point you're editing, because i certainly don't.

ok, most 3d models are stord in a file somewhere, and comprise of many many float variables.

for simplicity, you could load them into a bit array and do this
(havent used openGL in a while, so names are a bit iffy )

glBegin( GL_TRIANGLES );
for( int i = 0 ; i < array_size ; ++i ){
glVertex3f( vertices[i][X], vertices[i][Y], vertices[i][Z] );
}
glEnd();


Share this post


Link to post
Share on other sites
Sneftel    1788
Quote:
Original post by Noxir
better answers please, you're talking to an OpenGL beginner not albert einstein

Uh huh. Based on your posting history, it looks like (a) you are a beginner, and (b) you think you're Albert Einstein. You need to take things slower, and get more of an idea of the fundamentals of what you're doing. I'm not sure how to give you a better answer than "OpenGL only draws things", but I AM sure that you aren't going to get anywhere unless you spend some more time reading. Buy this book and start reading it. Also, this stuff will go a hell of a lot easier for you if you spend some time learning linear algebra. Not the really complicated stuff... just vectors and matrices.

Share this post


Link to post
Share on other sites
dbzprogrammer    100
Alright, you're probably familiar with easier development tools. With glVertex3f(), your not acessing a vertex. You're not modifying one. Your not deleting one. What you are doing is telling OpenGL to plot a vertex at the x,y, and z coordinate you pass to the function. OpenGL doesn't store your verticies for you, it justs displays things on the screen. So if you want to store verticies, you'll have to make your own data system to do that, and then pass the data to the glVertex3f() function to display it on the screen.

Share this post


Link to post
Share on other sites
Lundek    222
Quote:
Original post by Noxir
better answers please, you're talking to an OpenGL beginner not albert einstein

There are no better answers, because the question "How I know which point I'm editing?" doesn't make any sense. You're not editing anything, you're giving OpenGL the position of a vertex.

Take a look at this. I didn't bother to read much of it, but it looks like a reasonable introduction to drawing OpenGL primitives.

Share this post


Link to post
Share on other sites
Noxir    100
Quote:
Original post by Sneftel
Quote:
Original post by Noxir
better answers please, you're talking to an OpenGL beginner not albert einstein

Uh huh. Based on your posting history, it looks like (a) you are a beginner, and (b) you think you're Albert Einstein. You need to take things slower, and get more of an idea of the fundamentals of what you're doing. I'm not sure how to give you a better answer than "OpenGL only draws things", but I AM sure that you aren't going to get anywhere unless you spend some more time reading. Buy this book and start reading it. Also, this stuff will go a hell of a lot easier for you if you spend some time learning linear algebra. Not the really complicated stuff... just vectors and matrices.


I've tried learning how the fuck Vertex3f works for hours now and I still don't get it. About the book, I can't afford it, and won't be able to afford it for a long while. I just wanted someone to explain, how it works, instead of correcting my question with "It isn't editing, it's making".
And this is nothing about what's based on my posting history, ass.

Noobyesthxbye

Share this post


Link to post
Share on other sites
Noxir    100
Quote:
Original post by Lundek
Quote:
Original post by Noxir
better answers please, you're talking to an OpenGL beginner not albert einstein

There are no better answers, because the question "How I know which point I'm editing?" doesn't make any sense. You're not editing anything, you're giving OpenGL the position of a vertex.

Take a look at this. I didn't bother to read much of it, but it looks like a reasonable introduction to drawing OpenGL primitives.


Sure, new question: How I know which position of a vertex I'm giving?

Share this post


Link to post
Share on other sites
Cocalus    554
Quote:
Original post by Noxir

Sure, new question: How I know which position of a vertex I'm giving?


The x y z of glVertex3f(x,y,z). I doubt that's the answer you wanted. But your giving really general questions, that require us to know how you think opengl works. Or in other words, you have an idea of how opengl works. Like in your first question you assumed that there was a bunch of points you moved around (which isn't the case). And now your asking us questions about how you think opengl works, but we have no idea how it works in your head.

You might try asking more specific questions about opengl. Like how to draw a triangle, or how does the 3d position of x,y,z become a point on the screen.

Share this post


Link to post
Share on other sites
James Trotter    432
Alright, I think you should calm down a little. Sneftel gave you a good answer, so I don't think it was right to insult him. Remember, it's important to be polite, because he is doing you a favour spending time answering your questions.

The position at which OpenGL creates the vertex is the coordinates you pass into the function. So if you do this:

glVertex3f(0.0f, 0.0f, -1.0f);

You're telling OpenGL to put a vertex one unit down the Z-axis.

I'm curious of where you are learning from. A book would definitely be the best source, but since you don't have the opportunity, then there are also plenty of good websites with tutorials. Personally I learnt alot of my OpenGL from NeHe. I hope this can help you too.

Share this post


Link to post
Share on other sites
adam17    227
->Noxir

give this a try. go to nehe.gamedev.net and download one of the lessons. play around with the glVertex3f's nehe has in the code. just tweak the values of x, y and z. then try making more primitives and that should help you understand how it works better.

Share this post


Link to post
Share on other sites
dbzprogrammer    100
Quote:
Original post by Noxir
Quote:
Original post by Lundek
Quote:
Original post by Noxir
better answers please, you're talking to an OpenGL beginner not albert einstein

There are no better answers, because the question "How I know which point I'm editing?" doesn't make any sense. You're not editing anything, you're giving OpenGL the position of a vertex.

Take a look at this. I didn't bother to read much of it, but it looks like a reasonable introduction to drawing OpenGL primitives.


Sure, new question: How I know which position of a vertex I'm giving?


Did you read my first post? Ok, #1, get out of any mindset your in right now about OpenGL. If you don't know what a mindset is, then you shouldn't be doing game programming yet. Ok, OpenGL doesn't store verticies. It doesn't do anything in your engine except 2 things. The first thing it does is set the video settings for your application. The second thing you do is color the screen you provide it with. Follow this next part closely with this in mind.

Example:

We need to display a triangle on the screen. Now, the only way we can do this is to tell OpenGL we need it to color in a triangle on the screen. We tell it to start displaying triangles with glBegin(GL_TRIANGLES);. Now, for a triangle, there must be 3 verticies (points) to tell OpenGL the position of the triangle. But OpenGL doesn't contain any data on our verticies. A vertex has a x,y, and z coordinate describing its location. Let's make the coordinates for our 3 verticies (0,0,0),(1,0,0), and (0,1,0). So we pass to OpenGL the x,y, and z coordinates for each vertex with the glVertex3f(x,y,z); function.

glBegin(GL_TRIANGLE);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(1.0f,0.0f,0.0f);
glVertex3f(0.0f,1.0f,0,0f);
glEnd();

We have told OpenGL that we will create 3 verticies to form a triangle.

[Edited by - dbzprogrammer on October 23, 2005 8:08:19 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
When I make glVertex3f() the points never comes where I want them to be.
I tried making a star with gl_polygon, with 5 lines of glVertex3f() code, and when I compiled it turned out into a square.
Then I tried making a square and when I compiled it had the shape like:
/^\_/

Share this post


Link to post
Share on other sites
Noxir    100
ops, I'm anonymous poster, forgot logging in, anyway it had the shape like a 60 grade rotated square, so what the f.. I'm doing wrong I've drawed it exactly right with x y z etc

Share this post


Link to post
Share on other sites
Noxir    100
i dont got the code anymore, i deleted it, anyway, how can this be a square?

glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f);
// isnt this 1 unit left and 1 unit up? doesnt this mean that opengl is going to write a "\" ???
glVertex3f( 1.0f, 1.0f, 0.0f); // isn't this 1 unit right and 1 unit up? doesnt this mean that opengl is going to write a "/" ???
glVertex3f( 1.0f,-1.0f, 0.0f); // isn't this 1 unit right and 1 unit down? doesnt this mean that opengl is going to write a "\" ???
glVertex3f(-1.0f,-1.0f, 0.0f); // isn't this 1 unit left and 1 unit down? doesnt this mean that opengl is going to write a "/" ???
glEnd();

?!??!?!

Share this post


Link to post
Share on other sites
WarAmp    750
glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f);
// isnt this 1 unit left and 1 unit up? doesnt this mean that opengl is going to write a "\" ???
glVertex3f( 1.0f, 1.0f, 0.0f); // isn't this 1 unit right and 1 unit up? doesnt this mean that opengl is going to write a "/" ???
glVertex3f( 1.0f,-1.0f, 0.0f); // isn't this 1 unit right and 1 unit down? doesnt this mean that opengl is going to write a "\" ???
glVertex3f(-1.0f,-1.0f, 0.0f); // isn't this 1 unit left and 1 unit down? doesnt this mean that opengl is going to write a "/" ???
glEnd();


No, what glVertex3f does is simply set points, then the GL_QUADS tells Opengl that the points you are giving it are corners of Quads. So it simply 'connects the dots' to create a quad out of every 4 points you give it.

That code should create a single Quad, centered on the origin (0,0,0) that is 2 units on each side. (-1 to 1, -1 to 1, 0).

Share this post


Link to post
Share on other sites
smitty1276    560
How can that NOT be a square? Since your z values are all zero, why don't you ignore them and try plotting those coordinates on a piece of paper? You'll see that it is a square.

glVertex3f doesn't tell it to "move" anywhere, as you seem to be convinced. It gives OpenGL an EXACT COORDINATE at which to place a vertex. If the first vertex is (1.0, 1.0, 0.0) and you want it to go up and left you don't tell it (-1.0, 1.0, 0)... you would have to give it the coordinate that is actually up and left, in this case (0.0, 2.0, 0.0).

Share this post


Link to post
Share on other sites
LilBudyWizer    491
Without using any transforms, i.e. glRotate, glTranslate, glScale, etc, the camera it as the origin pointing down the negative z axis, the positive x axis is to the right and the positive y axis is up. Whether you actually see a point depends upon whether it is on the correct side of six planes. You have to be to the left of the right plane, right of the left, below the top, above the bottom, closer than far and further than near.

Getting started I would suggest using gluOrtho2D to setup the projection matrix. You specify left, right, top and bottom with near and far set to -1 and 1 for you. Then glVertex2f(x,y) will appear on the screen assuming the color is set appropriately and x is between left and right and y is between top and bottom. You won't see the effect of z other than it has to be between -1 and 1 for the point to be visible.

Share this post


Link to post
Share on other sites
Noxir    100
Quote:
Original post by WarAmp
glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f);
// isnt this 1 unit left and 1 unit up? doesnt this mean that opengl is going to write a "\" ???
glVertex3f( 1.0f, 1.0f, 0.0f); // isn't this 1 unit right and 1 unit up? doesnt this mean that opengl is going to write a "/" ???
glVertex3f( 1.0f,-1.0f, 0.0f); // isn't this 1 unit right and 1 unit down? doesnt this mean that opengl is going to write a "\" ???
glVertex3f(-1.0f,-1.0f, 0.0f); // isn't this 1 unit left and 1 unit down? doesnt this mean that opengl is going to write a "/" ???
glEnd();


No, what glVertex3f does is simply set points, then the GL_QUADS tells Opengl that the points you are giving it are corners of Quads. So it simply 'connects the dots' to create a quad out of every 4 points you give it.

That code should create a single Quad, centered on the origin (0,0,0) that is 2 units on each side. (-1 to 1, -1 to 1, 0).


thanks man i finally figured out how it works

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this