コード例 #1
0
        static void Display()
        {
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);

            CgGl.cgGLBindProgram(myCgVertexProgram);
            checkForCgError("binding vertex program");

            CgGl.cgGLEnableProfile(myCgVertexProfile);
            checkForCgError("enabling vertex profile");

            CgGl.cgGLBindProgram(myCgFragmentProgram);
            checkForCgError("binding fragment program");

            CgGl.cgGLEnableProfile(myCgFragmentProfile);
            checkForCgError("enabling fragment profile");

            DrawStars();

            CgGl.cgGLDisableProfile(myCgVertexProfile);
            checkForCgError("disabling vertex profile");

            CgGl.cgGLDisableProfile(myCgFragmentProfile);
            checkForCgError("disabling fragment profile");

            Glut.glutSwapBuffers();
        }
コード例 #2
0
        static void display()
        {
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);

            Cg.cgSetParameter1f(myCgVertexParam_twisting, myTwisting);

            CgGl.cgGLBindProgram(myCgVertexProgram);
            checkForCgError("binding vertex program");

            CgGl.cgGLEnableProfile(myCgVertexProfile);
            checkForCgError("enabling vertex profile");

            CgGl.cgGLBindProgram(myCgFragmentProgram);
            checkForCgError("binding fragment program");

            CgGl.cgGLEnableProfile(myCgFragmentProfile);
            checkForCgError("enabling fragment profile");

            drawSubDividedTriangle(5);

            CgGl.cgGLDisableProfile(myCgVertexProfile);
            checkForCgError("disabling vertex profile");

            CgGl.cgGLDisableProfile(myCgFragmentProfile);
            checkForCgError("disabling fragment profile");

            Glut.glutSwapBuffers();
        }
コード例 #3
0
        private void EnableShadersPass3()
        {
            CgGl.cgGLBindProgram(m_CGp_vertexProgramPass3);
            checkForCgError("binding vertex program3");

            CgGl.cgGLEnableProfile(m_CG_vertexProfile);
            checkForCgError("enabling vertex profile3");

            CgGl.cgGLBindProgram(m_CGp_fragmentProgramPass3);
            checkForCgError("binding fragment program3");

            CgGl.cgGLEnableProfile(m_CG_fragmentProfile);
            checkForCgError("enabling fragment profile3");
        }
コード例 #4
0
        private void EnableShadersPass2(Vector3f eyeVector)
        {
            SetShaderParametersPass2(eyeVector);

            CgGl.cgGLBindProgram(m_CGp_vertexProgramPass2);
            checkForCgError("binding vertex program2");

            CgGl.cgGLEnableProfile(m_CG_vertexProfile);
            checkForCgError("enabling vertex profile2");

            CgGl.cgGLBindProgram(m_CGp_fragmentProgramPass2);
            checkForCgError("binding fragment program2");

            CgGl.cgGLEnableProfile(m_CG_fragmentProfile);
            checkForCgError("enabling fragment profile2");
        }
コード例 #5
0
        static void Display()
        {
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);

            CgGl.cgGLBindProgram(myCgVertexProgram);
            checkForCgError("binding vertex program");

            CgGl.cgGLEnableProfile(myCgVertexProfile);
            checkForCgError("enabling vertex profile");

            /* Rendering code verbatim from Chapter 1, Section 2.4.1 "Rendering
             * a Triangle with OpenGL" (page 57). */
            Gl.glBegin(Gl.GL_TRIANGLES);
            Gl.glVertex2f(-0.8f, 0.8f);
            Gl.glVertex2f(0.8f, 0.8f);
            Gl.glVertex2f(0.0f, -0.8f);
            Gl.glEnd();

            CgGl.cgGLDisableProfile(myCgVertexProfile);
            checkForCgError("disabling vertex profile");

            Glut.glutSwapBuffers();
        }
コード例 #6
0
        /// <summary>
        /// Binds a Cg program</summary>
        /// <param name="id">ID for the Cg program we want to bind</param>
        public static void BindProgram(string id)
        {
            CgGl.cgGLBindProgram(m_cg_programs[id]);
//            System.Console.WriteLine("  Cg BindProgram  ," + m_cg_context + "," + m_cg_program_counter + " id=" + id);
        }
