PDA

View Full Version : glNormalPointer



hoshi55
03-14-2001, 01:08 PM
hi

im using vertex and normal array drawing to manage some quick landscape drawing. ive also got a facearray that indexes my vertex and normals arrays, and the vertices get drawn correctly. however, how do i have to use normal arrays when i wish to specify one normal per triangle vertex to achieve smooth shading of the polygons? as far as im concerned, glNormalPointer can be only used for one Normal per face, not per vertex, and i guess thats why my shading is completely messed up.
any suggestions?

eik

Bob
03-14-2001, 01:42 PM
Well, you are on the wrong track here. glNormalPointer does not suppor per-face normal, only per-vertex normal. So your normal array is probably somewhat incorrect.

Post some code please.

hoshi55
03-15-2001, 11:40 AM
Originally posted by Bob:
Well, you are on the wrong track here. glNormalPointer does not suppor per-face normal, only per-vertex normal. So your normal array is probably somewhat incorrect.

Post some code please.


ok, so suppose i use vertex/normal arrays with only one normal per face. how is that supposed to work if i have one array of faces and one array of normals?
there are 3 times as many entries in the face array as there are in the normal-array!
can i crunch the indices like { vertex1, vertex2, vertex3, normal, vertex1, vertex2.... }? if yes, how do i call this and how do i set the stride parameter?

regards

eik

hoshi55
03-15-2001, 11:56 AM
Originally posted by hoshi55:

ok, so suppose i use vertex/normal arrays with only one normal per face. how is that supposed to work if i have one array of faces and one array of normals?
there are 3 times as many entries in the face array as there are in the normal-array!
can i crunch the indices like { vertex1, vertex2, vertex3, normal, vertex1, vertex2.... }? if yes, how do i call this and how do i set the stride parameter?

regards

eik

hoshi55
03-15-2001, 11:59 AM
sorry for the above double entry.

what i wanted to add:

the redbook says the following about array drawing: "... all 20 vertices in a 20-sided polygon can be put into one array and called with oe function. if each vertex also has a surface normal, all 20 surface normals can be put into another array and also called with one function"

now what, once it talks about vertex normals, then face normals..? im confused, please help!

Moz
03-15-2001, 02:21 PM
In the extract you quote, it doesn't talk about face normal, but surface normal.

You approximate a surface by drawing triangles (faces) which have their own normals that can be different from the actual normals of the approximated surface.
What you put in the normal array are the actual normals of the approximated surface, and you have one normal per vertex.
Therefore you have as many normals in the normal array as you have vertices in the vertex array (2 arrays same size, easy).

The entry i in the normal array is the normal of the entry i in the vertex array, it is as simple as that.

You can also use face normals with vertex arrays but if one vertex is shared by n faces, it has to appear n times in the vertex array since you have to define n different vertex-normal couples. Then, you can use glDrawArray instead of glDrawElement since you never reuse vertices (not even if they are shared by several faces ... which often happens http://www.opengl.org/discussion_boards/ubb/smile.gif).

billy
03-16-2001, 12:21 AM
Sorry, this might be a bit of topic.

As I understand you can call a series of polygons using a glBegin and glEnd OR use a an array defined by OpenGL functions to do this, right? If the answer is yes, what is the diference? Performance?

And by the way, what does glNormalPointer do?



[This message has been edited by billy (edited 03-16-2001).]

Moz
03-16-2001, 03:05 AM
Originally posted by billy:

As I understand you can call a series of polygons using a glBegin and glEnd OR use a an array defined by OpenGL functions to do this, right? If the answer is yes, what is the diference? Performance?

Yes, that's right. If you choose to use vertex arrays, it's obviously for performance reasons.
You can define up to five vertex arrays:
one for vertices, one for texture coordinates, one for normal vectors, one for colors (or for color indices), one for polygon edge flags.
You have to fill in those arrays with your objects' data and then tell OpenGL which arrays you want to use (give it the address of the arrays), by using gl*Pointer. * can be Vertex, TexCoord, Normal ...


[B]
And by the way, what does glNormalPointer do?
[B]

glNormalPointer is used to specify the address of the array containing the normal vectors.

Check the Red book for more info on how to use vertex arrays.
Red book, chapter 2, vertex arrays: http://s.scs.uiuc.edu/ebt-bin/nph-infosr..._RESTART_N%25#X (http://s.scs.uiuc.edu/ebt-bin/nph-infosrch/infosrch/SGI_Developer/OpenGL_PG/@ebt-link;cs=fullhtml;pt=1963?target=%25N%14_4468_START _RESTART_N%25#X)

hoshi55
03-17-2001, 12:06 AM
thx for your help, ive now got both vertex/normal array drawing and manual triangle drawing working properly http://www.opengl.org/discussion_boards/ubb/smile.gif
theres still one confusing aspect about array drawing, though:
the index array indicates what vertices (and normals or colors) a triangle face uses. now if i enable texturecoordinate arrays, this seems to lead to a problem: if ive got two adjacent triangles, which share two vertices. they also share the vertex-normals, but i dont want the vertices to share the same texture coordinates. however, since the index array specifies vertex numbers, i cant think of a possibility to assign different texture coordinates per vertex for each face.
how can i work around this?

one more question, how do i properly switch the shading model on-the-fly?

int *param = NULL;
glGetIntegerv(GL_SHADE_MODEL, param);
if(param[0] == GL_SMOOTH) glShadeModel(GL_FLAT); else glShadeModel(GL_SMOOTH);

crashes on me

Bob
03-17-2001, 03:47 AM
The index array is used to point out uniqe vertices from the arrays. If two vertices got the same coordinates, normal and texture coordinates, they are identical. But if they got different texture coordinates, they are no longer identical, and must be represented as two separated vertices. There is no workaround, like having a separate index array for texture coordinates. You just have to duplicate that vertex and give them different texture coordinates.

Deiussum
03-19-2001, 09:04 AM
Originally posted by hoshi55:

one more question, how do i properly switch the shading model on-the-fly?

int *param = NULL;
glGetIntegerv(GL_SHADE_MODEL, param);
if(param[0] == GL_SMOOTH) glShadeModel(GL_FLAT); else glShadeModel(GL_SMOOTH);

crashes on me

Try this instead...



(Edit note ok... doing the & + param is translating to m in HTML so I'm changing the variable name.) http://www.opengl.org/discussion_boards/ubb/smile.gif
int p;
glGetIntegerv(GL_SHADE_MODEL, &p);

You have to have memory allocated for the pointer you send into glGet* stuff. OpenGL doesn't allocate the memory for those for you, and that's what it would have to do in the way you tried using it. In my example the memory will be allocated on the stack.

Almost always when you get a crash, it is due to touching memory you shouldn't be touching... in your case, you were trying to have OpenGL write to a NULL memory address. (Understanding of memory, is the key to mastering C/C++)




[This message has been edited by Deiussum (edited 03-19-2001).]