   2 cg shaders problem
  hi, I have small problem with loading and using more than one cg shader, basicly I do:1. Load and compile first pixel and vertex shader with cgCreateProgramFromFile2. Load and compile second3. binding programs and set parameters of first shaders4. try to draw geometry (using glDrawElements)the problem is with 4'th step, app crashes on glDrawElementsqyestion: is there something I need do for getting the both shaders work? I've analysed sample apps from NVIDIA SDK using more cg shaders, and the only difference I've noticed was that cgCreateProgram was used, instead of cgCreateProgramFromFile (though I might have overlooked something).   
  Since you're crashing at glDrawElements the problem is probably related to your indices or formats specified there. If Cg crashes it wont be in a GL call. Of course stranger things have happened. :-) Posting your code may help.Also, what version of Cg do you use?Thanks.   ;  Here is the code loading shaders:  shaders = new obiShaders ();  shaders->ChooseProfiles ();  unsigned char *heightmap = new BYTE[1024*1024];  obiImageLoader::LoadData ("..\\..\\data\\textures\\heightmap.raw",heightmap, 1024*1024);  memset(heightmap,0,sizeof(void *)*1); terrain = new obiTerrain (heightmap, 1024, 1024, 64, 64);  terrain->SetTexture (obiImageLoader::LoadTexture ("..\\..\\data\\textures\\rocky_surface.dds"));  terrain->SetLightTexture (obiImageLoader::LoadTexture ("..\\..\\data\\textures\\sunlight.dds"));  terrain->SetScale (obiVector3 (1,200,1));  terrain->SetOffset (obiVector3 (-512,-40, -512));  terrain->InitTerrain (shaders->LoadVertexShader ("..\\..\\data\\shaders\\caustic_vert.cg"),    shaders->LoadPixelShader ("..\\..\\data\\shaders\\caustic_pixel.cg"));  sky = new obiSkyBox ();  sky->SetTextures (obiImageLoader::LoadTexture ("..\\..\\data\\textures\\wrap2.dds"),    obiImageLoader::LoadTexture ("..\\..\\data\\textures\\white.dds"));  //water  water = new obiWater ();  GLuint water_txt = obiImageLoader::LoadTexture ("..\\..\\data\\textures\\water.dds");  if (!water_txt)    ErrorReporter::ReportError ("Nie mo&#380;na znale&#378;&#263; textury", "..\\..\\data\\textures\\water.dds");  water->InitWater (water_txt,shaders->LoadVertexShader ("..\\..\\data\\shaders\\water_vert.cg"),shaders->LoadPixelShader ("..\\..\\data\\shaders\\water_pixel.cg"));and here loading shader methods:CGprogram obiShaders::LoadVertexShader (const char* path){  // Load and compile the vertex program from demo_vert.cg; hold on to the  // handle to it that is returned.  CGprogram vertex_program = cgCreateProgramFromFile(context, CG_SOURCE, path,    vertex_profile, NULL, NULL);  //if (!cgIsProgramCompiled(vertex_program))  //  cgCompileProgram(vertex_program);  // Enable the appropriate vertex profile and load the vertex program.   cgGLLoadProgram(vertex_program);  return vertex_program; }CGprogram obiShaders::LoadPixelShader (const char* path){  // And similarly set things up for the fragment program.  CGprogram fragment_program = cgCreateProgramFromFile(context, CG_SOURCE, path,    fragment_profile, NULL, NULL);  //if (!cgIsProgramCompiled(fragment_program))  //  cgCompileProgram(fragment_program);  cgGLLoadProgram(fragment_program);  return fragment_program;}and the drawing code:  shaders->EnableProfiles ();  terrain->DrawTerrain (time / 1000);  //water->DrawWater (time / 1000 * 0.25f);   shaders->DisableProfiles ();void obiTerrain::DrawGeometry (){ //// enabling the bindings to the shader parameters  CGparameter param = cgGetNamedParameter(vertex_program, "IN.Position");  cgGLEnableClientState(param);  param = cgGetNamedParameter(vertex_program, "IN.Normal");  cgGLEnableClientState(param);  param = cgGetNamedParameter(vertex_program, "IN.TexCoord");  cgGLEnableClientState(param);  // Enable the texture parameter as well.  param = cgGetNamedParameter(fragment_program, "LightMap");  cgGLEnableTextureParameter(param);  param = cgGetNamedParameter(fragment_program, "GroundMap");  cgGLEnableTextureParameter(param);  // And now, draw the geometry.'  glDrawElements(GL_TRIANGLE_STRIP, i_cnt, GL_UNSIGNED_INT, indices);  glPopMatrix();  //// Be a good citizen and disable the various bindings we set up above.  param = cgGetNamedParameter(vertex_program, "IN.Position");  cgGLDisableClientState(param);  param = cgGetNamedParameter(vertex_program, "IN.Normal");  cgGLDisableClientState(param);  param = cgGetNamedParameter(vertex_program, "IN.TexCoord");  cgGLDisableClientState(param);  param = cgGetNamedParameter(fragment_program, "LightMap");  cgGLDisableTextureParameter(param);  param = cgGetNamedParameter(fragment_program, "GroundMap");  cgGLDisableTextureParameter(param);}void obiTerrain::DrawTerrainNoShader (float time){  glVertexPointer(3, GL_FLOAT, 0, vertices);  glEnableClientState(GL_VERTEX_ARRAY);  glNormalPointer(GL_FLOAT, 0, normals);  glEnableClientState(GL_NORMAL_ARRAY);  glTexCoordPointer (2, GL_FLOAT, 0, texels);  glEnableClientState (GL_TEXTURE_COORD_ARRAY);  glEnable(GL_TEXTURE_2D);  glBindTexture(GL_TEXTURE_2D, terrain_txt);  glDrawElements(GL_TRIANGLE_STRIP, i_cnt, GL_UNSIGNED_INT, indices);  glDisable(GL_TEXTURE_2D);  glDisableClientState(GL_VERTEX_ARRAY);  glDisableClientState(GL_NORMAL_ARRAY);  glDisableClientState (GL_TEXTURE_COORD_ARRAY);}void obiTerrain::DrawTerrain (float time){  // Setting up shaders  cgGLBindProgram(vertex_program);  cgGLBindProgram(fragment_program);  // Bind uniform parameters to vertex shader  cgGLSetStateMatrixParameter(cgGetNamedParameter(vertex_program, "ModelViewProj"),    CG_GL_MODELVIEW_PROJECTION_MATRIX,    CG_GL_MATRIX_IDENTITY);  //cgGLSetStateMatrixParameter(cgGetNamedParameter(vertex_program, "ModelViewIT"),  //  CG_GL_MODELVIEW_MATRIX,  //  CG_GL_MATRIX_INVERSE_TRANSPOSE);  cgSetParameter1f (time_param, time);  cgGLEnableTextureParameter(cgGetNamedParameter(fragment_program,    "LightMap"));  cgGLEnableTextureParameter(cgGetNamedParameter(fragment_program,    "GroundMap"));  DrawGeometry ();  // Disable the textures now that we're done with it.  cgGLDisableTextureParameter(cgGetNamedParameter(fragment_program,    "LightMap"));  cgGLDisableTextureParameter(cgGetNamedParameter(fragment_program,    "GroundMap"));}CG version 1.4drawing without shader works, same when I don't load water shaders (shaders->LoadVertexShader ("..\\..\\data\\shaders\\water_vert.cg"))so I think this should be somewhat related :)   ;  while debugging I've noticed that for indices count < 56 (whole mesh is ~8K) function draws without a crash. Strange thing is that indices, normals, texels, vertices vectors looks right (every have resonable values)   ;  Have you by any chance tried Cg 1.5 beta1?   ;  now at last it is reporting errors, thank you :), though they are a bit strange - it reports bad parameters when second shader is loaded. Back to debuging...   ;  CGparameter light_tex_param = cgGetNamedParameter(fragment_program, "LightMap");  CGparameter terr_tex_param = cgGetNamedParameter(fragment_program, "GroundMap");  time_param = cgGetNamedParameter(fragment_program, "time");  cgGLBindProgram (fragment_program);  cgGLSetTextureParameter(light_tex_param, light_txt);  cgGLSetTextureParameter(terr_tex_param, terrain_txt);  // Tell Cg which of these data pointers are associated with which  // parameters to the vertex shader, so that when we call  // cgGLEnableClientState() and then glDrawElements(), the shader  // gets the right input information.  CGparameter normal_param = cgGetNamedParameter(vertex_program, "IN.Normal");  CGparameter pos_param = cgGetNamedParameter(vertex_program, "IN.Position");  CGparameter tex_param = cgGetNamedParameter(vertex_program, "IN.TexCoord");  cgGLBindProgram (vertex_program);    cgGLSetParameterPointer(pos_param, 3, GL_FLOAT, 0, vertices);  cgGLSetParameterPointer(normal_param, 3, GL_FLOAT, 0, normals);  cgGLSetParameterPointer(tex_param, 2, GL_FLOAT, 0, texels);additonaly the shader loading order must be:pixel shader 1pixel shader 2...vertex shader 1vertex shader 2...I'm courious how could I know that...[Edited by - obi_1 on May 16, 2006 3:49:55 AM];  now I have problem with  cgGLSetParameterPointer, do I need to figure out the right order for setting this parameters, beside pointing right program? b/c now it seem to produce same error when I set them for another shader later...   ;  seems I needed to set pointer parameters right before drawing   