vp matrix loading

Hi, I want to load a matrix into my vertex program.

Right now I am loading each row into a seperate local parameter like this:

glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB,0,mat[0]);
glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB,1,mat[1]);
glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB,2,mat[2]);
glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB,3,mat[3]);

where mat[0] through mat[3] each represent one row of a 4x4 matrix.

Then the relevant part of the program looks like this:

PARAM tm[4] = { program.local[0…3] };\

Do you see anything wrong with this? Or is there an alternative method for loading a matrix? I’m not sure this is working correctly.

Secondly, is it possible to output texture coordinates without actually inputing texturing coordinates through TexCoord() or VertexAttrib()?

Thanks,

Old GLman

Anyone? , I know its late, but the specs making my eyes bleed. Well, maybe in the morning then.

Old Glman

Another way you could get matrices into your vertex program is to use glTrackMatrix to track an otherwise unused matrix…like one of the texture matrices.

The only thing that you MUST put into a vertex program is a vertex. You can generate values for everything else within the vertex program.

– Zeno

Yes, your matrix code looks correct and yes you can generate texture coordinates in the vertex program without having them as inputs.

Originally posted by Zeno:
Another way you could get matrices into your vertex program is to use glTrackMatrix to track an otherwise unused matrix…like one of the texture matrices.

glTrackMatrix is a NV_vertex_program function, not a ARB_vertex_program function. If you want to have matrix tracking in ARB_vertex_program, use the state struct (for example to access the modelview projection matrix you would use state.matrix.mvp).

[This message has been edited by jra101 (edited 12-14-2002).]

Thanks for your help.

Old GLman

Try this:

glMatrixMode( GL_MATRIX0 );
glLoadMatrixfv( mat );

Bind with state.matrix[0].

Note that matrices are internally transposed so that they Do The Right Thing when they get loaded into parameter row vectors. If you load a matrix array into vector registers on your own, you have to also transpose it on your own to have the right thing happen.

Great Jwatte!! worked great. Thank you. It seems that:

glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB,0,mat[0]);
glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB,1,mat[1]);
glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB,2,mat[2]);
glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB,3,mat[3]);

// and then in the program:

PARAM tm[4] = { program.local[0…3] };\

is syntaxically correct ( no errors or warnings reported ) but works differently from what I was able to discern from the spec.

However,

glMatrixMode(GL_MATRIX0_ARB);
glLoadMatrixf(mat);

glMatrixMode(GL_MODELVIEW);
// verts, tex coords, etc…

// and then in the program:

PARAM tm[4] = { state.matrix.program[0] };\

works like I expected. The inverse and transpose features are really nice also.

Thanks again!

Old GLman