예제 #1
0
파일: Program.cs 프로젝트: tuvshinot/csharp
        private static void OnRenderFrame()
        {
            watch.Stop();
            float deltaTime = (float)watch.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency;

            watch.Restart();

            // set up the viewport and clear the previous depth and color buffers
            Gl.Viewport(0, 0, width, height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // perform rotation of the cube depending on the keyboard state
            if (autoRotate)
            {
                xangle += deltaTime / 2;
                yangle += deltaTime;
            }
            if (right)
            {
                yangle += deltaTime;
            }
            if (left)
            {
                yangle -= deltaTime;
            }
            if (up)
            {
                xangle -= deltaTime;
            }
            if (down)
            {
                xangle += deltaTime;
            }

            // make sure the shader program and texture are being used
            Gl.UseProgram(program);
            Gl.ActiveTexture(TextureUnit.Texture1);
            Gl.BindTexture(brickNormals);
            Gl.ActiveTexture(TextureUnit.Texture0);
            Gl.BindTexture(brickDiffuse);

            // set up the model matrix and draw the cube
            program["model_matrix"].SetValue(Matrix4.CreateRotationY(yangle) * Matrix4.CreateRotationX(xangle));
            program["enable_lighting"].SetValue(lighting);
            program["enable_mapping"].SetValue(normalMapping);

            Gl.BindBufferToShaderAttribute(cube, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(cubeNormals, program, "vertexNormal");
            Gl.BindBufferToShaderAttribute(cubeTangents, program, "vertexTangent");
            Gl.BindBufferToShaderAttribute(cubeUV, program, "vertexUV");
            Gl.BindBuffer(cubeTriangles);

            Gl.DrawElements(BeginMode.Triangles, cubeTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);

            // bind the font program as well as the font texture
            Gl.UseProgram(fontProgram.ProgramID);
            Gl.BindTexture(font.FontTexture);

            // draw the tutorial information, which is static
            information.Draw();

            Glut.glutSwapBuffers();
        }
예제 #2
0
        private static void OnRenderFrame()
        {
            watch.Stop();
            float deltaTime = (float)watch.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency;

            watch.Restart();

            // update our camera by moving it up to 5 units per second in each direction
            if (down)
            {
                camera.MoveRelative(Vector3.UnitZ * deltaTime * 5);
            }
            if (up)
            {
                camera.MoveRelative(-Vector3.UnitZ * deltaTime * 5);
            }
            if (left)
            {
                camera.MoveRelative(-Vector3.UnitX * deltaTime * 5);
            }
            if (right)
            {
                camera.MoveRelative(Vector3.UnitX * deltaTime * 5);
            }
            if (space)
            {
                camera.MoveRelative(Vector3.UnitY * deltaTime * 3);
            }

            // set up the viewport and clear the previous depth and color buffers
            Gl.Viewport(0, 0, width, height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // make sure the shader program and texture are being used
            Gl.UseProgram(program);
            Gl.ActiveTexture(TextureUnit.Texture1);
            Gl.BindTexture(brickNormals);
            Gl.ActiveTexture(TextureUnit.Texture0);
            Gl.BindTexture(brickDiffuse);

            // apply our camera view matrix to the shader view matrix (this can be used for all objects in the scene)
            program["view_matrix"].SetValue(camera.ViewMatrix);

            // set up the model matrix and draw the cube
            program["model_matrix"].SetValue(Matrix4.Identity);
            program["enable_lighting"].SetValue(lighting);
            program["enable_mapping"].SetValue(normalMapping);

            Gl.BindBufferToShaderAttribute(cube, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(cubeNormals, program, "vertexNormal");
            Gl.BindBufferToShaderAttribute(cubeTangents, program, "vertexTangent");
            Gl.BindBufferToShaderAttribute(cubeUV, program, "vertexUV");
            Gl.BindBuffer(cubeTriangles);

            Gl.DrawElements(BeginMode.Triangles, cubeTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);

            // bind the font program as well as the font texture
            Gl.UseProgram(fontProgram.ProgramID);
            Gl.BindTexture(font.FontTexture);

            // draw the tutorial information, which is static
            information.Draw();

            Glut.glutSwapBuffers();
        }
예제 #3
0
        private static void OnRenderFrame()
        {
            watch.Stop();
            float deltaTime = (float)watch.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency;

            watch.Restart();

            // perform rotation of the scene depending on keyboard input
            if (right)
            {
                phi += deltaTime;
            }
            if (left)
            {
                phi -= deltaTime;
            }
            if (up)
            {
                theta += deltaTime;
            }
            if (down)
            {
                theta -= deltaTime;
            }
            if (theta < 0)
            {
                theta += (float)Math.PI * 2;
            }

            // set up the viewport and clear the previous depth and color buffers
            Gl.Viewport(0, 0, width, height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // make sure the shader program and texture are being used
            Gl.UseProgram(program.ProgramID);
            Gl.BindTexture(flagTexture);

            // calculate the camera position using some fancy polar co-ordinates
            Vector3 position = 20 * new Vector3(Math.Cos(phi) * Math.Sin(theta), Math.Cos(theta), Math.Sin(phi) * Math.Sin(theta));
            Vector3 upVector = ((theta % (Math.PI * 2)) > Math.PI) ? Vector3.Up : Vector3.Down;

            program["view_matrix"].SetValue(Matrix4.LookAt(position, Vector3.Zero, upVector));

            program["time"].SetValue(flagTime);
            flagTime += deltaTime;

            Gl.BindBufferToShaderAttribute(flagVertices, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(flagUVs, program, "vertexUV");
            Gl.BindBuffer(flagTriangles);

            Gl.DrawElements(BeginMode.Quads, flagTriangles.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);

            // bind the font program as well as the font texture
            Gl.UseProgram(fontProgram.ProgramID);
            Gl.BindTexture(font.FontTexture);

            // build this string every frame, since theta and phi can change
            FontVAO vao = font.CreateString(fontProgram, string.Format("Theta:   {0:0.000},  Phi:   {1:0.000},  Time:   {2:0.000}", theta, phi, flagTime), BMFont.Justification.Right);

            vao.Position = new Vector2(width / 2 - 10, height / 2 - font.Height - 10);
            vao.Draw();
            vao.Dispose();

            // draw the tutorial information, which is static
            information.Draw();

            Glut.glutSwapBuffers();
        }
예제 #4
0
        private static void OnRenderFrame()
        {
            watch.Stop();
            float deltaTime = (float)watch.ElapsedTicks / System.Diagnostics.Stopwatch.Frequency;

            watch.Restart();

            // perform rotation of the cube depending on the keyboard state
            if (autoRotate)
            {
                xangle += deltaTime / 2;
                yangle += deltaTime;
            }
            if (right)
            {
                yangle += deltaTime;
            }
            if (left)
            {
                yangle -= deltaTime;
            }
            if (up)
            {
                xangle -= deltaTime;
            }
            if (down)
            {
                xangle += deltaTime;
            }

            // set up the viewport and clear the previous depth and color buffers
            Gl.Viewport(0, 0, width, height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            // make sure the shader program and texture are being used
            Gl.UseProgram(program);
            Gl.BindTexture(glassTexture);

            // set up the model matrix and draw the cube
            program["model_matrix"].SetValue(Matrix4.CreateRotationY(yangle) * Matrix4.CreateRotationX(xangle));
            program["enable_lighting"].SetValue(lighting);

            Gl.BindBufferToShaderAttribute(cube, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(cubeNormals, program, "vertexNormal");
            Gl.BindBufferToShaderAttribute(cubeUV, program, "vertexUV");
            Gl.BindBuffer(cubeQuads);

            Gl.DrawElements(BeginMode.Quads, cubeQuads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);


            //Draw window
            Gl.BindTexture(kacaTexture);

            // set up the model matrix and draw the cube
            program["model_matrix"].SetValue(Matrix4.CreateRotationY(yangle) * Matrix4.CreateRotationX(xangle));
            program["enable_lighting"].SetValue(lighting);

            Gl.BindBufferToShaderAttribute(window, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(windowNormals, program, "vertexNormal");
            Gl.BindBufferToShaderAttribute(windowUV, program, "vertexUV");
            Gl.BindBuffer(windowQuads);

            Gl.DrawElements(BeginMode.Quads, windowQuads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);

            //drawwheel
            Gl.BindTexture(rodaTexture);

            Gl.BindBufferToShaderAttribute(wheel1, program, "vertexPosition");
            Gl.BindBufferToShaderAttribute(wheel1Normals, program, "vertexNormal");
            Gl.BindBufferToShaderAttribute(wheel1UV, program, "vertexUV");
            Gl.BindBuffer(wheel1Quads);

            Gl.DrawElements(BeginMode.TriangleStrip, wheel1Quads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            Gl.BindBufferToShaderAttribute(wheel11, program, "vertexPosition");
            Gl.DrawElements(BeginMode.TriangleStrip, wheel1Quads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            Gl.BindBufferToShaderAttribute(wheel21, program, "vertexPosition");
            Gl.DrawElements(BeginMode.TriangleStrip, wheel1Quads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            Gl.BindBufferToShaderAttribute(wheel31, program, "vertexPosition");
            Gl.DrawElements(BeginMode.TriangleStrip, wheel1Quads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            Gl.BindBufferToShaderAttribute(wheel41, program, "vertexPosition");

            Gl.DrawElements(BeginMode.TriangleStrip, wheel1Quads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            Gl.BindBufferToShaderAttribute(wheel111, program, "vertexPosition");
            Gl.DrawElements(BeginMode.TriangleStrip, wheel1Quads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            Gl.BindBufferToShaderAttribute(wheel211, program, "vertexPosition");
            Gl.DrawElements(BeginMode.TriangleStrip, wheel1Quads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            Gl.BindBufferToShaderAttribute(wheel311, program, "vertexPosition");
            Gl.DrawElements(BeginMode.TriangleStrip, wheel1Quads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            Gl.BindBufferToShaderAttribute(wheel411, program, "vertexPosition");

            Gl.DrawElements(BeginMode.TriangleStrip, wheel1Quads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            Gl.BindBufferToShaderAttribute(wheel112, program, "vertexPosition");
            Gl.DrawElements(BeginMode.TriangleStrip, wheel1Quads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            Gl.BindBufferToShaderAttribute(wheel212, program, "vertexPosition");
            Gl.DrawElements(BeginMode.TriangleStrip, wheel1Quads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            Gl.BindBufferToShaderAttribute(wheel312, program, "vertexPosition");
            Gl.DrawElements(BeginMode.TriangleStrip, wheel1Quads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            Gl.BindBufferToShaderAttribute(wheel412, program, "vertexPosition");

            Gl.DrawElements(BeginMode.TriangleStrip, wheel1Quads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            Gl.BindBufferToShaderAttribute(wheel2, program, "vertexPosition");
            Gl.DrawElements(BeginMode.TriangleStrip, wheel1Quads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            Gl.BindBufferToShaderAttribute(wheel3, program, "vertexPosition");
            Gl.DrawElements(BeginMode.TriangleStrip, wheel1Quads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);
            Gl.BindBufferToShaderAttribute(wheel4, program, "vertexPosition");
            Gl.DrawElements(BeginMode.TriangleStrip, wheel1Quads.Count, DrawElementsType.UnsignedInt, IntPtr.Zero);

            Glut.glutSwapBuffers();
        }