public static void Run()
{
string filePath = Path.Combine("..", "..");
string fileDirectory = "Data";
string vertexFileName = "C6E1v_bulge.cg";
if (File.Exists(vertexFileName))
{
filePath = "";
fileDirectory = "";
}
else if (File.Exists(Path.Combine(fileDirectory, vertexFileName)))
{
filePath = "";
}
string myVertexProgramFileName = Path.Combine(Path.Combine(filePath, fileDirectory), vertexFileName);
// Callback Delegates
keyboardDelegate += keyboard;
menuDelegate += menu;
idleDelegate += idle;
reshapeDelegate += reshape;
Glut.glutInitWindowSize(400, 400);
Glut.glutInitDisplayMode(Glut.GLUT_RGB | Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);
Glut.glutInit();
Glut.glutCreateWindow(myProgramName);
Glut.glutDisplayFunc(display);
Glut.glutKeyboardFunc(keyboardDelegate);
Glut.glutReshapeFunc(reshapeDelegate);
Gl.glClearColor(0.1f, 0.1f, 0.5f, 0f); /* Gray background. */
Gl.glEnable(Gl.GL_DEPTH_TEST); /* Hidden surface removal. */
myCgContext = Cg.cgCreateContext();
checkForCgError("creating context");
myCgVertexProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_VERTEX);
CgGl.cgGLSetOptimalOptions(myCgVertexProfile);
checkForCgError("selecting vertex profile");
myCgVertexProgram =
Cg.cgCreateProgramFromFile(
myCgContext, /* Cg runtime context */
Cg.CG_SOURCE, /* Program in human-readable form */
myVertexProgramFileName, /* Name of file containing program */
myCgVertexProfile, /* Profile: OpenGL ARB vertex program */
myVertexProgramName, /* Entry function name */
null); /* No extra compiler options */
checkForCgError("creating vertex program from file");
CgGl.cgGLLoadProgram(myCgVertexProgram);
checkForCgError("loading vertex program");
GET_PARAM("modelViewProj");
GET_PARAM("time");
GET_PARAM("frequency");
GET_PARAM("scaleFactor");
GET_PARAM("Kd");
GET_PARAM("shininess");
GET_PARAM("eyePosition");
GET_PARAM("lightPosition");
GET_PARAM("lightColor");
/* Set light source color parameters once. */
Cg.cgSetParameter3fv(myCgVertexParam_lightColor, out myLightColor[0]);
Cg.cgSetParameter1f(myCgVertexParam_scaleFactor, 0.3f);
Cg.cgSetParameter1f(myCgVertexParam_frequency, 2.4f);
Cg.cgSetParameter1f(myCgVertexParam_shininess, 35f);
myCgFragmentProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_FRAGMENT);
CgGl.cgGLSetOptimalOptions(myCgFragmentProfile);
checkForCgError("selecting fragment profile");
/* Specify fragment program with a string. */
myCgFragmentProgram =
Cg.cgCreateProgram(
myCgContext, /* Cg runtime context */
Cg.CG_SOURCE, /* Program in human-readable form */
"float4 main(float4 c : COLOR) : COLOR { return c; }",
myCgFragmentProfile, /* Profile: latest fragment profile */
"main", /* Entry function name */
null); /* No extra commyPiler options */
checkForCgError("creating fragment program from string");
CgGl.cgGLLoadProgram(myCgFragmentProgram);
checkForCgError("loading fragment program");
/* Specify vertex program for rendering the light source with a
string. */
myCgLightVertexProgram =
Cg.cgCreateProgram(
myCgContext, /* Cg runtime context */
Cg.CG_SOURCE, /* Program in human-readable form */
"void main(inout float4 p : POSITION, " +
"uniform float4x4 modelViewProj, " +
"out float4 c : COLOR) " +
"{ p = mul(modelViewProj, p); c = float4(1,1,0,1); }",
myCgVertexProfile, /* Profile: latest fragment profile */
"main", /* Entry function name */
null); /* No extra commyPiler options */
checkForCgError("creating light vertex program from string");
CgGl.cgGLLoadProgram(myCgLightVertexProgram);
checkForCgError("loading light vertex program");
myCgLightVertexParam_modelViewProj =
Cg.cgGetNamedParameter(myCgLightVertexProgram, "modelViewProj");
checkForCgError("could not get modelViewProj parameter");
Glut.glutCreateMenu(menu);
Glut.glutAddMenuEntry("[ ] Animate", ' ');
Glut.glutAttachMenu(Glut.GLUT_RIGHT_BUTTON);
// Change Animation to true, so that it starts with action ;-)
keyboard((byte)' ', 0, 0);
Glut.glutMainLoop();
}
#endregion Run())