reven's picture

Cg and OpenTK Matrix4

Hi, I'm currently having some troubles setting the parameters in a Cg Effect file with Cg.Tao. If this is the wrong place to ask the question, please direct me towards the right.

I would like to avoid using cgGlSetStateMatrixParameter and retrieving the matrices from the OpenGL set projection and modelview matrices. Instead, I'd like to manage my own matrices with OpenTK Matrix4 functions and then supply the matrices and uniform parameters.

I cannot, however, seem to make things work.

First I tried to set the matrix like this:

Matrix4 projectionMatrix = Matrix4.Identity * Matrix4.Perspective(90,800/600, 0.1f,100.0f); // this works right, cause it can be loaded with GL.LoadMatrix and displayed correctly..
IntPtr proj = Cg.cgGetEffectParameterBySemantic(effect, "Projection"); // retrieve projection matrix parameter 
 
// first try - did not work
Cg.cgSetMAtrixParameterfr(proj, out projectionMatrix.Row0.X);   
 
// second try - did not work either
CgGl.cgGLSetMAtrixParameterArrayfr(proj, 0,1, (IntPtr) projectionMatrix.Row0);
 
// Third:
float[] matrix = new float[]
{
   projectionMatrix.Row0.X,
   projectionMatrix.Row0.Y,  
   projectionMatrix.Row0.Z,
   ..
   ..
   projectionMatrix.Row3.W
}
 
Cg.cgSetMatrixPArameterfr(proj, out matrixA[0]);
 
// fourth
CgGl.cgGLSetMAtrixParameterArrayfr(proj, 0,1, matrix);

None of these seemed to work. Any ideas of what might be wrong?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Inertia's picture

Nice, since the Matrix4 struct works nicely together with OpenGL's Load-/Mult-TransposedMatrix and GLSL uniforms, I kinda think Cg is the culprit here. Nevertheless you should report the incorrect 'out' to the Tao.Cg maintainer, it is definitely incorrect.

Just out of curiousity, why Cg and not GLSL?