PDA

View Full Version : What are the functions of glVertex3f and glNormalsf?



09-04-2000, 06:16 PM
Hi, can anybody answer with me what are the functions and structures of the glVertex3f, glNormalsf and glTexCoord2f? If careless using them, what'll happen?

Thanks

09-04-2000, 09:41 PM
Hi, can anybody answer with me what are the functions and structures of the glVertex3f, glNormalsf and glTexCoord2f? If careless using them, what'll happen?

not sure what you are trying to ask, but i'll give it a go.

glVertex => allows you to define where the vertex is in space. if you have glVertex3f that means you have three floating point values.
floating point means you have decimals versus integers which are whole numbers.
the three values are x,y,z.
th easiest way to look at this is too imagine a graph which has a z axis too (depth). now say you had this command

glVertex3f( 1.0f, 0.0f, 0.0f); what that means is that you move up the x axis by one point, and since y and z are 0 you don't move along those axis at all.

okay here is where it might get a little bit more complicated so bear try to follow me.
for carelessness... don't be. granted you have typos, but be aware of how to code.
so where do you use glVertex
here is an example:

glBegin(GL_TRIANGLE);
glVertex3f( 1.0f, 0.0f, 0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glvertex3f( 0.0f,-1.0f, 0.0f);
glEnd();

first thing to note:
you must have the glBegin to start drawing a simple shape. in the parenthesis you insert the type of shape you are going to define. notice i use GL_TRIANGLE which means opengl will be expecting three vertexes, or three points. once you define the three points the points are "connected" and with additional coding you should get a window that has a triangle in the center.
for example if you use GL_POLYGONS instead of GL_TRIANGLE you could define more then three points as long as you follow the rules of creating polygons. (at this point i suggest getting a book or reading up on it. i don't want to confuse you. just want to get some ideas across)
the glEnd; tells opengl you are done defining the points of the shape.

glNormal is to do with the which way the points or the polygon/triangles are facing and the effect the lights should have on it.
ummm i wrote a few lines explaining this but i realised that it was getting to complex. so i really suggest getting a book or checking out the tutorials available here.

as for glTexcoord. think of a simple texture you have. just say its a square texture of some face. the center of the square would be 0,0 (x,y) and the edges have co-ordinates relative to the center of the tex. no matter what size the texture is in terms of pixels (well there are restrictions, but i'm keeping it simple) the co-ordinates are the same. in other words the top left point would be (-1,1). make sense so far?
so say you define a square
its co-ordinates are
(-2,2), (2,2), (2,-2), (-2,-2)
you tell opengl to apply the top left texture to the topleft of the square, i.e.:

glTexcoord2f(-1.0f,1.0f); <-- top left corner of the texutre
glVertex3f(-2.0f, 2.0f, 0.0f); <--- the top left vertex of the square

well like i said all these functions have to be used properly. so i suggest going through the online tutorials slowly, and get the idea of how 3d space is defined and manipulated with opengl. if you make a mistake, chances are that even though a program might work, there will be anomolies or what you though you programmed does not show up. plus a good debugger will allow you to spot certian mistakes. but try to be careful. typos are a bitch though. most of my debugging is just fixing typos. eck!

hopefully i've answered your questions. and most of all i hope that i've shown that opengl is actually pretty easy and is a great tool, and that you use the online tutorials as a guide for learning.

cheers

Gavin
09-05-2000, 01:20 AM
just to add a little..

A normal is perpendicular to a plane (or could be any geometric shape really). It is used in the equation of the plane so that you know in which direction the plane is pointing. This can be used to determine reflections and refractions of light when rendering. But as was mentioned the direction of the normal shows which way the plane/polygong is facing and shows the outside, i.e. the side which is rendered.

gav

Antonio
09-09-2000, 05:26 PM
Just to add a little bit more:

A normal in the OpenGL context doesn't have to be perpendicular to the plane. The normals are used to determine how an object responds to a light hitting it. So you may want to have a normal which is not the perpendicular, specially if you're using normals per vertex, in which case you can simulate a curved surface using only a flat polygon just by playing with the normals.

Antonio www.fatech.com/tech (http://www.fatech.com/tech)

Bob
09-10-2000, 03:42 AM
Antonio, you ARE correct about what you say, that a normal doesn't have to be prepedicular to the face, but mentioning vertex normals as an example is slightly wrong in my oppinion.

Consider a sphere. You approximate the sphere with a number of polygons. If you add vertex normals, each normals will not be prepedicular to a face, that's true. BUT!!! Each normals IS prependicular to the surface of the mathematically described sphere. So vertex normals IS prependicular to the actual surface, but not the approximated surface you draw.