Esempio n. 1
0
        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();
        }
Esempio n. 3
0
        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();
        }