Hi guys;
Do you know what glNormal good for ? I know what normal vector is, but I didn't get the idea of setting normal vector of a vertex.
Should I do that for every vertex ? or what ?
Posted on 2007-11-10 09:47:00 by Dite
Iirc it's required if you apply lighting or stuff like bumpmapping - but it's been ages since I've dealt with this kind of stuff :)
Posted on 2007-11-10 11:13:40 by f0dder
There are (basically) 2 ways to render things in OpenGL:

1) Issue a command for rendering of every single vertex (VEEEEEEEEERY bad idea)
2) Create vertex buffers and render them in 1 call.

The first option is probably left behind for some 'legacy' purposes. In this mode you set up Opengl's state, like texture coordinate, vertex normal, etc, and then send 'glVertex'. This produces one single vertex with 'actual' settings (texcoord, normal).

Or in other words:

For each vertex:
  glnormal, normal_of_current_vertex
  gltexcoord, texcoord_of_current_vertex
  glvertex, position_of_current_vertex

And yes, you MUST avoid this way of rendering thigs ;) Just pretend these functions don't exist :P
Posted on 2007-11-10 14:35:55 by ti_mo_n
Yes, That was exactly what I saw.
So, I shouldn't use this method. What is the 2. method ?
A litte bit hint please :)
Posted on 2007-11-10 14:55:55 by Dite
The second method is to use the so-called 'buffer objects'

Here's a link: http://developer.nvidia.com/object/using_VBOs.html
or here: http://www.spec.org/gwpg/gpc.static/vbo_whitepaper.html

IIRC, older versions of opengl did not supports vertex buffers (a.k.a buffer objects) and required the programmer to see if the ARB_vertex_buffer_object extension is present (for example, NEHE's tutorials are aimed for this older version). In newer versions there are functions which are now part of the opengl spec, if I am not mistaken. just check some new opengl spec (preferably version 2.0) and see for yourself.
Posted on 2007-11-10 15:09:46 by ti_mo_n
timon: the "bad way" of doing things can be fine when testing things, though - and it's not as bad in OpenGL as it is with DX<10, since GL always buffers stuff.

But yeah, it's still bad :)
Posted on 2007-11-10 16:34:33 by f0dder
thx guys
Posted on 2007-11-10 16:53:43 by Dite
glNormal is ... the normal vector of the vertex. (where this vertex points to). In fixed-function, each vertex has its color derived from something like:

LightIntensity0 = rsqr(distance(gl_VertexPosition,gl_LightPos0))
LightIntensity1 = rsqr(distance(gl_VertexPosition,gl_LightPos1))
LightIntensity2 = rsqr(distance(gl_VertexPosition,gl_LightPos2))

LightAngleTangent0 = dot(gl_Normal,gl_LightDirection0) // tangent of angle between gl_Normal and the light's direction
LightAngleTangent1 = dot(gl_Normal,gl_LightDirection1)
LightAngleTangent2 = dot(gl_Normal,gl_LightDirection2)

VertexColor = Diffuse + Light0_Color*LightIntensity0*LightAngleTangent0 + Light1_Color*LightIntensity1*LightAngleTangent1 +...

Then, textured pixels are multiplied by a linearly-interpolated value between the 3 vertices' resulting VertexColor. The result is ugly, that's why per-pixel shaders are almost always used, where not VertexColor, but those 3 gl_Normal vectors are interpolated. Since on all videocards from the last 3-4 years the fixed-function pipeline is transparently done via shaders by the drivers, in most cases per-pixel light is computed faster.

Don't rush to VBOs right from the start, first get a hang of the API, how to draw models, how to use lights, and then how to use shaders :). Using VBOs right from the start may introduce confusion, imho.
VBOs are needed when you want to draw 50000+ polygons with a good framerate and little cpu usage.

Posted on 2007-11-10 21:17:02 by Ultrano