Hi,

On 24 June 2011 12:37, Diederick C. Niehorster <dcnieho@gmail.com> wrote:
Hi Matti,

On Fri, Jun 24, 2011 at 16:58, Matti Lehtonen <m-Matti-a.Lehtonen@iki.fi> wrote:
> Hi,
>
> Did I said somewhere that everything must be passed to freeglut functions?
> As I said earlier, passing vertex and normal information for shader is
> enought.
>
> The ported freeglut code shall look something like this:
>   // Fill vertex and normal arrays
>   ...
>   // Pass arrays to shader program
>   GlInt cp, val, nal;
>   glGetIntegerv( GL_CURRENT_PROGRAM, &cp );
>   val = glGetAttribLocation( p, "a_Vertex3" );
>   glEnableVertexAttribArray( val );
>   glVertexAttribPointer( val, 3, GL_FLOAT, GL_TRUE, 0, vertexArray );
>   nal = glGetAttribLocation( p, "a_Normal" );
>   if( nal != -1 )
>   {
>     // Shader program needs normals as input
>     glEnableVertexAttribArray( nal );
>     glVertexAttribPointer( nal, 3, GL_FLOAT, GL_TRUE, 0, normalArray );
>   }
>   // Do the rendering
>   ...

Ah yes, that might be a good thing to do, passing the vertex data in
one way or the other, depending on the context used
(forward-compatible openGL 3+ and opengl ES). Just asking as I don't
know: is the attrib location such as a_Vertex3 in glGetAttribLocation(
p, "a_Vertex3" ) fixed? Guess not?

Yes and no. Typically the location zero (0) is reserved for vertex information "gl_Vertex" (type vec4). If shader isn't using "gl_Vertex", then its location is -1 and location zero is typically left empty.  If some other name is used for vertex information, then it's location can be pretty much everything ... except zero. Of course there are function that says that use this location for that input (doable before linking).

I once tried to redefine "gl_Vertex" to be vec2 instead of vec4, but the final result were unexpected. I were expecting error at compilation phase, but instead, I got shader that passed compilation *and* linking , but location of "gl_Vertex" were -1. :O

Lehtonen, Matti
--
Life is complex. It has real and imaginary parts.