public static void Run() { string filePath = Path.Combine("..", ".."); string fileDirectory = "Data"; string vertexFileName = "C2E1v_green.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); KeyboardDelegate += Keyboard; 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); Gl.glClearColor(0.1f, 0.3f, 0.6f, 0.0f); /* Blue background */ 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"); Glut.glutMainLoop(); }
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(); }
public static void Run() { string filePath = Path.Combine("..", ".."); string fileDirectory = "Data"; string vertexFileName = "C3E4v_twist.cg"; string fragmentFileName = "C2E2f_passthru.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); string myFragmentProgramFileName = Path.Combine(Path.Combine(filePath, fileDirectory), fragmentFileName); // Callback Delegates keyboardDelegate += keyboard; menuDelegate += menu; idleDelegate += idle; 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); Gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); /* White background */ 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"); myCgVertexParam_twisting = Cg.cgGetNamedParameter(myCgVertexProgram, "twisting"); checkForCgError("could not get twisting parameter"); myCgFragmentProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_FRAGMENT); CgGl.cgGLSetOptimalOptions(myCgFragmentProfile); checkForCgError("selecting fragment profile"); myCgFragmentProgram = Cg.cgCreateProgramFromFile( myCgContext, /* Cg runtime context */ Cg.CG_SOURCE, /* Program in human-readable form */ myFragmentProgramFileName, /* Name of file containing program */ myCgFragmentProfile, /* Profile: OpenGL ARB vertex program */ myFragmentProgramName, /* Entry function name */ null); /* No extra compiler options */ checkForCgError("creating fragment program from file"); CgGl.cgGLLoadProgram(myCgFragmentProgram); checkForCgError("loading fragment program"); /* No uniform fragment program parameters expected. */ Glut.glutCreateMenu(menuDelegate); Glut.glutAddMenuEntry("[ ] Animate", ' '); Glut.glutAddMenuEntry("[w] Wireframe", 'w'); Glut.glutAttachMenu(Glut.GLUT_RIGHT_BUTTON); // Change Animation to true, so that it starts with action ;-) keyboard((byte)' ', 0, 0); Glut.glutMainLoop(); }
private void InitCg() { m_CG_vertexProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_VERTEX); CgGl.cgGLSetOptimalOptions(m_CG_vertexProfile); checkForCgError("selecting vertex profile"); m_CG_fragmentProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_FRAGMENT); CgGl.cgGLSetOptimalOptions(m_CG_fragmentProfile); checkForCgError("selecting fragment profile"); // Create the context... m_CGcontext = Cg.cgCreateContext(); checkForCgError("creating context"); string cas = Application.StartupPath; //load pass1 m_CGp_vertexProgramPass1 = Cg.cgCreateProgramFromFile(m_CGcontext, Cg.CG_SOURCE, cas + "/SpriteVertexProgram.cg", m_CG_vertexProfile, "main_pass1", null); checkForCgError("creating vertex program pass1 from file SpriteVertexProgram.cg"); CgGl.cgGLLoadProgram(m_CGp_vertexProgramPass1); checkForCgError("loading vertex program"); m_CGp_fragmentProgramPass1 = Cg.cgCreateProgramFromFile(m_CGcontext, Cg.CG_SOURCE, cas + "/SpriteFragmentProgram.cg", m_CG_fragmentProfile, "main_pass1", null); checkForCgError("creating fragment program from file SpriteFragmentProgram.cg"); CgGl.cgGLLoadProgram(m_CGp_fragmentProgramPass1); checkForCgError("loading fragment program"); //load pass2 m_CGp_vertexProgramPass2 = Cg.cgCreateProgramFromFile(m_CGcontext, Cg.CG_SOURCE, cas + "/SpriteVertexProgram.cg", m_CG_vertexProfile, "main_pass2", null); checkForCgError("creating vertex program pass2 from file SpriteVertexProgram.cg"); CgGl.cgGLLoadProgram(m_CGp_vertexProgramPass2); checkForCgError("loading vertex program"); m_CGp_fragmentProgramPass2 = Cg.cgCreateProgramFromFile(m_CGcontext, Cg.CG_SOURCE, cas + "/SpriteFragmentProgram.cg", m_CG_fragmentProfile, "main_pass2", null); checkForCgError("creating fragment program from file SpriteFragmentProgram.cg"); CgGl.cgGLLoadProgram(m_CGp_fragmentProgramPass2); checkForCgError("loading fragment program"); //load pass3 m_CGp_vertexProgramPass3 = Cg.cgCreateProgramFromFile(m_CGcontext, Cg.CG_SOURCE, cas + "/SpriteVertexProgram.cg", m_CG_vertexProfile, "main_pass3", null); checkForCgError("creating vertex program pass3 from file SpriteVertexProgram.cg"); CgGl.cgGLLoadProgram(m_CGp_vertexProgramPass3); checkForCgError("loading vertex program"); m_CGp_fragmentProgramPass3 = Cg.cgCreateProgramFromFile(m_CGcontext, Cg.CG_SOURCE, cas + "/SpriteFragmentProgram.cg", m_CG_fragmentProfile, "main_pass3", null); checkForCgError("creating fragment program from file SpriteFragmentProgram.cg"); CgGl.cgGLLoadProgram(m_CGp_fragmentProgramPass3); checkForCgError("loading fragment pass3 program"); //pass1 parameters m_CGparam_modelViewProjPass1 = Cg.cgGetNamedParameter(m_CGp_vertexProgramPass1, "modelViewProj"); checkForCgError("getting modal view proj"); m_CGparam_modelViewITPass1 = Cg.cgGetNamedParameter(m_CGp_vertexProgramPass1, "modelViewIT"); checkForCgError("getting modal view IT"); m_CGparam_modelViewPass1 = Cg.cgGetNamedParameter(m_CGp_vertexProgramPass1, "modelView"); checkForCgError("getting modal view"); m_CGparam_eyePositionPass1 = Cg.cgGetNamedParameter(m_CGp_vertexProgramPass1, "eyePos"); checkForCgError("getting eyePos"); m_CGparam_sizeFactorPass1 = Cg.cgGetNamedParameter(m_CGp_vertexProgramPass1, "sizeFactor"); checkForCgError("getting sizeFactor"); m_CGparam_zoffsetPass1 = Cg.cgGetNamedParameter(m_CGp_vertexProgramPass1, "zoffset"); checkForCgError("getting zoffset"); CgGl.cgGLSetParameter1f(m_CGparam_zoffsetPass1, 0.003f); checkForCgError("setting zoffset"); m_CGparam_splatRotationCutoffDistPass1 = Cg.cgGetNamedParameter(m_CGp_vertexProgramPass1, "splatRotationCutoffDist"); checkForCgError("getting splatRotationCutoffDist"); CgGl.cgGLSetParameter1f(m_CGparam_zoffsetPass1, 0.003f); checkForCgError("setting zoffset"); m_CGparam_farcullPass1 = Cg.cgGetNamedParameter(m_CGp_vertexProgramPass1, "farcull"); checkForCgError("getting farcull"); CgGl.cgGLSetParameter1f(m_CGparam_farcullPass1, WorldView.farCull); checkForCgError("setting farcull"); m_CGparam_viewParamsPass1 = Cg.cgGetNamedParameter(m_CGp_vertexProgramPass1, "viewParams"); checkForCgError("getting viewParams"); //pass2 parameters m_CGparam_modelViewProjPass2 = Cg.cgGetNamedParameter(m_CGp_vertexProgramPass2, "modelViewProj"); checkForCgError("getting modal view proj2"); m_CGparam_modelViewITPass2 = Cg.cgGetNamedParameter(m_CGp_vertexProgramPass2, "modelViewIT"); checkForCgError("getting modal view IT2"); m_CGparam_modelViewPass2 = Cg.cgGetNamedParameter(m_CGp_vertexProgramPass2, "modelView"); checkForCgError("getting modal view2"); m_CGparam_eyePositionPass2 = Cg.cgGetNamedParameter(m_CGp_vertexProgramPass2, "eyePos"); checkForCgError("getting eyePos2"); m_CGparam_sizeFactorPass2 = Cg.cgGetNamedParameter(m_CGp_vertexProgramPass2, "sizeFactor"); checkForCgError("getting sizeFactor2"); m_CGparam_splatRotationCutoffDistPass2 = Cg.cgGetNamedParameter(m_CGp_vertexProgramPass2, "splatRotationCutoffDist"); checkForCgError("getting splatRotationCutoffDist"); CgGl.cgGLSetParameter1f(m_CGparam_sizeFactorPass1, 1f); checkForCgError("setting sizeFactor"); CgGl.cgGLSetParameter1f(m_CGparam_sizeFactorPass2, 1f); checkForCgError("setting sizeFactor2"); m_CGparam_farcullPass2 = Cg.cgGetNamedParameter(m_CGp_vertexProgramPass2, "farcull"); checkForCgError("getting farcull"); CgGl.cgGLSetParameter1f(m_CGparam_farcullPass2, WorldView.farCull); checkForCgError("setting farcull"); m_CGparam_viewParamsPass2 = Cg.cgGetNamedParameter(m_CGp_vertexProgramPass2, "viewParams"); checkForCgError("getting viewParams"); }