CgFx on a JoGL

Hi everybody!
i have an question, how to use CgFx effect shaders in a JoGL? how to use simple terchniques from effect?
can anyone give me example? :wink:

I don’t really have time to explain much, but for a single pass taking position, normal & uv input to the vertex shader, something along these lines:


////init
CGContext context = CgGL.cgCreateContext();
CgGL.cgGLRegisterStates(context);
CGEffect effect = CgGL.cgCreateEffectFromFile(context, filename, null);
CGTechnique technique = CgGL.cgGetFirstTechnique(effect);
CGPass pass = CgGL.cgGetFirstPass(technique);
		
CGParam obj2cam = CgGL.cgGetNamedEffectParameter(effect, "__object_to_camera");
CGParam obj2rast = CgGL.cgGetNamedEffectParameter(effect, "__object_to_raster");
CGParam cam2obj = CgGL.cgGetNamedEffectParameter(effect, "__camera_to_object");


////display loop
//setup Cg state.
CgGL.cgGLEnableProfile(CgGL.CG_PROFILE_VP40);
CgGL.cgGLEnableProfile(CgGL.CG_PROFILE_FP40);
CgGL.cgSetPassState(pass);

CgGL.cgGLSetStateMatrixParameter(obj2cam, CgGL.CG_GL_MODELVIEW_PROJECTION_MATRIX, CgGL.CG_GL_MATRIX_IDENTITY);
CgGL.cgGLSetStateMatrixParameter(obj2rast, CgGL.CG_GL_PROJECTION_MATRIX, CgGL.CG_GL_MATRIX_IDENTITY);
CgGL.cgGLSetStateMatrixParameter(cam2obj, CgGL.CG_GL_MODELVIEW_PROJECTION_MATRIX, CgGL.CG_GL_MATRIX_INVERSE);

//render using vertex arrays
gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL.GL_NORMAL_ARRAY);
gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);
//assuming verts, norms & texco are appropriate FloatBuffers and indices is an appropriate IntBuffer
gl.glVertexPointer(3, GL.GL_FLOAT, 0,verts);
gl.glNormalPointer(GL.GL_FLOAT, 0,norms);
gl.glTexCoordPointer(2, GL.GL_FLOAT, 0,texco);
gl.glDrawElements(GL.GL_QUADS, indices.remaining()-1, GL.GL_UNSIGNED_INT, indices);
gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL.GL_NORMAL_ARRAY);

CgGL.cgResetPassState(pass);

Disclaimer: Use this at your own risk, I am not responsible for loss or damage, etc. Hopefully that might be somewhat useful to get you up and running. If anyone notices any apparent problems, please point them out.