Ejemplo n.º 1
0
  void LoadCgPrograms() {
    assert CgGL.cgIsContext(context);

    // Load and compile the vertex program from demo_vert.cg; hold on to the
    // handle to it that is returned.
    try {
      vertexProgram =
          CgGL.cgCreateProgramFromStream(
              context,
              CgGL.CG_SOURCE,
              getClass()
                  .getClassLoader()
                  .getResourceAsStream("demos/cg/runtime_ogl_vertex_fragment/demo_vert.cg"),
              vertexProfile,
              null,
              null);
    } catch (final IOException e) {
      throw new RuntimeException("Error loading Cg vertex program", e);
    }
    if (!CgGL.cgIsProgramCompiled(vertexProgram)) CgGL.cgCompileProgram(vertexProgram);

    // Enable the appropriate vertex profile and load the vertex program.
    CgGL.cgGLEnableProfile(vertexProfile);
    CgGL.cgGLLoadProgram(vertexProgram);

    // And similarly set things up for the fragment program.
    try {
      fragmentProgram =
          CgGL.cgCreateProgramFromStream(
              context,
              CgGL.CG_SOURCE,
              getClass()
                  .getClassLoader()
                  .getResourceAsStream("demos/cg/runtime_ogl_vertex_fragment/demo_frag.cg"),
              fragmentProfile,
              null,
              null);
    } catch (final IOException e) {
      throw new RuntimeException("Error loading Cg fragment program", e);
    }
    if (!CgGL.cgIsProgramCompiled(fragmentProgram)) CgGL.cgCompileProgram(fragmentProgram);

    CgGL.cgGLEnableProfile(fragmentProfile);
    CgGL.cgGLLoadProgram(fragmentProgram);
  }