コード例 #7
0
        static void display()
        {
            /* World-space positions for light and eye. */
            float[] eyePosition   = { 0, 0, 8, 1 };
            float[] lightPosition = { 5 * (float)Math.Sin(myLightAngle),
                                      1.5f,
                                      5 * (float)Math.Cos(myLightAngle), 1 };

            float[] translateMatrix = new float[16], rotateMatrix = new float[16],
            modelMatrix     = new float[16], invModelMatrix = new float[16], viewMatrix = new float[16],
            modelViewMatrix = new float[16], modelViewProjMatrix = new float[16];
            float[] objSpaceEyePosition = new float[4], objSpaceLightPosition = new float[4];

            Cg.cgSetParameter1f(myCgVertexParam_time, myTime);

            buildLookAtMatrix(eyePosition[0], eyePosition[1], eyePosition[2],
                              0, 0, 0,
                              0, 1, 0,
                              ref viewMatrix);

            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);

            CgGl.cgGLEnableProfile(myCgVertexProfile);
            checkForCgError("enabling vertex profile");

            CgGl.cgGLEnableProfile(myCgFragmentProfile);
            checkForCgError("enabling fragment profile");

            CgGl.cgGLBindProgram(myCgVertexProgram);
            checkForCgError("binding vertex program");

            CgGl.cgGLBindProgram(myCgFragmentProgram);
            checkForCgError("binding fragment program");

            /*** Render green solid bulging sphere ***/

            /* modelView = rotateMatrix * translateMatrix */
            makeRotateMatrix(70f, 1f, 1f, 1f, ref rotateMatrix);
            makeTranslateMatrix(2.2f, 1f, 0.2f, ref translateMatrix);
            multMatrix(ref modelMatrix, translateMatrix, rotateMatrix);

            /* invModelMatrix = inverse(modelMatrix) */
            invertMatrix(ref invModelMatrix, ref modelMatrix);

            /* Transform world-space eye and light positions to sphere's object-space. */
            transform(ref objSpaceEyePosition, invModelMatrix, eyePosition);
            Cg.cgSetParameter3fv(myCgVertexParam_eyePosition, out objSpaceEyePosition[0]);
            transform(ref objSpaceLightPosition, invModelMatrix, lightPosition);
            Cg.cgSetParameter3fv(myCgVertexParam_lightPosition, out objSpaceLightPosition[0]);

            /* modelViewMatrix = viewMatrix * modelMatrix */
            multMatrix(ref modelViewMatrix, viewMatrix, modelMatrix);

            /* modelViewProj = projectionMatrix * modelViewMatrix */
            multMatrix(ref modelViewProjMatrix, myProjectionMatrix, modelViewMatrix);

            /* Set matrix parameter with row-major matrix. */
            Cg.cgSetMatrixParameterfr(myCgVertexParam_modelViewProj, out modelViewProjMatrix[0]);
            Cg.cgSetParameter4f(myCgVertexParam_Kd, 0.1f, 0.7f, 0.1f, 1f);  /* Green */
            Glut.glutSolidSphere(1.0, 40, 40);

            /*** Render red solid bulging torus ***/

            /* modelView = viewMatrix * translateMatrix */
            makeTranslateMatrix(-2f, -1.5f, 0f, ref translateMatrix);
            makeRotateMatrix(55, 1, 0, 0, ref rotateMatrix);
            multMatrix(ref modelMatrix, translateMatrix, rotateMatrix);

            /* invModelMatrix = inverse(modelMatrix) */
            invertMatrix(ref invModelMatrix, ref modelMatrix);

            /* Transform world-space eye and light positions to sphere's object-space. */
            transform(ref objSpaceEyePosition, invModelMatrix, eyePosition);
            Cg.cgSetParameter3fv(myCgVertexParam_eyePosition, out objSpaceEyePosition[0]);
            transform(ref objSpaceLightPosition, invModelMatrix, lightPosition);
            Cg.cgSetParameter3fv(myCgVertexParam_lightPosition, out objSpaceLightPosition[0]);

            /* modelViewMatrix = viewMatrix * modelMatrix */
            multMatrix(ref modelViewMatrix, viewMatrix, modelMatrix);

            /* modelViewProj = projectionMatrix * modelViewMatrix */
            multMatrix(ref modelViewProjMatrix, myProjectionMatrix, modelViewMatrix);

            /* Set matrix parameter with row-major matrix. */
            Cg.cgSetMatrixParameterfr(myCgVertexParam_modelViewProj, out modelViewProjMatrix[0]);
            Cg.cgSetParameter4f(myCgVertexParam_Kd, 0.8f, 0.1f, 0.1f, 1f);  /* Red */
            Glut.glutSolidTorus(0.15, 1.7, 40, 40);

            /*** Render light as emissive yellow ball ***/

            CgGl.cgGLBindProgram(myCgLightVertexProgram);
            checkForCgError("binding light vertex program");

            /* modelView = translateMatrix */
            makeTranslateMatrix(lightPosition[0], lightPosition[1], lightPosition[2],
                                ref modelMatrix);

            /* modelViewMatrix = viewMatrix * modelMatrix */
            multMatrix(ref modelViewMatrix, viewMatrix, modelMatrix);

            /* modelViewProj = projectionMatrix * modelViewMatrix */
            multMatrix(ref modelViewProjMatrix, myProjectionMatrix, modelViewMatrix);

            /* Set matrix parameter with row-major matrix. */
            Cg.cgSetMatrixParameterfr(myCgLightVertexParam_modelViewProj,
                                      out modelViewProjMatrix[0]);
            Glut.glutSolidSphere(0.1, 12, 12);

            CgGl.cgGLDisableProfile(myCgVertexProfile);
            checkForCgError("disabling vertex profile");

            CgGl.cgGLDisableProfile(myCgFragmentProfile);
            checkForCgError("disabling fragment profile");

            Glut.glutSwapBuffers();
        }